def submission(args): logging.info('======= user config ======') logging.info(pprint(opt)) logging.info(pprint(args)) logging.info('======= end ======') test_loader, idx_to_class = get_test_provider(opt) net = getattr(network, opt.network.name)(classes=opt.dataset.num_classes, pretrain=False) net.load_state_dict(torch.load(args.model_path)['state_dict']) net.eval() net = nn.DataParallel(net) net = net.cuda() preds = list() img_ids = list() for data, fname in test_loader: with torch.no_grad(): scores = net(data) pred_labels = scores.max(1)[1].cpu().numpy().tolist() preds.extend(pred_labels) img_ids.extend(fname) df = pd.DataFrame({'file': img_ids, 'species': preds}) df['species'] = df['species'].apply(lambda x: idx_to_class[x]) df.to_csv('submission1.csv', index=False)
def submission(args): test_loader, id_to_class = get_test_provider(args.bs) net = network.ResNet18(num_classes=10) net.load_state_dict(torch.load(args.model_path)['state_dict']) net = nn.DataParallel(net) net.eval() if args.use_gpu: net = net.cuda() pred_labels = list() indices = list() for data, fname in test_loader: if args.use_gpu: data = data.cuda() with torch.no_grad(): scores = net(data) labels = scores.max(1)[1].cpu().numpy() pred_labels.extend(labels) indices.extend(fname.numpy()) df = pd.DataFrame({'id': indices, 'label': pred_labels}) df['label'] = df['label'].apply(lambda x: id_to_class[x]) df.to_csv('submission.csv', index=False)