You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@mxnet.apache.org by niklongstone via MXNet Forum <mx...@discoursemail.com.INVALID> on 2021/05/04 09:15:29 UTC

[MXNet Forum] Export and Import pre-trained model


I would like to tweak a pre-trained model, export it and import in another system.
I am having issues as soon as I change the classes (see code below).
Ideally I would like to export architecture and weight and then use gluon.nn.SymbolBlock.imports

    from gluoncv import model_zoo, data, utils
    from matplotlib import pyplot as plt
    net = model_zoo.get_model('yolo3_darknet53_voc', pretrained=True)
    my_classes = ['car']
    net.reset_class(classes=my_classes, reuse_weights=my_classes)
    net.save_parameters('mymodel.params')
    new_net = net = model_zoo.get_model('yolo3_darknet53_voc', pretrained=False)
    new_net.load_parameters('mymodel.params')

I've got error shape incompatible.
Could someone explain how to do that using gluon.nn.SymbolBlock.imports
Thanks





---
[Visit Topic](https://discuss.mxnet.apache.org/t/export-and-import-pre-trained-model/6947/1) or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.mxnet.apache.org/email/unsubscribe/081de4e2a09b911bd9ad3bd371cec4992da2b0a2dcc5ea9bce3971a657e0f003).

[MXNet Forum] Export and Import pre-trained model

Posted by niklongstone via MXNet Forum <mx...@discoursemail.com.INVALID>.

I found the right way

```
from gluoncv import model_zoo, data, utils
from matplotlib import pyplot as plt
net = model_zoo.get_model('yolo3_darknet53_voc', pretrained=True)
my_classes = ['car']
net.reset_class(classes=my_classes, reuse_weights=my_classes)
x = nd.random.uniform(shape=(1, 3, 512, 512))
_ = net(x)
net.export("sample_model")
```

Then, the model can be imported with gluon.nn.SymbolBlock.imports.
Note that the classes parameters won't be available and so you can run an assignment as
```
imported_model.class = my_classes
```





---
[Visit Topic](https://discuss.mxnet.apache.org/t/export-and-import-pre-trained-model/6947/2) or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.mxnet.apache.org/email/unsubscribe/5f69b129fdc58c96a460fe03c697c648181ffe16e1ad91354866ab5d3f284aa6).