From torchsummary import summary

Hi, I just used summary to output the information about my model, but it did not work. Then, I tested it with an official example, and it did not work too. For example,

from torchsummary import summary
model=torchvision.models.vgg16()
model=model.cuda()
summary(model,(3,224,224))

The error is “can’t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first”

In a word, the function “summary” seems does not work on my machine. I do not know why it happened. Please help me. Thanks!

You could try to keep the model on the CPU, as the error points to a device mismatch and I guess summary creates a CPUTensor using the passed input shapes.

I want to see how much GPU memory is required by the model. If I keep the model on the CPU, is the memory requirement same as that on GPU? I am a little confused.

More importantly, if I just keep the model on the CPU, it also gives the same error information “can’t convert CUDA tensor to numpy…” I do not know why it happens. I understand the meaning of the error information, but I do not know how to solve it. It is very strange.

This sounds like an issue in torchsummary. Note that there seems to be a new library, which can be foudn here, as the old one was apparently abandoned.

That works! Just uninstall the original ‘pytorchsummary’ and re-install ‘pytorch-summary’. Thanks very much!