model_dir = os.path.dirname(model_path) sys.path.insert(0, model_dir) from lib import SegDataset, Model, AlignCollate from settings import ModelSettings ms = ModelSettings() if torch.cuda.is_available() and not opt.usegpu: print('WARNING: You have a CUDA device, so you should probably run with --cuda') # Define Data Loaders pin_memory = False if opt.usegpu: pin_memory = True test_dataset = SegDataset(opt.lmdb) test_align_collate = AlignCollate('test', ms.LABELS, ms.MEAN, ms.STD, ms.IMAGE_SIZE_HEIGHT, ms.IMAGE_SIZE_WIDTH, ms.ANNOTATION_SIZE_HEIGHT, ms.ANNOTATION_SIZE_WIDTH, ms.CROP_SCALE, ms.CROP_AR, random_cropping=ms.RANDOM_CROPPING, horizontal_flipping=ms.HORIZONTAL_FLIPPING,random_jitter=ms.RANDOM_JITTER) assert test_dataset test_loader = torch.utils.data.DataLoader(test_dataset, batch_size=opt.batchsize, shuffle=False, num_workers=opt.nworkers, pin_memory=pin_memory, collate_fn=test_align_collate) # Define Model model = Model(ms.LABELS, load_model_path=model_path, usegpu=opt.usegpu) # Test Model test_accuracy, test_dice_coeff = model.test(ms.CLASS_WEIGHTS, test_loader)
model_dir = os.path.dirname(args.model) # Load Seeds random.seed(s.SEED) np.random.seed(s.SEED) torch.manual_seed(s.SEED) # Load Data data = Data(data_file=args.data, input_horizon=s.INPUT_HORIZON, n_stations=args.n_stations, train_ratio=s.TRAIN_RATIO, val_ratio=s.VAL_RATIO, debug=False) # Load Model model = Model(args.n_stations, s.MOVING_HORIZON, s.ACTIVATION, s.CRITERION, load_model_path=args.model, usegpu=args.usegpu) # Train First RNN _, _, [X_test, y_test] = data.load_data_lstm_1() print '\n\n' + '#' * 10 + ' TESTING ' + '#' * 10 prediction_test = model.test([X_test, y_test]) draw_graph_all_stations(model_dir, data, args.n_stations, y_test, prediction_test)
pin_memory = False if opt.usegpu: pin_memory = True test_dataset = SegDataset(opt.lmdb) test_align_collate = AlignCollate('test', ms.LABELS, ms.MEAN, ms.STD, ms.IMAGE_SIZE_HEIGHT, ms.IMAGE_SIZE_WIDTH, ms.ANNOTATION_SIZE_HEIGHT, ms.ANNOTATION_SIZE_WIDTH, ms.CROP_SCALE, ms.CROP_AR, random_cropping=ms.RANDOM_CROPPING, horizontal_flipping=ms.HORIZONTAL_FLIPPING) assert test_dataset test_loader = torch.utils.data.DataLoader(test_dataset, batch_size=opt.batchsize, shuffle=False, num_workers=opt.nworkers, pin_memory=pin_memory, collate_fn=test_align_collate) # Define Model model = Model(ms.LABELS, load_model_path=model_path, usegpu=opt.usegpu) # Test Model test_accuracy, test_loss = model.test(ms.CLASS_WEIGHTS, test_loader)