help="the model file to be evaluated. Usually it is of the form model_X.pth" ) parser.add_argument('--outfile', type=str, default='experiment/kaggle.csv', metavar='D', help="name of the output csv file") args = parser.parse_args() use_cuda = torch.cuda.is_available() state_dict = torch.load(args.model) model.load_state_dict(state_dict) model.eval() if use_cuda: print('Using GPU') model.cuda() else: print('Using CPU') from data import data_transform_val test_dir = args.data + '/test_images/mistery_category' def pil_loader(path): # open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835) with open(path, 'rb') as f: with Image.open(f) as img: return img.convert('RGB')
default=0.001, help='initial learning rate') parser.add_argument('-s', type=bool, default=True, help='whether shuffle the dataset') parser.add_argument('-a', type=bool, default=False, help='test the filter, reconstructed') parser.add_argument('-b', type=bool, default=False, help='test the acc') parser.add_argument('-c', type=bool, default=True, help='train') args = parser.parse_args() net = Resnet(BasicBlock) net = net.cuda() #参数和模型应该都放在cuda上 cifar10_training_loader = get_training_dataloader( batch_size=args.batchsize, shuffle=args.s) cifar10_test_loader = get_test_dataloader(batch_size=args.batchsize, shuffle=args.s) cifar10_image_loader = get_test_dataloader(batch_size=1, shuffle=args.s) loss_function = nn.CrossEntropyLoss() optimizer = optim.Adam(net.parameters(), lr=args.lr) #TIME_NOW = datetime.now().isoformat() #这个文件命名有点问题,Windows下文件夹名称不允许有: TIME_NOW = '20191025' checkpoint_path = os.path.join('checkpoint', TIME_NOW)