print() time_elapsed = time.time() - since print('Training complete in {:.0f}m {:.0f}s'.format( time_elapsed // 60, time_elapsed % 60)) print('Best val Acc: {:4f}'.format(best_acc)) # load best model weights model.load_state_dict(best_model_wts) return model from torchsample.callbacks import ReduceLROnPlateau model_ft = resnet3.resnet182(pretrained=True) num_ftrs = model_ft.fc.in_features model_ft.fc = nn.Linear(num_ftrs, 2) model_ft.avgpool = nn.AdaptiveAvgPool2d(1) ct = 0 for child in model_ft.children(): ct += 1 if ct < 0: for param in child.parameters(): param.requires_grad = False if use_gpu: model_ft = model_ft.cuda() criterion = nn.CrossEntropyLoss()
import cv2, torch import io from PIL import Image from torchvision import models, transforms from torch.autograd import Variable from torch.nn import functional as F import numpy as np import resnet3 import torch.nn.functional as F import torch.nn as nn import os net = resnet3.resnet182(pretrained=True) num_ftrs = net.fc.in_features net.fc = nn.Linear(num_ftrs, 2) net.avgpool = nn.AdaptiveAvgPool2d(1) net.eval() resume = 'GD1.pth.tar' if resume: if os.path.isfile(resume): print("=> loading checkpoint '{}'".format(resume)) checkpoint = torch.load(resume) start_epoch = checkpoint['epoch'] best_prec1 = checkpoint['best_prec1'] net.load_state_dict(checkpoint['state_dict']) print("=> loaded checkpoint '{}' (epoch {})".format( resume, checkpoint['epoch'])) finalconv_name = 'layer4'