-
Notifications
You must be signed in to change notification settings - Fork 965
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
[Group convolution in Keras] ResNeXt mxnet -> IR -> keras #58
Comments
Hi @kamikawa, fixed the issue you met. But there is no offical "group conv" support in keras. Any help to fill this group_conv part like this pull request are welcome. |
Thank you for an answer, I understand the situation. |
We can split the input into groups, apply the kernel for each one, and concat them after all, to work around it. |
Hi @kamikawa . The keras group convolution is implemented by @skybigzhou and tested mxnet resnext->keras conversion. Please try the newest code. Thanks both. |
Hi @kitstar , thank you for handling this issue, @skybigzhou , thank you for the fixed code. $ python -m mmdnn.conversion._script.IRToCode -f keras --IRModelPath resnext-101-64x4d.pb --dstModelPath keras_resnext-101-64x4d.py $ python -m mmdnn.conversion.examples.keras.imagenet_test -n keras_resnext-101-64x4d.py -w resnext-101-64x4d.npy --dump keras_resnext-101-64x4d.h5 |
It is not hanged up.... It took 30 minutes in my machine to finish the conversion (keras model.save() function). Maybe it needs to copy weights for each conv group since it is a workaround solution. You can put it background and wait for ... 1hour? |
Oh, sorry. I think I waited about 10 minutes. I will try again next week, and let you know. |
Hi @kitstar , I tried the resnext-101-64x64d IR weight conversion (took about 70 min.) , but failed to save to hdf5 by the limitation of hdf5 object header size. I could convert resnext-50 cases. Traceback (most recent call last): |
Another problem. Traceback (most recent call last): |
Hi @kamikawa For resnext-50, we tested with below steps:
$ python3 -m mmdnn.conversion.examples.mxnet.extract_model -n imagenet1k-resnext-50 -i mmdnn/conversion/examples/data/seagull.jpg
Downloading file [./resnext-50-symbol.json] from [http://data.mxnet.io/models/imagenet/resnext/50-layers/resnext-50-symbol.json]
100% [..............................................................................] 79195 / 79195Downloading file [./resnext-50-0000.params] from [http://data.mxnet.io/models/imagenet/resnext/50-layers/resnext-50-0000.params]
100% [......................................................................] 100404458 / 100404458Model imagenet1k-resnext-50 saved.
[11:13:01] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
[11:13:01] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
[(396, 0.7104751), (398, 0.122665755), (438, 0.06391319), (440, 0.029796895), (417, 0.019492012)]
$ python3 -m mmdnn.conversion._script.convertToIR -f mxnet -n examples/mxnet/models/resnext-50-symbol.json -w examples/mxnet/models/resnext-50-0000.params -d mxnet_resnext50 --inputShape 3 224 224
IR network structure is saved as [mxnet_resnext50.json].
IR network structure is saved as [mxnet_resnext50.pb].
IR weights are saved as [mxnet_resnext50.npy].
$ python3 -m mmdnn.conversion._script.IRToCode -f keras --IRModelPath mxnet_resnext50.pb --dstModelPath converted_resnext50.py --IRWeightPath mxnet_resnext50.npy
Parse file [mxnet_resnext50.pb] with binary format successfully.
Target network code snippet is saved as [converted_resnext50.py].
$ python3 -m mmdnn.conversion.examples.keras.imagenet_test -p imagenet1k-resnext-50 -s mxnet -n converted_resnext50 -w mxnet_resnext50.npy -i mmdnn/conversion/examples/data/seagull.jpg
[(396, 0.71047646), (398, 0.12266552), (438, 0.063913494), (440, 0.02979695), (417, 0.01949201)]
Test model [imagenet1k-resnext-50] from [mxnet] passed.
$ python3 -m mmdnn.conversion.examples.keras.imagenet_test -n converted_resnext50 -w mxnet_resnext50.npy --dump mxnet_resnext50.h5
Keras model file is saved as [mxnet_resnext50.h5], generated by [converted_resnext50.py] and [mxnet_resnext50.npy] Converted model inference result matches the original inference result. Test passed. For resnext-101, we tested only without last step and result is ok like resnext-50. Seems we can wait for Keras update to fix this problem. Thanks. You can download the resnext-50 related files(Including final h5 file and IR files) from here. |
Hi @kitstar , thank you for the detailed procedure. model = KitModel(weight_file=None) # error when resnext , OK when resnet It seems that the converted resnext Kitmodel function does not support when argument is set "None" Regards. |
Glad it help! Thank you for using it and issue submission! Any other idea is welcome! |
The limitation of Keras hdf5 object header size seems to be solved |
Hi @kitstar I followed ur step, but got an error in the final step saving as Keras model, the error is as following:
Do you know why this happened? Any suggestions? |
Hi
Thank you for a great covert tool.
I am trying to convert from mxnet resnext to keras.
symbol file: http://data.mxnet.io/models/imagenet/resnext/101-layers/resnext-101-64x4d-symbol.json
param file: http://data.mxnet.io/models/imagenet/resnext/101-layers/resnext-101-64x4d-0000.params
I could convert from mxnet to IR with no error,
but failed to convert from IR to keras with an error below.
Would you support this model?
Regards,
Parse file [resnext-101-64x4d.pb] with binary format successfully.
Traceback (most recent call last):
File "C:\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "C:\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Anaconda3\lib\site-packages\mmdnn\conversion_script\IRToCode.py", line 120, in
_main()
File "C:\Anaconda3\lib\site-packages\mmdnn\conversion_script\IRToCode.py", line 115, in _main
ret = _convert(args)
File "C:\Anaconda3\lib\site-packages\mmdnn\conversion_script\IRToCode.py", line 56, in _convert
emitter.run(args.dstModelPath, args.dstWeightPath, args.phase)
File "C:\Anaconda3\lib\site-packages\mmdnn\conversion\common\DataStructure\emitter.py", line 21, in run
self.save_code(dstNetworkPath, phase)
File "C:\Anaconda3\lib\site-packages\mmdnn\conversion\common\DataStructure\emitter.py", line 53, in save_code
code = self.gen_code(phase)
File "C:\Anaconda3\lib\site-packages\mmdnn\conversion\keras\keras2_emitter.py", line 95, in gen_code
func(current_node)
File "C:\Anaconda3\lib\site-packages\mmdnn\conversion\keras\keras2_emitter.py", line 194, in emit_Conv
return self._emit_convolution(IR_node, 'layers.Conv{}D'.format(dim))
File "C:\Anaconda3\lib\site-packages\mmdnn\conversion\keras\keras2_emitter.py", line 179, in _emit_convolution
input_node, padding = self._defuse_padding(IR_node)
File "C:\Anaconda3\lib\site-packages\mmdnn\conversion\keras\keras2_emitter.py", line 160, in _defuse_padding
padding = self._convert_padding(padding)
File "C:\Anaconda3\lib\site-packages\mmdnn\conversion\keras\keras2_emitter.py", line 139, in _convert_padding
padding = convert_onnx_pad_to_tf(padding)[1:-1]
File "C:\Anaconda3\lib\site-packages\mmdnn\conversion\common\utils.py", line 62, in convert_onnx_pad_to_tf
return np.transpose(np.array(pads).reshape([2, -1])).reshape(-1, 2).tolist()
ValueError: cannot reshape array of size 1 into shape (2,newaxis)
The text was updated successfully, but these errors were encountered: