Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Unable to save gluon model to symbolic network : neural style #9813

Closed
samhodge opened this issue Feb 16, 2018 · 22 comments · Fixed by #11044
Closed

Unable to save gluon model to symbolic network : neural style #9813

samhodge opened this issue Feb 16, 2018 · 22 comments · Fixed by #11044

Comments

@samhodge
Copy link

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

@samhodge
Copy link
Author

I have had a bit of a fiddle but I am getting lost
have a look here:
samhodge@5b5c39b

But I am currently getting the following:

Traceback (most recent call last): 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 226, 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 514, 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 108, 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 514, in forward return self.hybrid_forward(ndarray, x, *args, **params) TypeError: hybrid_forward() takes exactly 5 arguments (3 given)

from

python main.py train --dataset dataset --style-folder images/styles --save-model-dir models --cuda 0

Note that main.py needed a minor edit also.

@samhodge
Copy link
Author

samhodge commented Feb 19, 2018

I have continued on further see

python main.py train --dataset dataset --style-folder images/styles --save-model-dir models --cuda 0
with

samhodge@949993f

yields

  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

@Roshrini
Copy link
Member

Roshrini commented Feb 19, 2018

@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

@anirudh2290
Copy link
Member

@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.

@samhodge
Copy link
Author

thanks for the help, I will continue with this advice.

@samhodge
Copy link
Author

I think I have got something working:

samhodge@2ae6e2e

currently no errors, I am training without CUDA, so it could take some time.

@samhodge
Copy link
Author

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.

@samhodge
Copy link
Author

samhodge commented Feb 21, 2018

OK here are my latest commits:
samhodge@c072d8d
samhodge@dcd0e55

this allows me to execute the following from the command line

python main.py eval --content-image ~/Desktop/bapic.png --output-image out.png --style-image images/styles/starry_night.jpg --model models/Epoch_0iters_8000_Wed_Feb_21_11\:58\:24_2018_1.0_5.0.params --cuda 0

Which results in

/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
Traceback (most recent call last):
  File "main.py", line 234, in <module>
    main()
  File "main.py", line 223, in main
    evaluate(args)
  File "main.py", line 150, in evaluate
    y = style_model(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 523, in forward
    return self.hybrid_forward(symbol, x, *args, **params)
  File "/Users/sam/dev/incubator-mxnet/example/gluon/style_transfer/net.py", line 297, in hybrid_forward
    return self.model(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 523, in forward
    return self.hybrid_forward(symbol, x, *args, **params)
  File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/gluon/nn/basic_layers.py", line 108, 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 523, in forward
    return self.hybrid_forward(symbol, x, *args, **params)
  File "/Users/sam/dev/incubator-mxnet/example/gluon/style_transfer/net.py", line 324, in hybrid_forward
    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)
  File "<string>", line 54, in SwapAxis
AssertionError: Argument data must be Symbol instances, but got 
[[[-0.04 -0.03 -0.02 ...,  0.02 -0.03  0.05]
  [-0.02 -0.02  0.   ..., -0.01 -0.01  0.03]
  [-0.01  0.02  0.04 ...,  0.01 -0.02 -0.03]
  ..., 
  [ 0.02  0.01  0.03 ..., -0.1  -0.05 -0.  ]
  [ 0.06 -0.03 -0.03 ..., -0.06 -0.01 -0.  ]
  [-0.01 -0.02  0.   ...,  0.03  0.   -0.04]]]
<NDArray 1x512x512 @cpu(0)>

So what I need to do now is work on:

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)
        self.P = F.batch_dot(F.broadcast_to(self.weight.data(), shape=(self.gram.shape)), self.gram.data())
    def setTarget(self, target):
        self.gram.set_data(target)
    def hybrid_forward(self, F, X, gram, weight):
        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) + ')'

The attempt

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):
        self.P = F.batch_dot(F.broadcast_to(weight, shape=(self.gram.shape)), gram)
        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) + ')'

instead results in

Traceback (most recent call last):
  File "main.py", line 234, in <module>
    main()
  File "main.py", line 223, in main
    evaluate(args)
  File "main.py", line 150, in evaluate
    y = style_model(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 523, in forward
    return self.hybrid_forward(symbol, x, *args, **params)
  File "/Users/sam/dev/incubator-mxnet/example/gluon/style_transfer/net.py", line 297, in hybrid_forward
    return self.model(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 523, in forward
    return self.hybrid_forward(symbol, x, *args, **params)
  File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/gluon/nn/basic_layers.py", line 108, 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 523, in forward
    return self.hybrid_forward(symbol, x, *args, **params)
  File "/Users/sam/dev/incubator-mxnet/example/gluon/style_transfer/net.py", line 325, in hybrid_forward
    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)
AttributeError: 'Symbol' object has no attribute 'shape'

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.

@anirudh2290
Copy link
Member

can you try infer_shape without arguments ?

@samhodge
Copy link
Author

OK I tried some things
I got it to save out a symbolic model

see
samhodge@b9ea449

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.

@anirudh2290
Copy link
Member

do you have a validation dataset to test the model ?

@samhodge
Copy link
Author

I found this a little bit of help: #1337

samhodge added a commit to samhodge/incubator-mxnet that referenced this issue Feb 24, 2018
… 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
@samhodge
Copy link
Author

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
plot.gv.pdf
Does this look correct?

Here is my latest commit:
samhodge@48a0e1a

@samhodge
Copy link
Author

Now I have a new error

________________________________________________________________________________________________________________________
Layer (type)                                        Output Shape            Param #     Previous Layer                  
========================================================================================================================
net0_inspiration0_weight(null)                      512x512                 0                                           
________________________________________________________________________________________________________________________
net0_inspiration0_broadcast_to0(broadcast_to)       512x512                 0           net0_inspiration0_weight        
________________________________________________________________________________________________________________________
net0_inspiration0_batch_dot0(batch_dot)             512x512                 0           net0_inspiration0_broadcast_to0 
________________________________________________________________________________________________________________________
net0_inspiration0_swapaxis0(SwapAxis)               512x512                 0           net0_inspiration0_batch_dot0    
________________________________________________________________________________________________________________________
net0_inspiration0_broadcast_to1(broadcast_to)       512x512                 0           net0_inspiration0_swapaxis0     
________________________________________________________________________________________________________________________
net0_reflectancepadding0_pad0(Pad)                  3x1926x1086             0                                           
________________________________________________________________________________________________________________________
Traceback (most recent call last):
  File "main.py", line 240, in <module>
    main()
  File "main.py", line 229, in main
    evaluate(args)
  File "main.py", line 159, in evaluate
    mx.visualization.print_summary(y,{'data':(1,3,1920,1080)})
  File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/visualization.py", line 184, in print_summary
    total_params += print_layer_summary(nodes[i], out_shape)
  File "/Users/sam/anaconda2/lib/python2.7/site-packages/mxnet/visualization.py", line 137, in print_layer_summary
    if ("no_bias" in node["attrs"]) and int(node["attrs"]["no_bias"]):
ValueError: invalid literal for int() with base 10: 'False'
kaos:style_transfer sam$ python -c 'int("False")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'False'

I will hack visualisation for now.

@samhodge
Copy link
Author

The hack

def print_summary(symbol, shape=None, line_length=120, positions=[.44, .64, .74, 1.]):
    """Convert symbol for detail information.

    Parameters
    ----------
    symbol: Symbol
        Symbol to be visualized.
    shape: dict
        A dict of shapes, str->shape (tuple), given input shapes.
    line_length: int
        Rotal length of printed lines
    positions: list
        Relative or absolute positions of log elements in each line.
    Returns
    ------
    None
    """
    if not isinstance(symbol, Symbol):
        raise TypeError("symbol must be Symbol")
    show_shape = False
    if shape is not None:
        show_shape = True
        interals = symbol.get_internals()
        _, out_shapes, _ = interals.infer_shape(**shape)
        if out_shapes is None:
            raise ValueError("Input shape is incomplete")
        shape_dict = dict(zip(interals.list_outputs(), out_shapes))
    conf = json.loads(symbol.tojson())
    nodes = conf["nodes"]
    heads = set(conf["heads"][0])
    if positions[-1] <= 1:
        positions = [int(line_length * p) for p in positions]
    # header names for the different log elements
    to_display = ['Layer (type)', 'Output Shape', 'Param #', 'Previous Layer']
    def print_row(fields, positions):
        """Print format row.

        Parameters
        ----------
        fields: list
            Information field.
        positions: list
            Field length ratio.
        Returns
        ------
        None
        """
        line = ''
        for i, field in enumerate(fields):
            line += str(field)
            line = line[:positions[i]]
            line += ' ' * (positions[i] - len(line))
        print(line)
    print('_' * line_length)
    print_row(to_display, positions)
    print('=' * line_length)
    def print_layer_summary(node, out_shape):
        """print layer information

        Parameters
        ----------
        node: dict
            Node information.
        out_shape: dict
            Node shape information.
        Returns
        ------
            Node total parameters.
        """
        op = node["op"]
        pre_node = []
        pre_filter = 0
        if op != "null":
            inputs = node["inputs"]
            for item in inputs:
                input_node = nodes[item[0]]
                input_name = input_node["name"]
                if input_node["op"] != "null" or item[0] in heads:
                    # add precede
                    pre_node.append(input_name)
                    if show_shape:
                        if input_node["op"] != "null":
                            key = input_name + "_output"
                        else:
                            key = input_name
                        if key in shape_dict:
                            shape = shape_dict[key][1:]
                            pre_filter = pre_filter + int(shape[0])
        cur_param = 0
        if op == 'Convolution':
            if ("no_bias" in node["attrs"]) and (isinstance(node["attrs"]["no_bias"],(bool,int)) and int(node["attrs"]["no_bias"])) or ((isinstance(node["attrs"]["no_bias"],(str)) and bool(node["attrs"]["no_bias"]))):
                cur_param = pre_filter * int(node["attrs"]["num_filter"])
                for k in _str2tuple(node["attrs"]["kernel"]):
                    cur_param *= int(k)
            else:
                cur_param = pre_filter * int(node["attrs"]["num_filter"])
                for k in _str2tuple(node["attrs"]["kernel"]):
                    cur_param *= int(k)
                cur_param += int(node["attrs"]["num_filter"])
        elif op == 'FullyConnected':
            if ("no_bias" in node["attrs"]) and int(node["attrs"]["no_bias"]):
                cur_param = pre_filter * (int(node["attrs"]["num_hidden"]))
            else:
                cur_param = (pre_filter+1) * (int(node["attrs"]["num_hidden"]))
        elif op == 'BatchNorm':
            key = node["name"] + "_output"
            if show_shape:
                num_filter = shape_dict[key][1]
                cur_param = int(num_filter) * 2
        if not pre_node:
            first_connection = ''
        else:
            first_connection = pre_node[0]
        fields = [node['name'] + '(' + op + ')',
                  "x".join([str(x) for x in out_shape]),
                  cur_param,
                  first_connection]
        print_row(fields, positions)
        if len(pre_node) > 1:
            for i in range(1, len(pre_node)):
                fields = ['', '', '', pre_node[i]]
                print_row(fields, positions)
        return cur_param
    total_params = 0
    for i, node in enumerate(nodes):
        out_shape = []
        op = node["op"]
        if op == "null" and i > 0:
            continue
        if op != "null" or i in heads:
            if show_shape:
                if op != "null":
                    key = node["name"] + "_output"
                else:
                    key = node["name"]
                if key in shape_dict:
                    out_shape = shape_dict[key][1:]
        total_params += print_layer_summary(nodes[i], out_shape)
        if i == len(nodes) - 1:
            print('=' * line_length)
        else:
            print('_' * line_length)
    print('Total params: %s' % total_params)
    print('_' * line_length)

And the result:

________________________________________________________________________________________________________________________
Layer (type)                                        Output Shape            Param #     Previous Layer                  
========================================================================================================================
net0_inspiration0_weight(null)                      512x512                 0                                           
________________________________________________________________________________________________________________________
net0_inspiration0_broadcast_to0(broadcast_to)       512x512                 0           net0_inspiration0_weight        
________________________________________________________________________________________________________________________
net0_inspiration0_batch_dot0(batch_dot)             512x512                 0           net0_inspiration0_broadcast_to0 
________________________________________________________________________________________________________________________
net0_inspiration0_swapaxis0(SwapAxis)               512x512                 0           net0_inspiration0_batch_dot0    
________________________________________________________________________________________________________________________
net0_inspiration0_broadcast_to1(broadcast_to)       512x512                 0           net0_inspiration0_swapaxis0     
________________________________________________________________________________________________________________________
net0_reflectancepadding0_pad0(Pad)                  3x1926x1086             0                                           
________________________________________________________________________________________________________________________
net0_conv0_fwd(Convolution)                         64x1920x1080            9472        net0_reflectancepadding0_pad0   
________________________________________________________________________________________________________________________
net0_instancenorm0_fwd(InstanceNorm)                64x1920x1080            0           net0_conv0_fwd                  
________________________________________________________________________________________________________________________
net0_relu0_fwd(Activation)                          64x1920x1080            0           net0_instancenorm0_fwd          
________________________________________________________________________________________________________________________
net0_conv1_fwd(Convolution)                         128x960x540             8320        net0_relu0_fwd                  
________________________________________________________________________________________________________________________
net0_hybridsequential2_instancenorm0_fwd(InstanceNor64x1920x1080            0           net0_relu0_fwd                  
________________________________________________________________________________________________________________________
net0_hybridsequential2_relu0_fwd(Activation)        64x1920x1080            0           net0_hybridsequential2_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential2_conv0_fwd(Convolution)       32x1920x1080            2080        net0_hybridsequential2_relu0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential2_instancenorm1_fwd(InstanceNor32x1920x1080            0           net0_hybridsequential2_conv0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential2_relu1_fwd(Activation)        32x1920x1080            0           net0_hybridsequential2_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential2_reflectancepadding0_pad0(Pad)32x1922x1082            0           net0_hybridsequential2_relu1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential2_conv1_fwd(Convolution)       32x960x540              9248        net0_hybridsequential2_reflectan
________________________________________________________________________________________________________________________
net0_hybridsequential2_instancenorm2_fwd(InstanceNor32x960x540              0           net0_hybridsequential2_conv1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential2_relu2_fwd(Activation)        32x960x540              0           net0_hybridsequential2_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential2_conv2_fwd(Convolution)       128x960x540             4224        net0_hybridsequential2_relu2_fwd
________________________________________________________________________________________________________________________
net0_bottleneck0__plus0(elemwise_add)               128x960x540             0           net0_conv1_fwd                  
                                                                                        net0_hybridsequential2_conv2_fwd
________________________________________________________________________________________________________________________
net0_conv2_fwd(Convolution)                         512x480x270             66048       net0_bottleneck0__plus0         
________________________________________________________________________________________________________________________
net0_hybridsequential3_instancenorm0_fwd(InstanceNor128x960x540             0           net0_bottleneck0__plus0         
________________________________________________________________________________________________________________________
net0_hybridsequential3_relu0_fwd(Activation)        128x960x540             0           net0_hybridsequential3_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential3_conv0_fwd(Convolution)       128x960x540             16512       net0_hybridsequential3_relu0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential3_instancenorm1_fwd(InstanceNor128x960x540             0           net0_hybridsequential3_conv0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential3_relu1_fwd(Activation)        128x960x540             0           net0_hybridsequential3_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential3_reflectancepadding0_pad0(Pad)128x962x542             0           net0_hybridsequential3_relu1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential3_conv1_fwd(Convolution)       128x480x270             147584      net0_hybridsequential3_reflectan
________________________________________________________________________________________________________________________
net0_hybridsequential3_instancenorm2_fwd(InstanceNor128x480x270             0           net0_hybridsequential3_conv1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential3_relu2_fwd(Activation)        128x480x270             0           net0_hybridsequential3_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential3_conv2_fwd(Convolution)       512x480x270             66048       net0_hybridsequential3_relu2_fwd
________________________________________________________________________________________________________________________
net0_bottleneck1__plus0(elemwise_add)               512x480x270             0           net0_conv2_fwd                  
                                                                                        net0_hybridsequential3_conv2_fwd
________________________________________________________________________________________________________________________
net0_inspiration0_reshape0(Reshape)                 512x129600              0           net0_bottleneck1__plus0         
________________________________________________________________________________________________________________________
net0_inspiration0_batch_dot1(batch_dot)             512x129600              0           net0_inspiration0_broadcast_to1 
                                                                                        net0_inspiration0_reshape0      
________________________________________________________________________________________________________________________
net0_inspiration0_reshape1(Reshape)                 512x480x270             0           net0_inspiration0_batch_dot1    
________________________________________________________________________________________________________________________
net0_hybridsequential4_instancenorm0_fwd(InstanceNor512x480x270             0           net0_inspiration0_reshape1      
________________________________________________________________________________________________________________________
net0_hybridsequential4_relu0_fwd(Activation)        512x480x270             0           net0_hybridsequential4_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential4_conv0_fwd(Convolution)       128x480x270             65664       net0_hybridsequential4_relu0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential4_instancenorm1_fwd(InstanceNor128x480x270             0           net0_hybridsequential4_conv0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential4_relu1_fwd(Activation)        128x480x270             0           net0_hybridsequential4_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential4_reflectancepadding0_pad0(Pad)128x482x272             0           net0_hybridsequential4_relu1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential4_conv1_fwd(Convolution)       128x480x270             147584      net0_hybridsequential4_reflectan
________________________________________________________________________________________________________________________
net0_hybridsequential4_instancenorm2_fwd(InstanceNor128x480x270             0           net0_hybridsequential4_conv1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential4_relu2_fwd(Activation)        128x480x270             0           net0_hybridsequential4_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential4_conv2_fwd(Convolution)       512x480x270             66048       net0_hybridsequential4_relu2_fwd
________________________________________________________________________________________________________________________
net0_bottleneck2__plus0(elemwise_add)               512x480x270             0           net0_inspiration0_reshape1      
                                                                                        net0_hybridsequential4_conv2_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential5_instancenorm0_fwd(InstanceNor512x480x270             0           net0_bottleneck2__plus0         
________________________________________________________________________________________________________________________
net0_hybridsequential5_relu0_fwd(Activation)        512x480x270             0           net0_hybridsequential5_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential5_conv0_fwd(Convolution)       128x480x270             65664       net0_hybridsequential5_relu0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential5_instancenorm1_fwd(InstanceNor128x480x270             0           net0_hybridsequential5_conv0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential5_relu1_fwd(Activation)        128x480x270             0           net0_hybridsequential5_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential5_reflectancepadding0_pad0(Pad)128x482x272             0           net0_hybridsequential5_relu1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential5_conv1_fwd(Convolution)       128x480x270             147584      net0_hybridsequential5_reflectan
________________________________________________________________________________________________________________________
net0_hybridsequential5_instancenorm2_fwd(InstanceNor128x480x270             0           net0_hybridsequential5_conv1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential5_relu2_fwd(Activation)        128x480x270             0           net0_hybridsequential5_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential5_conv2_fwd(Convolution)       512x480x270             66048       net0_hybridsequential5_relu2_fwd
________________________________________________________________________________________________________________________
net0_bottleneck3__plus0(elemwise_add)               512x480x270             0           net0_bottleneck2__plus0         
                                                                                        net0_hybridsequential5_conv2_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential6_instancenorm0_fwd(InstanceNor512x480x270             0           net0_bottleneck3__plus0         
________________________________________________________________________________________________________________________
net0_hybridsequential6_relu0_fwd(Activation)        512x480x270             0           net0_hybridsequential6_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential6_conv0_fwd(Convolution)       128x480x270             65664       net0_hybridsequential6_relu0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential6_instancenorm1_fwd(InstanceNor128x480x270             0           net0_hybridsequential6_conv0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential6_relu1_fwd(Activation)        128x480x270             0           net0_hybridsequential6_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential6_reflectancepadding0_pad0(Pad)128x482x272             0           net0_hybridsequential6_relu1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential6_conv1_fwd(Convolution)       128x480x270             147584      net0_hybridsequential6_reflectan
________________________________________________________________________________________________________________________
net0_hybridsequential6_instancenorm2_fwd(InstanceNor128x480x270             0           net0_hybridsequential6_conv1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential6_relu2_fwd(Activation)        128x480x270             0           net0_hybridsequential6_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential6_conv2_fwd(Convolution)       512x480x270             66048       net0_hybridsequential6_relu2_fwd
________________________________________________________________________________________________________________________
net0_bottleneck4__plus0(elemwise_add)               512x480x270             0           net0_bottleneck3__plus0         
                                                                                        net0_hybridsequential6_conv2_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential7_instancenorm0_fwd(InstanceNor512x480x270             0           net0_bottleneck4__plus0         
________________________________________________________________________________________________________________________
net0_hybridsequential7_relu0_fwd(Activation)        512x480x270             0           net0_hybridsequential7_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential7_conv0_fwd(Convolution)       128x480x270             65664       net0_hybridsequential7_relu0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential7_instancenorm1_fwd(InstanceNor128x480x270             0           net0_hybridsequential7_conv0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential7_relu1_fwd(Activation)        128x480x270             0           net0_hybridsequential7_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential7_reflectancepadding0_pad0(Pad)128x482x272             0           net0_hybridsequential7_relu1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential7_conv1_fwd(Convolution)       128x480x270             147584      net0_hybridsequential7_reflectan
________________________________________________________________________________________________________________________
net0_hybridsequential7_instancenorm2_fwd(InstanceNor128x480x270             0           net0_hybridsequential7_conv1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential7_relu2_fwd(Activation)        128x480x270             0           net0_hybridsequential7_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential7_conv2_fwd(Convolution)       512x480x270             66048       net0_hybridsequential7_relu2_fwd
________________________________________________________________________________________________________________________
net0_bottleneck5__plus0(elemwise_add)               512x480x270             0           net0_bottleneck4__plus0         
                                                                                        net0_hybridsequential7_conv2_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential8_instancenorm0_fwd(InstanceNor512x480x270             0           net0_bottleneck5__plus0         
________________________________________________________________________________________________________________________
net0_hybridsequential8_relu0_fwd(Activation)        512x480x270             0           net0_hybridsequential8_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential8_conv0_fwd(Convolution)       128x480x270             65664       net0_hybridsequential8_relu0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential8_instancenorm1_fwd(InstanceNor128x480x270             0           net0_hybridsequential8_conv0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential8_relu1_fwd(Activation)        128x480x270             0           net0_hybridsequential8_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential8_reflectancepadding0_pad0(Pad)128x482x272             0           net0_hybridsequential8_relu1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential8_conv1_fwd(Convolution)       128x480x270             147584      net0_hybridsequential8_reflectan
________________________________________________________________________________________________________________________
net0_hybridsequential8_instancenorm2_fwd(InstanceNor128x480x270             0           net0_hybridsequential8_conv1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential8_relu2_fwd(Activation)        128x480x270             0           net0_hybridsequential8_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential8_conv2_fwd(Convolution)       512x480x270             66048       net0_hybridsequential8_relu2_fwd
________________________________________________________________________________________________________________________
net0_bottleneck6__plus0(elemwise_add)               512x480x270             0           net0_bottleneck5__plus0         
                                                                                        net0_hybridsequential8_conv2_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential9_instancenorm0_fwd(InstanceNor512x480x270             0           net0_bottleneck6__plus0         
________________________________________________________________________________________________________________________
net0_hybridsequential9_relu0_fwd(Activation)        512x480x270             0           net0_hybridsequential9_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential9_conv0_fwd(Convolution)       128x480x270             65664       net0_hybridsequential9_relu0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential9_instancenorm1_fwd(InstanceNor128x480x270             0           net0_hybridsequential9_conv0_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential9_relu1_fwd(Activation)        128x480x270             0           net0_hybridsequential9_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential9_reflectancepadding0_pad0(Pad)128x482x272             0           net0_hybridsequential9_relu1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential9_conv1_fwd(Convolution)       128x480x270             147584      net0_hybridsequential9_reflectan
________________________________________________________________________________________________________________________
net0_hybridsequential9_instancenorm2_fwd(InstanceNor128x480x270             0           net0_hybridsequential9_conv1_fwd
________________________________________________________________________________________________________________________
net0_hybridsequential9_relu2_fwd(Activation)        128x480x270             0           net0_hybridsequential9_instancen
________________________________________________________________________________________________________________________
net0_hybridsequential9_conv2_fwd(Convolution)       512x480x270             66048       net0_hybridsequential9_relu2_fwd
________________________________________________________________________________________________________________________
net0_bottleneck7__plus0(elemwise_add)               512x480x270             0           net0_bottleneck6__plus0         
                                                                                        net0_hybridsequential9_conv2_fwd
________________________________________________________________________________________________________________________
net0_upsampleconvlayer0_upsampling0(UpSampling)     512x960x540             0           net0_bottleneck7__plus0         
________________________________________________________________________________________________________________________
net0_conv3_fwd(Convolution)                         128x960x540             65664       net0_upsampleconvlayer0_upsampli
________________________________________________________________________________________________________________________
net0_hybridsequential10_instancenorm0_fwd(InstanceNo512x480x270             0           net0_bottleneck7__plus0         
________________________________________________________________________________________________________________________
net0_hybridsequential10_relu0_fwd(Activation)       512x480x270             0           net0_hybridsequential10_instance
________________________________________________________________________________________________________________________
net0_hybridsequential10_conv0_fwd(Convolution)      32x480x270              16416       net0_hybridsequential10_relu0_fw
________________________________________________________________________________________________________________________
net0_hybridsequential10_instancenorm1_fwd(InstanceNo32x480x270              0           net0_hybridsequential10_conv0_fw
________________________________________________________________________________________________________________________
net0_hybridsequential10_relu1_fwd(Activation)       32x480x270              0           net0_hybridsequential10_instance
________________________________________________________________________________________________________________________
net0_hybridsequential10_upsampleconvlayer0_upsamplin32x960x540              0           net0_hybridsequential10_relu1_fw
________________________________________________________________________________________________________________________
net0_hybridsequential10_conv1_fwd(Convolution)      32x960x540              9248        net0_hybridsequential10_upsample
________________________________________________________________________________________________________________________
net0_hybridsequential10_instancenorm2_fwd(InstanceNo32x960x540              0           net0_hybridsequential10_conv1_fw
________________________________________________________________________________________________________________________
net0_hybridsequential10_relu2_fwd(Activation)       32x960x540              0           net0_hybridsequential10_instance
________________________________________________________________________________________________________________________
net0_hybridsequential10_conv2_fwd(Convolution)      128x960x540             4224        net0_hybridsequential10_relu2_fw
________________________________________________________________________________________________________________________
net0_upbottleneck0__plus0(elemwise_add)             128x960x540             0           net0_conv3_fwd                  
                                                                                        net0_hybridsequential10_conv2_fw
________________________________________________________________________________________________________________________
net0_upsampleconvlayer1_upsampling0(UpSampling)     128x1920x1080           0           net0_upbottleneck0__plus0       
________________________________________________________________________________________________________________________
net0_conv4_fwd(Convolution)                         64x1920x1080            8256        net0_upsampleconvlayer1_upsampli
________________________________________________________________________________________________________________________
net0_hybridsequential11_instancenorm0_fwd(InstanceNo128x960x540             0           net0_upbottleneck0__plus0       
________________________________________________________________________________________________________________________
net0_hybridsequential11_relu0_fwd(Activation)       128x960x540             0           net0_hybridsequential11_instance
________________________________________________________________________________________________________________________
net0_hybridsequential11_conv0_fwd(Convolution)      16x960x540              2064        net0_hybridsequential11_relu0_fw
________________________________________________________________________________________________________________________
net0_hybridsequential11_instancenorm1_fwd(InstanceNo16x960x540              0           net0_hybridsequential11_conv0_fw
________________________________________________________________________________________________________________________
net0_hybridsequential11_relu1_fwd(Activation)       16x960x540              0           net0_hybridsequential11_instance
________________________________________________________________________________________________________________________
net0_hybridsequential11_upsampleconvlayer0_upsamplin16x1920x1080            0           net0_hybridsequential11_relu1_fw
________________________________________________________________________________________________________________________
net0_hybridsequential11_conv1_fwd(Convolution)      16x1920x1080            2320        net0_hybridsequential11_upsample
________________________________________________________________________________________________________________________
net0_hybridsequential11_instancenorm2_fwd(InstanceNo16x1920x1080            0           net0_hybridsequential11_conv1_fw
________________________________________________________________________________________________________________________
net0_hybridsequential11_relu2_fwd(Activation)       16x1920x1080            0           net0_hybridsequential11_instance
________________________________________________________________________________________________________________________
net0_hybridsequential11_conv2_fwd(Convolution)      64x1920x1080            1088        net0_hybridsequential11_relu2_fw
________________________________________________________________________________________________________________________
net0_upbottleneck1__plus0(elemwise_add)             64x1920x1080            0           net0_conv4_fwd                  
                                                                                        net0_hybridsequential11_conv2_fw
________________________________________________________________________________________________________________________
net0_instancenorm1_fwd(InstanceNorm)                64x1920x1080            0           net0_upbottleneck1__plus0       
________________________________________________________________________________________________________________________
net0_relu1_fwd(Activation)                          64x1920x1080            0           net0_instancenorm1_fwd          
________________________________________________________________________________________________________________________
net0_reflectancepadding1_pad0(Pad)                  64x1926x1086            0           net0_relu1_fwd                  
________________________________________________________________________________________________________________________
net0_conv5_fwd(Convolution)                         3x1920x1080             9411        net0_reflectancepadding1_pad0   
========================================================================================================================
Total params: 2124003
________________________________________________________________________________________________________________________

@samhodge
Copy link
Author

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.

@samhodge
Copy link
Author

OK a minor update to generalise the model to the width and height of the input

samhodge@1d72d60

@samhodge
Copy link
Author

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.

@anirudh2290
Copy link
Member

@samhodge the model makes calls to operators implemented in the C++ backend and leverages the backend dependency engine.

@samhodge
Copy link
Author

samhodge commented Feb 25, 2018

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.

@samhodge
Copy link
Author

This clumsy attempt wont work because you cannot convert a symbol to an int.

@anirudh2290
Copy link
Member

anirudh2290 commented Feb 28, 2018

@samhodge this pr once merged should help with your use case: #9893

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants