test_images = load_images(image_list)

image_list_gt = glob.glob('gt_syn_test/*.png')
test_images_gt = load_images(image_list_gt)
# model checkpoints
model = Model().cuda()
# model.load_state_dict(torch.load(r'models\01-27-2021_12-51-33-n17183-e20-bs4-lr0.0001\weights.epoch8_model.pth'))
# optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
# epoch = checkpoint['epoch']
# loss = checkpoint['loss']

optimizer = torch.optim.Adam(model.parameters(), 0.0001)
checkpoint = torch.load(
    r'models\01-27-2021_12-51-33-n17183-e20-bs4-lr0.0001\weights.epoch8_model.pth'
)
model.load_state_dict(checkpoint['model_state_dict'])
optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
epoch = checkpoint['epoch']
loss = checkpoint['loss']
model.eval()

predictions = predict(model, test_images)

show_images(test_images)
show_depth_colormap(test_images_gt)
show_depth_colormap(predictions)

i = 1
# save the prediction in numpy file
for pred in predictions:
    plt.imsave("gt_syn_test/depth_image_{0}.jpg".format(i), pred, cmap='Greys')
dataiter = iter(train_loader)
images = dataiter.next()

print("\n Time taken to load Images: %s " % (time.time() - start_time))
print("\n Test Dataset Shape: {shape}".format(shape=np.shape(depth_dataset)))

# ### Importing the Model

from Mobile_model import Model

model = Model().cuda()
model = nn.DataParallel(model)

# Import the Pre-trained Model

model.load_state_dict(torch.load(pretrained_path))
print("\n Loaded MobileNet U-Net Weights successfully\n")

model.eval()

# ### Model Variables (state_dict)

# print("\n\nModel's state_dict:\n\n")
# for param_tensor in model.state_dict():
#     print(param_tensor, "\t", model.state_dict()[param_tensor].size())

# ## Generating Depth Images

start_time = time.time()

for i, sample_batched1 in enumerate(train_loader):
Exemple #3
0
                        help='Image size of network input')
    parser.add_argument('--data_dir',
                        default='comarision_datasets\input',
                        type=str,
                        help='Data path')
    parser.add_argument(
        '--result_dir',
        default='demo_results',
        type=str,
        help='Directory for saving results, default: demo_results')
    parser.add_argument('--gpu_id',
                        default=0,
                        type=int,
                        help='GPU id, default:0')
    args = parser.parse_args()

    if not os.path.exists(args.result_dir):
        os.makedirs(args.result_dir)

    gpu_id = args.gpu_id
    torch.cuda.device(gpu_id)

    net = Model().cuda()
    net.load_state_dict(torch.load('weights_model.pth'))
    net.eval()

    print('Begin to test ...')
    with torch.no_grad():
        demo(net, args)
    print('Finished!')