In the past, I once wrote an article describing how I printed the model architect I built using PyTorch. For specific links, please refer to the end of the article.
But it didn't take long for me to be happy, after a while, when I wanted to use this tool to draw another new model architecture to prepare a report, I got the following error message:
AttributeError: 'tuple' object has no attribute 'size'
Fortunately, after checking, I immediately found that someone had the same error as me, was also under the LSTM model layer, and was also setting batch_size=True
.
After using the recommended tools, my problem was indeed solved, and the LSTM model was successfully drawn. Looking at the Github issue discussion, it seems to be a version issue.
Just leave a record on the Blog, maybe I will need it again after I relocate the environment, but I don’t think so-but recently I discovered that humans are fickle animals, and I seem to have discovered a more beautiful kit that can be used to print PyTorch model architecture.
Human beings are really sad animals, always choosing better-looking desktop picture.
Solution
First, we can go to the GitHub project: https://github.com/Bond-H/pytorch-summary。
git clone.
git clone https://github.com/Bond-SYSU/pytorch-summary
The architecture looks like this:
What we need is the folder "torchsummary". Move it to the directory required by your project, and use the following code again to draw the model.
from torchsummary import summary summary(your_model, input_size=(channels, H, W))
This method solved my error, you can try and see.