print("=================FLAGS==================") for k, v in args.__dict__.items(): print('{}: {}'.format(k, v)) print("========================================") # seed args.cuda = torch.cuda.is_available() torch.manual_seed(args.seed) if args.cuda: torch.cuda.manual_seed(args.seed) # data loader and model train_loader, test_loader = dataset.get(batch_size=args.batch_size, data_root=args.data_root, num_workers=1) model = model.svhn(n_channel=args.channel) model = torch.nn.DataParallel(model, device_ids=range(args.ngpu)) if args.cuda: model.cuda() # optimizer optimizer = optim.Adam(model.parameters(), lr=args.lr, weight_decay=args.wd) decreasing_lr = list(map(int, args.decreasing_lr.split(','))) print('decreasing_lr: ' + str(decreasing_lr)) best_acc, old_file = 0, None t_begin = time.time() try: for epoch in range(args.epochs): model.train() if epoch in decreasing_lr: optimizer.param_groups[0]['lr'] *= 0.1
print("========================================") # seed args.cuda = torch.cuda.is_available() torch.manual_seed(args.seed) if args.cuda: torch.cuda.manual_seed(args.seed) # data loader and model train_loader, test_loader = dataset_digits.get(batch_size=args.batch_size, csv_path=args.csv_path, data_root=args.data_root, num_workers=0) model = model.svhn(n_channel=args.channel, pretrained=args.use_pretrained, local_model=args.local_model) model = torch.nn.DataParallel(model, device_ids=range(args.ngpu)) if args.cuda: model.cuda() # optimizer optimizer = optim.Adam(model.parameters(), lr=args.lr, weight_decay=args.wd) decreasing_lr = list(map(int, args.decreasing_lr.split(','))) print('decreasing_lr: ' + str(decreasing_lr)) best_acc, old_file = 0, None best_loss = 50000 t_begin = time.time() try: for epoch in range(args.epochs):
from torch.utils.data import DataLoader from torch.utils.data import Dataset import torch.nn.functional as F from scipy import ndimage from PIL import Image import matplotlib.pyplot as plt from sklearn.metrics import average_precision_score, classification_report from PIL import Image use_cuda = torch.cuda.is_available() model_svhn = model.svhn( 32, pretrained="Local", local_model= "C:\\Users\\fcalcagno\\Documents\\pytorch-playground_local\\svhn\\log\\latest.pth" ) class MyDataset(Dataset): def __init__(self, transform=None, target_transform=None): self.data = [(cv2.imread(file), file) for file in glob.glob( "C:\\Users\\fcalcagno\\Documents\\pytorch-playground_local\\svhn\\testingimages\\test\\*.png" )] self.transform = transform def __getitem__(self, index): img1 = self.data[index][0] img1 = cv2.resize(img1, (32, 32))