As you said I made a separate class as vgg.py and kept it in a folder model
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import torchvision.models as models
vggnet=models.vgg16_bn(pretrained=True)
classifier=list(vggnet.classifier.children())[:-6]
features=list(vggnet.features.children())
features.extend(nn.Sequential(nn.AvgPool2d(1, stride=1, padding=0, ceil_mode    =False, count_include_pad=True)))
avgpool=list(vggnet.avgpool.children())[:-1]
vggnet.features=nn.Sequential(*list(features))
vggnet.classifier=nn.Sequential(*list(classifier))
vggnet.classifier[0]=nn.Linear(512,10)
vggnet.avgpool=nn.Sequential(*list(avgpool))
class CifarVggnet(nn.Module):
def init(self,vggnet):
super(CifarVggnet,self).init()
self.vggnet=vggnet
def forward(self,x):
return self.vggnet(x)
model=CifarVggnet(vggnet)
-----------------------------------------------------------------------------------------------------------------------------------------
From a separate file as Checking.py I did— from model import *
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
from model import *
import numpy as np
from torch.utils.data.dataset import Dataset
ckpt_path=’/home/students/soumyajit_po/hsd_cnn_code/SOUMYA/checkpoint/vggCif    ar10TEST.pth.tar’
checkpoint=torch.load(ckpt_path,map_location=lambda storage,loc:storage)
---------------------------------------------------------------------------------------------------------------------------------------
The error I get is-
File “Checking.py”, line 15, in 
checkpoint=torch.load(ckpt_path,map_location=lambda storage,loc:storage)
File “/home/anaconda2/envs/pytorch_v36/lib/python3.6/site-packages/torch/serialization.py”, line 387, in load
return _load(f, map_location, pickle_module, **pickle_load_args)
File “/home/anaconda2/envs/pytorch_v36/lib/python3.6/site-packages/torch/serialization.py”, line 574, in _load
result = unpickler.load()
AttributeError: Can’t get attribute ‘CifarVggnet’ on <module ‘main’ from ‘Checking.py’>
I do not understand this error!!!
CifarVggnet the model I saved , should be accessible now as I imported the model .