Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to export my own mobilenet1.0 #982

Closed
ou525 opened this issue Oct 12, 2019 · 14 comments
Closed

how to export my own mobilenet1.0 #982

ou525 opened this issue Oct 12, 2019 · 14 comments

Comments

@ou525
Copy link

ou525 commented Oct 12, 2019

i train my own data using train_imagenet.py. but i donot how to export the model to mxnet.
i try:

import gluoncv as gcv
from gluoncv.utils import export_block

net = gcv.model_zoo.get_model('mobilenet1.0', pretrained=True)
net.load_parameters('./0.0877-imagenet-mobilenet1.0-88-best.params')
export_block('mobilenet1.0', net, preprocess=True, layout='HWC')
print('Done.')
But there was an error, how can I solve it?

error:
Traceback (most recent call last):
File "export_class.py", line 5, in
net.load_parameters('/home/ou/workplace/tmp_model/0.0877-imagenet-mobilenet1.0-88-best.params')
File "/usr/local/lib/python2.7/dist-packages/mxnet/gluon/block.py", line 410, in load_parameters
params[name]._load_init(loaded[name], ctx, cast_dtype=cast_dtype, dtype_source=dtype_source)
File "/usr/local/lib/python2.7/dist-packages/mxnet/gluon/parameter.py", line 279, in _load_init
self.name, str(self.shape), str(data.shape))
AssertionError: Failed loading Parameter 'mobilenet0_dense0_weight' from saved params: shape incompatible expected (1000, 1024) vs saved (5, 1024)

@hetong007
Copy link
Member

Use

net = gcv.model_zoo.get_model('mobilenet1.0', classes=5)

instead.

@ou525
Copy link
Author

ou525 commented Oct 14, 2019

@hetong007 ,thank you for you reply, i try do it ,but error still happen, as follow:
self.name, str(self.shape), str(data.shape))
AssertionError: Failed loading Parameter 'mobilenet0_dense0_weight' from saved params: shape incompatible expected (5, 0) vs saved (1000, 1024)

@hetong007
Copy link
Member

basically the idea is to use the same model definition in both training and test.

So, let ask: how did you define the model when training (which generated the parameters that you want to load)?

@ou525
Copy link
Author

ou525 commented Oct 14, 2019

train_imagenet.txt
i use the cmomand as follow:
python train_imagenet.py --rec-train train.rec --rec-train-idx train.idx --rec-val test.rec --rec-val-idx test.idx --model mobilenet1.0 --mode hybrid --lr 0.4 --lr-mode cosine --num-epochs 100 --batch-size 64 --num-gpus 1 -j 8 --use-rec --dtype float32 --warmup-epochs 5 --no-wd --label-smoothing --mixup --save-dir params_mobilenet1.0_mixup --logging-file mbilenet1.0_mixup.log

how can i do it ?

@hetong007
Copy link
Member

what is the exact command that generates this error message:

self.name, str(self.shape), str(data.shape))
AssertionError: Failed loading Parameter 'mobilenet0_dense0_weight' from saved params: shape incompatible expected (5, 0) vs saved (1000, 1024)

@ou525
Copy link
Author

ou525 commented Oct 14, 2019

this is run export.py
import gluoncv as gcv
from gluoncv.utils import export_block

net = gcv.model_zoo.get_model('mobilenet1.0', pretrained=True,classes=5)
net.load_parameters('./0.0877-imagenet-mobilenet1.0-88-best.params')
export_block('mobilenet1.0', net, preprocess=True, layout='HWC')
print('Done.')

@hetong007
Copy link
Member

be careful, remember to remove pretrained=True

@ou525
Copy link
Author

ou525 commented Oct 14, 2019

thank you very much, its ok.

@ou525
Copy link
Author

ou525 commented Oct 14, 2019

@hetong007 Sorry to bother again, my training and export are normal, but in the c program execution has been a segmentation error, other models call normal.

error:
(gdb) bt
#0 0x00007fffddc69be8 in MXPredSetInput () from /home/ou/workplace/sv_video/third-libs/mxnet/lib/libmxnet.so
#1 0x000000000042f80c in Classification::predict (this=this@entry=0x7fffffffdb30, pred_hnd=0x7fffd52dee78 <operator new(unsigned long)+24>,
image_data=std::vector of length 150528, capacity 150528 = {...}, nd_hnd=,
synset_file="/home/ou/workplace/incubator-mxnet/example/image-classification/predict-cpp/model/resnet_ou/synset5.txt") at /home/ou/workplace/sv_video/src/classification.cpp:109
#2 0x000000000042fe2f in Classification::runabi:cxx11 (this=this@entry=0x7fffffffdb30, img=...) at /home/ou/workplace/sv_video/src/classification.cpp:464
#3 0x000000000044b9ad in SpecialVehicle::run (this=this@entry=0x7fffffffda60) at /home/ou/workplace/sv_video/src/special_vehicle.cpp:278
#4 0x000000000042ac45 in main (argc=, argv=) at /home/ou/workplace/sv_video/main.cpp:13

@hetong007
Copy link
Member

@zhreshold can we have your help here

@zhreshold
Copy link
Member

without your c++ code it's hard to tell. @ou525 would you mind share the piece of classification.cpp ?

@ou525
Copy link
Author

ou525 commented Oct 15, 2019

classification.txt
i call the function run(img).@zhreshold

@zhreshold
Copy link
Member

Can't find obvious problem so far. What if you use the pretrained model from gluoncv model zoo?

@ou525
Copy link
Author

ou525 commented Oct 15, 2019

using the pretrained model from gluoncv model zoo and the trained model by mxnet are ok, so i think the train script may have some prblem ,but i donot kown how to do?

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

No branches or pull requests

3 participants