Hi guys,
I just found an error - name ‘vgg’ is not defined - when I ran the training codes. Listed are part codes in the training file. Any ideas are welcome. Cheers!
import os
import torch
import numpy as np
import scipy
import sys
sys.path.append(’…/’)
from Dataset.data import *
VGG is a architecture-defined python file in the Model folder
from Model.VGG import *
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import torch.autograd as autograd
from torch.utils.data import Dataset, DataLoader
#from PIL import Image
import matplotlib.pyplot as plt
from torchvision import datasets, models, transforms
class Train:
def init(self, number_classes = 2):
“”"
Init Dataset, Model and others
“”"
root_path = “/home/*****”
path_prefix = “VGG16”
self.save_prefix = path_prefix
    self.num_classes = number_classes
    #self.pretrained = None
    batch_size=1
    self.aff_dataset = ImageData(root_path=root_path, train_mode = "train")
    dataloader = DataLoader(self.aff_dataset, batch_size=batch_size, shuffle=True, num_workers=8)

    # create a Net
    vgg = VGG()
    vgg16 = models.vgg16(pretrained=True)
    pretrained_dict = vgg16.state_dict()
    model_dict = vgg.state_dict()
    pretrained_dict =  {k: v for k, v in pretrained_dict.items() if k in model_dict}
    model_dict.update(pretrained_dict)
    vgg.load_state_dict(model_dict)