Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Anirudh Subramanian
    @anirudh2290
    is it possible for you to share reproduce steps ?
    do you have any post in the discussion forum https://discuss.mxnet.io/ ?
    Sam Hodge
    @samhodge
    Yup
    I just woke up it is 5:16 am in Adelaide
    Let me get coffee and laptop
    Anirudh Subramanian
    @anirudh2290
    aah sorry about that. found your issue: apache/incubator-mxnet#9813
    Sam Hodge
    @samhodge
      File "main.py", line 229, in <module>
        main()
      File "main.py", line 214, in main
        train(args)
      File "main.py", line 82, in train
        style_model.setTarget(style_image)
      File "/Users/sam/dev/incubator-mxnet/example/gluon/style_transfer/net.py", line 236, in setTarget
        F = self.model1(Xs)
      File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/gluon/block.py", line 304, in __call__
        return self.forward(*args)
      File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/gluon/block.py", line 516, in forward
        return self.hybrid_forward(ndarray, x, *args, **params)
      File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/gluon/nn/basic_layers.py", line 111, in hybrid_forward
        x = block(x)
      File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/gluon/block.py", line 304, in __call__
        return self.forward(*args)
      File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/gluon/block.py", line 507, in forward
        params = {i: j.data(ctx) for i, j in self._reg_params.items()}
      File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/gluon/block.py", line 507, in <dictcomp>
        params = {i: j.data(ctx) for i, j in self._reg_params.items()}
      File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/gluon/parameter.py", line 389, in data
        return self._check_and_get(self._data, ctx)
      File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/gluon/parameter.py", line 189, in _check_and_get
        "nested child Blocks"%(self.name,type(self)))
    RuntimeError: Parameter net0_instancenorm0_beta <class 'mxnet.gluon.parameter.Parameter'> has not been initialized. Note that you should initialize parameters and create Trainer with Block.collect_params() instead of Block.params because the later does not include Parameters of nested child Blocks
    There : samhodge/incubator-mxnet@949993f
    I may have no idea what I am doing
    here is my command line args
    python main.py train --dataset dataset --style-folder images/styles --save-model-dir models --cuda 0
    Anirudh Subramanian
    @anirudh2290
    i should be able to reproduce the issue by just using your changed example correct ?
    Sam Hodge
    @samhodge
    yup
    you will need to download the images and the model
    but repro yes
    To be honest I am still learning
    but the objective is clear, convert Gluon model to Symbolic model and then run in C++
    I am stuck at step 1
    @anirudh2290 Thank you for being generous with your time
    Sam Hodge
    @samhodge
    @anirudh2290 I need to get ready for my day job, I look forward to any pearls of wisdom you might have.
    Anirudh Subramanian
    @anirudh2290
    @samhodge answered on the issue.
    Sam Hodge
    @samhodge
    thankyou
    I might be able to look into it on my lunch break here at work.
    Sam Hodge
    @samhodge
    I have updated the issue apache/incubator-mxnet#9813
    Just training now, I will let it cook until the morning CPU only
    Sam Hodge
    @samhodge
    @anirudh2290 Thanks for all of your help, if I get a decent trained model out of this I will put in a pull request.
    Anirudh Subramanian
    @anirudh2290
    no worries! will be happy to look at your PR!
    Sam Hodge
    @samhodge
    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
    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
    OK apache/incubator-mxnet#9813 has been updated @anirudh2290 if you could help me out that would be great
    Sam Hodge
    @samhodge
    Does anybody have experience with how to get the shape of a Symbol using infer_shape?
    Anirudh Subramanian
    @anirudh2290
    hi @samhodge sorry i have been busy and havent gotten a chance to look at your changes. Have you looked at infer_shape documentation ?
    Anirudh Subramanian
    @anirudh2290
    i think you should be able to use infer_shape without any arguments
    the shape should be inferred when data is bound to the symbolic inputs to the model
    Sam Hodge
    @samhodge
    I will try again, I looked
    Anirudh Subramanian
    @anirudh2290
    its not very clear from the documentation. maybe we should add an example to the documentation.
    Sam Hodge
    @samhodge
    /home/samh/dev/MXNet-Gluon-Style-Transfer/net.py:332: UserWarning: Cannot decide shape for the following arguments (0s in shape means unknown dimensions). Consider providing them as input:
    data: ()
    in_shapes,out_shapes,arg_shapes= X.infer_shape()
    that is not a good start
    With this
    `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, ctx=mx.cpu(0)):
    super(Inspiration, self).init()
        # B is equal to 1 or input mini_batch
        self.C = C
        self.B = B
    
        self.weight = self.collect_params().get('weight', shape=(1,self.C,self.C),
                                      init=mx.initializer.Uniform(),
                                      allow_deferred_init=True)
        self.gram = self.collect_params().get('gram', shape=(self.B,self.C,self.C),
                                    init=mx.initializer.Uniform(),
                                    allow_deferred_init=True,
                                    lr_mult=0)
        self.weight.initialize(ctx=ctx)
        self.gram.initialize(ctx=ctx)
    def setTarget(self, target):
        self.gram.set_data(target)
    def hybrid_forward(self, F, X, gram, weight):
    
        P = F.batch_dot(F.broadcast_to(weight, shape=(self.gram.shape)), gram) 
        if not isinstance(X,symbol.Symbol):   
            return F.batch_dot(F.SwapAxis(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)
        else:
            #print "Hooppla", interals
            #for i in dir(interals):
            #    print "kk:", i
            in_shapes,out_shapes,arg_shapes= X.infer_shape(self.gram.shape)
            #print out_shapes
            #raise Exception
            #arg_shapes, out_shapes, aux_shapes = interals.infer_shape(self.gram.shape)
            #print "A", arg_shapes, "O", out_shapes, "AU", aux_shapes
            return F.batch_dot(F.SwapAxis(P,1,2).broadcast_to((in_shapes[0], self.C, self.C)), X.reshape((0,0,in_shapes[2]*in_shapes[3]))).reshape(in_shapes)
    
    def __repr__(self):
        return self.__class__.__name__ + '(' \
            + 'N x ' + str(self.C) + ')'`
    i get the following error
    Sam Hodge
    @samhodge
    terminate called after throwing an instance of 'std::logic_error'
    what(): basic_string::_S_construct null not valid
    Abort
    Sam Hodge
    @samhodge
    OK I will update the repository and the ticket
    Anirudh Subramanian
    @anirudh2290
    @samhodge i dont have much clue at this point. i will try to reproduce in the evening. when you use infer_shape without argument it just fails ?
    Sam Hodge
    @samhodge
    I have updated the ticket in my lunch break
    Anirudh Subramanian
    @anirudh2290
    very positive news @samhodge . dont you have a validation dataset to test your model with ?