conflict with compressai
Freed-Wu opened this issue · comments
wzy commented
Describe the bug
A clear and concise description of what the bug is.
In [1]: from torchinfo import summary
In [2]: from compressai.zoo import image_models
In [3]: model = image_models['bmshj2018-factorized'](quality=4, pretrained=True)
In [4]: summary(model, (1, 3, 256, 256))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.10/site-packages/torchinfo/torchinfo.py", line 217, in summary
summary_list = forward_pass(
File "/usr/lib/python3.10/site-packages/torchinfo/torchinfo.py", line 296, in forward_pass
raise RuntimeError(
RuntimeError: Failed to run torchinfo. See above stack traces for more details. Executed layers up to: [Sequential: 1, Conv2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, Conv2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, Conv2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, Conv2d: 2, EntropyBottleneck: 1, LowerBound: 2, Sequential: 1, ConvTranspose2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, ConvTranspose2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, ConvTranspose2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, ConvTranspose2d: 2]
Failed to run torchinfo. See above stack traces for more details. Executed layers up to: [Sequential: 1, Conv2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, Conv2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, Conv2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, Conv2d: 2, EntropyBottleneck: 1, LowerBound: 2, Sequential: 1, ConvTranspose2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, ConvTranspose2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, ConvTranspose2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, ConvTranspose2d: 2]
Expected behavior
No error
Sebastian Müller commented
I've looked into it, and it seems to be caused by the same problem that caused issue#141.
PR#212 should solve the issue.
The full Traceback from replicating the code in this issue:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
[/usr/local/lib/python3.8/dist-packages/torchinfo/torchinfo.py](https://localhost:8080/#) in forward_pass(model, x, batch_dim, cache_forward_pass, device, mode, **kwargs)
286 if isinstance(x, (list, tuple)):
--> 287 _ = model.to(device)(*x, **kwargs)
288 elif isinstance(x, dict):
5 frames
[/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in _call_impl(self, *input, **kwargs)
1214 for hook in (*_global_forward_hooks.values(), *self._forward_hooks.values()):
-> 1215 hook_result = hook(self, input, result)
1216 if hook_result is not None:
[/usr/local/lib/python3.8/dist-packages/torchinfo/torchinfo.py](https://localhost:8080/#) in hook(module, inputs, outputs)
550 info.input_size, _ = info.calculate_size(inputs, batch_dim)
--> 551 info.output_size, elem_bytes = info.calculate_size(outputs, batch_dim)
552 info.output_bytes = elem_bytes * prod(info.output_size)
[/usr/local/lib/python3.8/dist-packages/torchinfo/layer_info.py](https://localhost:8080/#) in calculate_size(inputs, batch_dim)
131 for _, output in inputs.items():
--> 132 size = list(output.size())
133 if batch_dim is not None:
AttributeError: 'dict' object has no attribute 'size'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
[<ipython-input-38-a9ae3b54797c>](https://localhost:8080/#) in <module>
----> 1 summary(model, (1, 3, 256, 256))
[/usr/local/lib/python3.8/dist-packages/torchinfo/torchinfo.py](https://localhost:8080/#) in summary(model, input_size, input_data, batch_dim, cache_forward_pass, col_names, col_width, depth, device, dtypes, mode, row_settings, verbose, **kwargs)
215 input_data, input_size, batch_dim, device, dtypes
216 )
--> 217 summary_list = forward_pass(
218 model, x, batch_dim, cache_forward_pass, device, model_mode, **kwargs
219 )
[/usr/local/lib/python3.8/dist-packages/torchinfo/torchinfo.py](https://localhost:8080/#) in forward_pass(model, x, batch_dim, cache_forward_pass, device, mode, **kwargs)
294 except Exception as e:
295 executed_layers = [layer for layer in summary_list if layer.executed]
--> 296 raise RuntimeError(
297 "Failed to run torchinfo. See above stack traces for more details. "
298 f"Executed layers up to: {executed_layers}"
RuntimeError: Failed to run torchinfo. See above stack traces for more details. Executed layers up to: [Sequential: 1, Conv2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, Conv2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, Conv2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, Conv2d: 2, EntropyBottleneck: 1, LowerBound: 2, Sequential: 1, ConvTranspose2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, ConvTranspose2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, ConvTranspose2d: 2, GDN: 2, NonNegativeParametrizer: 3, LowerBound: 4, NonNegativeParametrizer: 3, LowerBound: 4, ConvTranspose2d: 2]