Thank you for your reply. To explain a little more my code, I use a small drone (Tello) which captures images of the corridor and transmits them to my computer by WIFI. From there, I process the recovered images with the following method that seems to be very slow :
def test_simple(source, target, encoder_dict, intrinsics_json_path, pose_enc, pose_dec):
"""Function to predict for a single image or folder of images
"""
# Load input data
input_image, original_size = load_and_preprocess_image(target,
resize_width=encoder_dict['width'],
resize_height=encoder_dict['height'])
source_image, _ = load_and_preprocess_image(source,
resize_width=encoder_dict['width'],
resize_height=encoder_dict['height'])
K, invK = load_and_preprocess_intrinsics(intrinsics_json_path,
resize_width=encoder_dict['width'],
resize_height=encoder_dict['height'])
with torch.no_grad():
# Estimate poses
pose_inputs = [source_image, input_image]
pose_inputs = [pose_enc(torch.cat(pose_inputs, 1))]
axisangle, translation = pose_dec(pose_inputs)
pose = transformation_from_parameters(axisangle[:, 0], translation[:, 0], invert=True)
# Estimate depth
output, lowest_cost, _ = encoder(current_image=input_image,
lookup_images=source_image.unsqueeze(1),
poses=pose.unsqueeze(1),
K=K,
invK=invK,
min_depth_bin=encoder_dict['min_depth_bin'],
max_depth_bin=encoder_dict['max_depth_bin'])
output = depth_decoder(output)
sigmoid_output = output[("disp", 0)]
sigmoid_output_resized = torch.nn.functional.interpolate(
sigmoid_output, original_size, mode="bilinear", align_corners=False)
sigmoid_output_resized = sigmoid_output_resized.cpu().numpy()[:, 0]
toplot=sigmoid_output_resized
toplot = toplot.squeeze()
normalizer = mpl.colors.Normalize(vmin=toplot.min(), vmax=np.percentile(toplot, 95))
mapper = cm.ScalarMappable(norm=normalizer, cmap='magma')
colormapped_im = (mapper.to_rgba(toplot)[:, :, :3] * 255).astype(np.uint8)
#im = pil.fromarray(colormapped_im)
return colormapped_im
Tell me if it’s not clear, or if you want something more runnable for you.