-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Unable to save gluon model to symbolic network : neural style #9813
Comments
I have had a bit of a fiddle but I am getting lost But I am currently getting the following:
from
Note that main.py needed a minor edit also. |
I have continued on further see
yields
|
@samhodge Not sure if this helps but HybridBlock has export method https://mxnet.incubator.apache.org/api/python/gluon/gluon.html#mxnet.gluon.HybridBlock.export to export model |
@samhodge Can you just reuse the InstanceNorm in python/mxnet/gluon/nn/basic_layers.py ? your Net class seems to be taking incorrect number of inputs for hybrid forward. GramMatrix doesnt seem to be initializing the super class HybridBlock. Also, for the Bottleneck class the residual parameter set only based on whether self.downsample is not None. for other cases it breaks. |
thanks for the help, I will continue with this advice. |
I think I have got something working: currently no errors, I am training without CUDA, so it could take some time. |
OK I can train the model, but the loss didnt get low enough to brag about yet, but when I save the model, I am getting errors because the hybrid_forward function of Inspiration X doesnt have the attribute "shape" when it is a Symbol, but the hybrid forward function uses this attribute, I feel I will come across more of this, I have been able to evaluate the model before saving and it looks like with more training it will give the expected result. |
OK here are my latest commits: this allows me to execute the following from the command line
Which results in
So what I need to do now is work on:
The attempt
instead results in
So this leads into using .infer_shape, but I am confused about what to give as the shape arguement to X.infer_shape. Any help would be great. |
can you try infer_shape without arguments ? |
OK I tried some things see But is it the right symbolic model? I cannot say, I would have to confirm with input from the original designer who is @zhanghang1989 I can go onto see if the model loaded in C++ give the right output, but I feel I am stabbing around in the dark, rather than operating with precision, but it has got me this far OK. Thanks for all the help so far. |
do you have a validation dataset to test the model ? |
I found this a little bit of help: #1337 |
… known to save the symbolic network, but I have worked with 1(image),3(channels),1920(width),1080(height), assuming this is working, I will comment on the ticket apache#9813 about this and post the output of the network diagram
OK I have now added arguments to infer_shape_partial because without it I wasnt getting any values for the output_shapes, which is what I need rather than arg_shapes, the whole point of a symbolic network is that you do not need to define the input, which seems to defeat the point, I have been able to visualise the network which I will attach here Here is my latest commit: |
Now I have a new error
I will hack visualisation for now. |
The hack
And the result:
|
OK now I have discovered the limit of this network it can only be saved as a symbolic network if the resolution of the input is known at the time of serialisation of the model. I am note sure if a multi resolution model is able to be saved. |
OK a minor update to generalise the model to the width and height of the input |
If I want to run this model in C++ it might make more sense to implement the network parts in C++ also so I can deal with the fact the width and height change the convolution network. |
@samhodge the model makes calls to operators implemented in the C++ backend and leverages the backend dependency engine. |
I have seen this: #6087 and I have also seen this: #4009 and I feel between the two of them there may be a reasonable way to save a neural style model that is independant of channels(3)*width(N)*height(M) currently the model is fixed in N and M at the point it is saved a symbolic model see https://github.com/samhodge/incubator-mxnet/blob/1d72d60495cd47423c572506e8042abe578bbd6a/example/gluon/style_transfer/main.py#L152-L155 and the width and height are passed in as args to even get it to work this far: https://github.com/samhodge/incubator-mxnet/blob/1d72d60495cd47423c572506e8042abe578bbd6a/example/gluon/style_transfer/main.py#L145 Any guidance would be greatly celebrated. |
This clumsy attempt wont work because you cannot convert a symbol to an int. |
Description
see: https://github.com/zhanghang1989/MXNet-Gluon-Style-Transfer/issues/2
within https://github.com/apache/incubator-mxnet/tree/master/example/gluon/style_transfer
There are a number of Hybrid* with only forward and not hybrid forward defined, so the model cannot be serialised to a Symbol network, as a described in:
https://mxnet.incubator.apache.org/tutorials/gluon/hybrid.html
Environment info (Required)
----------Python Info----------
('Version :', '2.7.14')
('Compiler :', 'GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)')
('Build :', ('default', 'Dec 7 2017 11:07:58'))
('Arch :', ('64bit', ''))
------------Pip Info-----------
('Version :', '9.0.1')
('Directory :', '/Users/sam/anaconda2/lib/python2.7/site-packages/pip')
----------MXNet Info-----------
/Users/sam/anaconda2/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py:46: DeprecationWarning: OpenSSL.rand is deprecated - you should use os.urandom instead
import OpenSSL.SSL
('Version :', '1.0.0')
('Directory :', '/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet')
('Commit Hash :', '9ef196909ec7bf9cdda66d5b97c92793109798e1')
----------System Info----------
('Platform :', 'Darwin-16.7.0-x86_64-i386-64bit')
('system :', 'Darwin')
('node :', 'kaos.fritz.box')
('release :', '16.7.0')
('version :', 'Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64')
----------Hardware Info----------
('machine :', 'x86_64')
('processor :', 'i386')
machdep.cpu.extfeatures: SYSCALL XD 1GBPAGE EM64T LAHF LZCNT PREFETCHW RDTSCP TSCI
machdep.cpu.leaf7_features: SMEP ERMS RDWRFSGS TSC_THREAD_OFFSET BMI1 HLE AVX2 BMI2 INVPCID RTM SMAP RDSEED ADX IPT SGX FPU_CSDS MPX CLFSOPT
machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTES64 MON DSCPL VMX SMX EST TM2 SSSE3 FMA CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC MOVBE POPCNT AES PCID XSAVE OSXSAVE SEGLIM64 TSCTMR AVX1.0 RDRAND F16C
machdep.cpu.brand_string: Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
----------Network Test----------
Setting timeout: 10
Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.2019 sec, LOAD: 1.9668 sec.
Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.0498 sec, LOAD: 0.4649 sec.
Timing for FashionMNIST: https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.0760 sec, LOAD: 2.2928 sec.
Timing for Conda: https://repo.continuum.io/pkgs/free/, DNS: 1.2123 sec, LOAD: 1.5902 sec.
Timing for Gluon Tutorial(en): http://gluon.mxnet.io, DNS: 0.2438 sec, LOAD: 0.9825 sec.
Timing for Gluon Tutorial(cn): https://zh.gluon.ai, DNS: 0.3199 sec, LOAD: 2.5883 sec.
Package used (Python/R/Scala/Julia):
Im using Python
Error Message:
File "/asset/common/software/thirdparty/mxnet/1.0.0-build1/python2.7/mxnet/gluon/block.py", line 360, in call
return self.forward(*args)
File "/home/samh/dev/MXNet-Gluon-Style-Transfer/net.py", line 215, in forward
return self.model(input)
File "/asset/common/software/thirdparty/mxnet/1.0.0-build1/python2.7/mxnet/gluon/block.py", line 360, in call
return self.forward(*args)
File "/asset/common/software/thirdparty/mxnet/1.0.0-build1/python2.7/mxnet/gluon/nn/basic_layers.py", line 53, in forward
x = block(x)
File "/asset/common/software/thirdparty/mxnet/1.0.0-build1/python2.7/mxnet/gluon/block.py", line 360, in call
return self.forward(*args)
File "/asset/common/software/thirdparty/mxnet/1.0.0-build1/python2.7/mxnet/gluon/nn/basic_layers.py", line 53, in forward
x = block(x)
File "/asset/common/software/thirdparty/mxnet/1.0.0-build1/python2.7/mxnet/gluon/block.py", line 360, in call
return self.forward(*args)
File "/home/samh/dev/MXNet-Gluon-Style-Transfer/net.py", line 123, in forward
x = self.pad(x)
File "/asset/common/software/thirdparty/mxnet/1.0.0-build1/python2.7/mxnet/gluon/block.py", line 360, in call
return self.forward(*args)
File "/home/samh/dev/MXNet-Gluon-Style-Transfer/net.py", line 44, in forward
return F.pad(x, mode='reflect', pad_width=self.pad_width)
File "", line 112, in pad
AssertionError: Argument data must have NDArray type, but got
Minimum reproducible example
Adding the following lines
x = mx.sym.var('data') y = style_model(x) y_json = y.tojson() y.save("MODEL.json") y.save_params("MODEL.params")
to the end of the evaluate function of
https://github.com/apache/incubator-mxnet/blob/master/example/gluon/style_transfer/net.py
and running
python main.py eval
with argument to a valid model, style image and output image
Steps to reproduce
As described edit the source file https://github.com/apache/incubator-mxnet/blob/master/example/gluon/style_transfer/net.py to allow for converting the Net model to a symbolic model , try to save the symbolic model, it fails because hybrid_forward functions are not implemented.
What have you tried to solve it?
I have tried replacing the forward functions with hybrid_forward functions but have been unable to convert the Inspiration(HybridBlock)
This would provide an excellent example of training in Python and deploying in C++ if possible
The text was updated successfully, but these errors were encountered: