clcarwin / convert_torch_to_pytorch

Convert torch t7 model to pytorch model and source.
MIT License
540 stars 161 forks source link

TypeError: '<' not supported between instances of 'NoneType' and 'str' #56

Open flukefer1243 opened 2 years ago

flukefer1243 commented 2 years ago

hi, I need to convert model VGG_FACEt.7 (This model, I download form this link: https://www.robots.ox.ac.uk/~vgg/software/vgg_face/) to Pytorch model. When I run command "python convert_torch.py -m VGGFACE.t7", I obtain the error follow as below.


Traceback (most recent call last): File "convert_torch.py", line 314, in torch_to_pytorch(args.model,args.output) File "convert_torch.py", line 259, in torch_to_pytorch model = load_lua(t7_filename,unknown_classes=True) File "C:\Users\User\anaconda3\envs\env_pytorch\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 608, in load_lua return reader.read() File "C:\Users\User\anaconda3\envs\env_pytorch\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 593, in read return self.read_object() File "C:\Users\User\anaconda3\envs\env_pytorch\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 523, in wrapper result = fn(self, *args, **kwargs) File "C:\Users\User\anaconda3\envs\env_pytorch\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 546, in read_object return reader_registry[cls_name](self, version) File "C:\Users\User\anaconda3\envs\env_pytorch\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 245, in read_nn_class _load_backend(obj) File "C:\Users\User\anaconda3\envs\env_pytorch\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 220, in _load_backend for key in dir(obj): TypeError: '<' not supported between instances of 'NoneType' and 'str'


10peta-cat commented 1 year ago

I encounted the same problem too. To solve this, you need to edit convert_torch.py two times. First, to solve TypeError: '<' not supported between instances of 'NoneType' and 'str', change line 261 like this:

model = load_lua(t7_filename,unknown_classes=True,long_size=8)

After that, you may encount RuntimeError: The expanded size of the tensor (3) must match the existing size (27) at non-singleton dimension 3. Then, change line 44 like this:

if m.weight is not None: 
        m.weight.data = m.weight.view(n.weight.size())
        n.weight.data.copy_(m.weight)

This solution is based on here: https://github.com/pytorch/pytorch/issues/9816 https://github.com/clcarwin/convert_torch_to_pytorch/issues/35

Aelisa commented 1 year ago

you are right!THANKS!!!