pytorch reports an error when loading the model AttributeError: Can't get attribute 'CNN' on <module '__main__'>

1. Problem description

When loading the model in Pytorch, an error is reported:
AttributeError: Can't get attribute 'CNN' on <module '__ main __' from 'E:\…

After reading a lot of other people's sharing, they are more complicated or not suitable for my situation.

insert image description here

2. Solutions

Copy all the classes that define the model when you trained the model before to this py file.

In my case, the entire CNN network including the __init__ method and the forward method is as follows:

insert image description here

Guess you like

Origin blog.csdn.net/qq_43750528/article/details/130295800