akamaster / pytorch_resnet_cifar10

Proper implementation of ResNet-s for CIFAR10/100 in pytorch that matches description of the original paper.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

test accuracy

U-C-J opened this issue · comments

commented

Hi, I use your pretrained model (resnet56) to initialize the resnet56 model and predict the test set, and got this result. I think there is something that I did not use correctly but now I could not figure this out. I attached the code I used. Can you please check it? Thank you.

Test: [0/79] Time 5.170 (5.170) Loss 3.2016 (3.2016) Prec@1 11.719 (11.719)
Test: [50/79] Time 0.040 (0.145) Loss 3.1556 (3.2240) Prec@1 7.031 (10.003)

  • Prec@1 10.000

My testing code is as below.

parser.add_argument('--testmodel', default='./pretrained_models/resnet56-4bfd9763.th', type=str, metavar='TESTM',
help='path to test model')
def test():

global args, best_prec1
args = parser.parse_args()
# Check the save_dir exists or not
if not os.path.exists(args.save_dir):
    os.makedirs(args.save_dir)
model = resnet.__dict__[args.arch]()
model.load_state_dict(torch.load(args.testmodel), strict=False)
model = torch.nn.DataParallel(model)
#model = torch.nn.DataParallel(model, device_ids=GPUS).cuda()
model.cuda()

cudnn.benchmark = True

normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])

train_loader = torch.utils.data.DataLoader(
    datasets.CIFAR10(root='./data', train=True, transform=transforms.Compose([
        transforms.RandomHorizontalFlip(),
        transforms.RandomCrop(32, 4),
        transforms.ToTensor(),
        normalize,
    ]), download=True),
    batch_size=args.batch_size, shuffle=True,
    num_workers=args.workers, pin_memory=True)

val_loader = torch.utils.data.DataLoader(
    datasets.CIFAR10(root='./data', train=False, transform=transforms.Compose([
        transforms.ToTensor(),
        normalize,
    ])),
    batch_size=128, shuffle=False,
    num_workers=args.workers, pin_memory=True)

# define loss function (criterion) and optimizer
criterion = nn.CrossEntropyLoss().cuda()


args.evaluate = True
if args.evaluate:
    validate(val_loader, model, criterion)
    return
commented

Problem solved. Put model = torch.nn.DataParallel(model) before the load state.