These are chat archives for dmlc/mxnet

21st
Feb 2018
Sam Hodge
@samhodge
Feb 21 2018 03:12
OK nearly there, it seems to be training a model OK, but when I go to save the model the issue is in the Inspiration(HybridBlock) the current code which was (poorly) converted from Block to HybridBlock, is not using a Symbol in the args for return value from HybridForward, it is a NDArray, the errors tell me this, but now I am stuck with the issue that the infer_shapes code keeps givng me back and error
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
so basically the question comes back to
Sam Hodge
@samhodge
Feb 21 2018 03:19
class Inspiration(HybridBlock):
    """ Inspiration Layer (from MSG-Net paper)
    tuning the featuremap with target Gram Matrix
    ref https://arxiv.org/abs/1703.06953
    """
    def __init__(self, C, B=1):
        super(Inspiration, self).__init__()
        # B is equal to 1 or input mini_batch
        self.C = C
        self.weight = self.params.get('weight', shape=(1,C,C),
                                      init=mx.initializer.Uniform(),
                                      allow_deferred_init=True)
        self.gram = self.params.get('gram', shape=(B,C,C),
                                    init=mx.initializer.Uniform(),
                                    allow_deferred_init=True,
                                    lr_mult=0)

    def setTarget(self, target):
        self.gram.set_data(target)

    def forward(self, X):
        # input X is a 3D feature map
        self.P = F.batch_dot(F.broadcast_to(self.weight.data(), shape=(self.gram.shape)), self.gram.data())
        return F.batch_dot(F.SwapAxis(self.P,1,2).broadcast_to((X.shape[0], self.C, self.C)), X.reshape((0,0,X.shape[2]*X.shape[3]))).reshape(X.shape)

    def __repr__(self):
        return self.__class__.__name__ + '(' \
            + 'N x ' + str(self.C) + ')'
How do you implement the hybrid forward function for this block, given X.shape is not a method of a Symbol and X.infer_shape(Y), needs an argument of Y as a shape and returns args_shapes,output_shapes,input_shapes
Anyone want to throw me a hand?
I have been able to train on GPU and CPU, but I am not able to save the symbolic moel
I will be able to commit my changes to repro the error in about 7 hours from now.
Sam Hodge
@samhodge
Feb 21 2018 10:57
OK apache/incubator-mxnet#9813 has been updated @anirudh2290 if you could help me out that would be great