Incubator-mxnet: Missing constant symbol (equivalent of tf.constant)?

Created on 25 Oct 2017  路  3Comments  路  Source: apache/incubator-mxnet

Hi, I just started using this framework for building something that is only marginally related to deep learning. As such, pardon me if this is simply due to my unfamiliarity or if this is an issue that doesn't arise often for deep learning applications.

Basically, I'm trying to do simple operations with symbols involving constant tensors but I cannot find an obvious way to do it. There's sym.ones and sym.zeros which create constant symbols of ones and zeros but there doesn't seem to be an easy way to create an arbitrary constant tensor symbol that I can use in operations such as sym.dot...

Call for Contribution Feature request Symbol

Most helpful comment

Yes, it would be nice to have a constant symbol similar to nd.array

All 3 comments

Yes, it would be nice to have a constant symbol similar to nd.array

  1. define a var in symbol
weight = mx.symbol.Variable(name="weight", lr_mult=0)
  1. define a mixed initializer, init the weight by const ndarray
weight = mx.nd.ones((3))
initializer = mx.init.Mixed(['weight', '.*'], [mx.init.Constant(weight), xavier])

As a workaround, you can implement a constant CustomOp. It requires that you serialize the data through the CustomOpProp implementation somehow. One example of this can be seen here:
https://github.com/tqchen/mxnet-gan/blob/master/mxgan/custom_ops.py

Was this page helpful?
0 / 5 - 0 ratings