def main(): """Create the model and start the evaluation process.""" for i in range(1, 50): model_path = './snapshots/GTA2Cityscapes/GTA5_{0:d}.pth'.format(i * 2000) save_path = './result/GTA2Cityscapes_{0:d}'.format(i * 2000) args = get_arguments() gpu0 = args.gpu if not os.path.exists(save_path): os.makedirs(save_path) model = Res_Deeplab(num_classes=args.num_classes) saved_state_dict = torch.load(model_path) model.load_state_dict(saved_state_dict) model.eval() model.cuda(gpu0) testloader = data.DataLoader(cityscapesDataSet(args.data_dir, args.data_list, crop_size=(1024, 512), mean=IMG_MEAN, scale=False, mirror=False, set=args.set), batch_size=1, shuffle=False, pin_memory=True) interp = nn.Upsample(size=(1024, 2048), mode='bilinear', align_corners=True) with torch.no_grad(): for index, batch in enumerate(testloader): if index % 100 == 0: print('%d processd' % index) image, _, _, name = batch output1, output2 = model(Variable(image).cuda(gpu0)) output = interp(output1 + output2).cpu().data[0].numpy() output = output.transpose(1, 2, 0) output = np.asarray(np.argmax(output, axis=2), dtype=np.uint8) output_col = colorize_mask(output) output = Image.fromarray(output) name = name[0].split('/')[-1] output.save('%s/%s' % (save_path, name)) output_col.save('%s/%s_color.png' % (save_path, name.split('.')[0])) print(save_path)
def main(): """Create the model and start the evaluation process.""" args = get_arguments() os.makedirs(args.save, exist_ok=True) device = torch.device("cuda" if not args.cpu else "cpu") model = Res_Deeplab(num_classes=args.num_classes) saved_state_dict = torch.load(args.restore_from) model.load_state_dict(saved_state_dict) model.eval() model.to(device) testloader = data.DataLoader(cityscapesDataSet(args.data_dir, args.data_list, crop_size=(1024, 512), mean=IMG_MEAN, scale=False, mirror=False, set=args.set), batch_size=1, shuffle=False, pin_memory=True) interp = nn.Upsample(size=(1024, 2048), mode='bilinear', align_corners=True) print('### STARTING EVALUATING ###') print('total to process: %d' % len(testloader)) with torch.no_grad(): for index, batch in enumerate(testloader): if index % 100 == 0: print('%d processed' % index) image, _, name, = batch output1, output2 = model(image.to(device)) output = interp(output1 + output2).cpu().data[0].numpy() output = output.transpose(1,2,0) output = np.asarray(np.argmax(output, axis=2), dtype=np.uint8) output_col = colorize_mask(output) output = Image.fromarray(output) name = name[0].split('/')[-1] output.save('%s/%s' % (args.save, name)) output_col.save('%s/%s_color.png' % (args.save, name.split('.')[0])) print('### EVALUATING FINISHED ###')
def main(args): """Create the model and start the evaluation process.""" save_dir = os.path.join(args.save, args.experiment) model_dir = os.path.join(args.restore_from, args.experiment) os.makedirs(save_dir, exist_ok=True) device = torch.device("cuda" if not args.cpu else "cpu") start = time.time() n_files = len([name for name in os.listdir(model_dir)]) if args.d: n_files = int(n_files / 2) if args.a: n_files = int(n_files / 3) for i in range(1, n_files + 1): model_path = os.path.join(model_dir, 'GTA5_{0:d}.pth'.format(i * args.save_step)) save_path = os.path.join(save_dir, '{0:d}'.format(i * args.save_step)) os.makedirs(save_path, exist_ok=True) print('#### Evaluating model: ' + str(i) + '/' + str(n_files) + ' ####') model = Res_Deeplab(num_classes=args.num_classes) saved_state_dict = torch.load(model_path) model.load_state_dict(saved_state_dict) model.eval() model.to(device) testloader = data.DataLoader(cityscapesDataSet(args.data_dir, args.data_list, crop_size=(1024, 512), mean=IMG_MEAN, scale=False, mirror=False, set=args.set), batch_size=1, shuffle=False, pin_memory=True) interp = nn.Upsample(size=(1024, 2048), mode='bilinear', align_corners=True) with torch.no_grad(): for index, batch in enumerate(testloader): if index % 100 == 0: print('%d processed' % index) image, _, name = batch output1, output2 = model(image.to(device)) output = interp(output1 + output2).cpu().data[0].numpy() output = output.transpose(1, 2, 0) output = np.asarray(np.argmax(output, axis=2), dtype=np.uint8) output_col = colorize_mask(output) output = Image.fromarray(output) name = name[0].split('/')[-1] output.save('%s/%s' % (save_path, name)) output_col.save('%s/%s_color.png' % (save_path, name.split('.')[0])) print(save_path) end = time.time() print('Total time: {} min, {} sec '.format(int((end - start) / 60 % 60), int((end - start) % 60)))