From 1e8072ce3dda94be2f7961fc5f243dc7a3453910 Mon Sep 17 00:00:00 2001 From: Martin Rauscher Date: Sat, 23 Jun 2018 19:24:17 +0200 Subject: [PATCH 1/2] Created using Colaboratory --- demo.ipynb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 demo.ipynb diff --git a/demo.ipynb b/demo.ipynb new file mode 100644 index 0000000..479460d --- /dev/null +++ b/demo.ipynb @@ -0,0 +1,41 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Untitled0.ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/Hades32/MegaDepth/blob/master/demo.ipynb)" + ] + }, + { + "metadata": { + "id": "ViJt7oifpX3d", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file From d4c8cb21398bc87639953f570d90f66d9ff564c9 Mon Sep 17 00:00:00 2001 From: Martin Rauscher Date: Sun, 24 Jun 2018 00:13:48 +0200 Subject: [PATCH 2/2] set PyTorch in non-training mode. Faster, less RAM usage --- demo.py | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/demo.py b/demo.py index 2447470..00dd182 100644 --- a/demo.py +++ b/demo.py @@ -22,29 +22,30 @@ def test_simple(model): total_loss =0 toal_count = 0 print("============================= TEST ============================") - model.switch_to_eval() - - img = np.float32(io.imread(img_path))/255.0 - img = resize(img, (input_height, input_width), order = 1) - input_img = torch.from_numpy( np.transpose(img, (2,0,1)) ).contiguous().float() - input_img = input_img.unsqueeze(0) - - input_images = Variable(input_img.cuda() ) - pred_log_depth = model.netG.forward(input_images) - pred_log_depth = torch.squeeze(pred_log_depth) - - pred_depth = torch.exp(pred_log_depth) - - # visualize prediction using inverse depth, so that we don't need sky segmentation (if you want to use RGB map for visualization, \ - # you have to run semantic segmentation to mask the sky first since the depth of sky is random from CNN) - pred_inv_depth = 1/pred_depth - pred_inv_depth = pred_inv_depth.data.cpu().numpy() - # you might also use percentile for better visualization - pred_inv_depth = pred_inv_depth/np.amax(pred_inv_depth) - - io.imsave('demo.png', pred_inv_depth) - # print(pred_inv_depth.shape) - sys.exit() + with torch.no_grad(): + model.switch_to_eval() + + img = np.float32(io.imread(img_path))/255.0 + img = resize(img, (input_height, input_width), order = 1) + input_img = torch.from_numpy( np.transpose(img, (2,0,1)) ).contiguous().float() + input_img = input_img.unsqueeze(0) + + input_images = Variable(input_img.cuda() ) + pred_log_depth = model.netG.forward(input_images) + pred_log_depth = torch.squeeze(pred_log_depth) + + pred_depth = torch.exp(pred_log_depth) + + # visualize prediction using inverse depth, so that we don't need sky segmentation (if you want to use RGB map for visualization, \ + # you have to run semantic segmentation to mask the sky first since the depth of sky is random from CNN) + pred_inv_depth = 1/pred_depth + pred_inv_depth = pred_inv_depth.data.cpu().numpy() + # you might also use percentile for better visualization + pred_inv_depth = pred_inv_depth/np.amax(pred_inv_depth) + + io.imsave('demo.png', pred_inv_depth) + # print(pred_inv_depth.shape) + sys.exit()