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

Error converting caffe to torch model #942

Closed
sagarkalburgi opened this issue Mar 20, 2023 · 1 comment
Closed

Error converting caffe to torch model #942

sagarkalburgi opened this issue Mar 20, 2023 · 1 comment

Comments

@sagarkalburgi
Copy link

Platform (like ubuntu 16.04/win10): win10

Python version: 3.10

Source framework with version (like Tensorflow 1.4.1 with GPU): caffe

Destination framework with version (like CNTK 2.3 with GPU): pytorch

Pre-trained model path (webpath or webdisk path): https://github.com/CSAILVision/places365, vgg16 hybrid1365

Running scripts: mmconvert --srcFramework caffe --inputWeight vgg16_hybrid1365.caffemodel --inputNetwork deploy_vgg16_hybrid1365.prototxt --dstFramework pytorch -om vgg16_hybrid1365.pth

The following error:

------------------------------------------------------------
    WARNING: PyCaffe not found!
    Falling back to a pure protocol buffer implementation.
    * Conversions will be drastically slower.
    * This backend is UNTESTED!
------------------------------------------------------------

Type                 Name                                          Param               Output
----------------------------------------------------------------------------------------------
Data                 data                                             --    (10, 3, 224, 224)
Convolution          conv1_1                               (3, 3, 3, 64)   (10, 64, 224, 224)
ReLU                 relu1_1                                          --   (10, 64, 224, 224)
Convolution          conv1_2                              (3, 3, 64, 64)   (10, 64, 224, 224)
ReLU                 relu1_2                                          --   (10, 64, 224, 224)
Pooling              pool1                                            --   (10, 64, 112, 112)
Convolution          conv2_1                             (3, 3, 64, 128)  (10, 128, 112, 112)
ReLU                 relu2_1                                          --  (10, 128, 112, 112)
Convolution          conv2_2                            (3, 3, 128, 128)  (10, 128, 112, 112)
ReLU                 relu2_2                                          --  (10, 128, 112, 112)
Pooling              pool2                                            --    (10, 128, 56, 56)
Convolution          conv3_1                            (3, 3, 128, 256)    (10, 256, 56, 56)
ReLU                 relu3_1                                          --    (10, 256, 56, 56)
Convolution          conv3_2                            (3, 3, 256, 256)    (10, 256, 56, 56)
ReLU                 relu3_2                                          --    (10, 256, 56, 56)
Convolution          conv3_3                            (3, 3, 256, 256)    (10, 256, 56, 56)
ReLU                 relu3_3                                          --    (10, 256, 56, 56)
Pooling              pool3                                            --    (10, 256, 28, 28)
Convolution          conv4_1                            (3, 3, 256, 512)    (10, 512, 28, 28)
ReLU                 relu4_1                                          --    (10, 512, 28, 28)
Convolution          conv4_2                            (3, 3, 512, 512)    (10, 512, 28, 28)
ReLU                 relu4_2                                          --    (10, 512, 28, 28)
Convolution          conv4_3                            (3, 3, 512, 512)    (10, 512, 28, 28)
ReLU                 relu4_3                                          --    (10, 512, 28, 28)
Pooling              pool4                                            --    (10, 512, 14, 14)
Convolution          conv5_1                            (3, 3, 512, 512)    (10, 512, 14, 14)
ReLU                 relu5_1                                          --    (10, 512, 14, 14)
Convolution          conv5_2                            (3, 3, 512, 512)    (10, 512, 14, 14)
ReLU                 relu5_2                                          --    (10, 512, 14, 14)
Convolution          conv5_3                            (3, 3, 512, 512)    (10, 512, 14, 14)
ReLU                 relu5_3                                          --    (10, 512, 14, 14)
Pooling              pool5                                            --      (10, 512, 7, 7)
InnerProduct         fc6                                   (25088, 4096)     (10, 4096, 1, 1)
ReLU                 relu6                                            --     (10, 4096, 1, 1)
Dropout              drop6                                            --     (10, 4096, 1, 1)
InnerProduct         fc7                                    (4096, 4096)     (10, 4096, 1, 1)
ReLU                 relu7                                            --     (10, 4096, 1, 1)
Dropout              drop7                                            --     (10, 4096, 1, 1)
InnerProduct         fc8a                                   (4096, 1365)     (10, 1365, 1, 1)
Softmax              prob                                             --     (10, 1365, 1, 1)
IR network structure is saved as [09e40723c6e34cd4b0c799409703de9b.json].
IR network structure is saved as [09e40723c6e34cd4b0c799409703de9b.pb].
IR weights are saved as [09e40723c6e34cd4b0c799409703de9b.npy].
Parse file [09e40723c6e34cd4b0c799409703de9b.pb] with binary format successfully.
Target network code snippet is saved as [vgg16_hybrid1365.py].
Target weights are saved as [09e40723c6e34cd4b0c799409703de9b.npy].
Traceback (most recent call last):
  File "D:\Users\KalburgS\Anaconda3\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\Users\KalburgS\Anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\Users\KalburgS\Anaconda3\Scripts\mmconvert.exe\__main__.py", line 7, in <module>
  File "D:\Users\KalburgS\Anaconda3\lib\site-packages\mmdnn\conversion\_script\convert.py", line 112, in _main
    dump_code(args.dstFramework, network_filename + '.py', temp_filename + '.npy', args.outputModel, args.dump_tag)
  File "D:\Users\KalburgS\Anaconda3\lib\site-packages\mmdnn\conversion\_script\dump_code.py", line 32, in dump_code
    save_model(MainModel, network_filepath, weight_filepath, dump_filepath)
  File "D:\Users\KalburgS\Anaconda3\lib\site-packages\mmdnn\conversion\pytorch\saver.py", line 5, in save_model
    model = MainModel.KitModel(weight_filepath)
  File "vgg16_hybrid1365.py", line 28, in __init__
    self.conv1_1 = self.__conv(2, name='conv1_1', in_channels=3, out_channels=64, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
  File "vgg16_hybrid1365.py", line 126, in __conv
    layer.state_dict()['bias'].copy_(torch.from_numpy(_weights_dict[name]['bias']))
RuntimeError: output with shape [64] doesn't match the broadcast shape [1, 1, 1, 64]
@zeo233
Copy link

zeo233 commented Jan 30, 2024

I met the same error, did you solve that?

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

2 participants