|
45 | 45 | "source": [ |
46 | 46 | "## Imports and utility functions\n", |
47 | 47 | "\n", |
48 | | - "We need pytorch, numpy, and the code for the segmentation model. And some othe utilities for visualizing the data." |
| 48 | + "We need pytorch, numpy, and the code for the segmentation model. And some utilities for visualizing the data." |
49 | 49 | ] |
50 | 50 | }, |
51 | 51 | { |
|
55 | 55 | "outputs": [], |
56 | 56 | "source": [ |
57 | 57 | "# System libs\n", |
58 | | - "import os\n", |
59 | | - "# Numerical libs\n", |
60 | | - "import torch, numpy\n", |
61 | | - "from scipy.io import loadmat\n", |
62 | | - "from torchvision import transforms\n", |
63 | | - "import csv\n", |
| 58 | + "import os, csv, torch, numpy, scipy.io, PIL.Image, torchvision.transforms\n", |
64 | 59 | "# Our libs\n", |
65 | | - "from mit_semseg.dataset import TestDataset\n", |
66 | 60 | "from mit_semseg.models import ModelBuilder, SegmentationModule\n", |
67 | 61 | "from mit_semseg.utils import colorEncode\n", |
68 | | - "from mit_semseg.lib.nn import user_scattered_collate, async_copy_to\n", |
69 | | - "from mit_semseg.lib.utils import as_numpy\n", |
70 | | - "from PIL import Image\n", |
71 | | - "from mit_semseg.config import cfg\n", |
72 | 62 | "\n", |
73 | | - "colors = loadmat('data/color150.mat')['colors']\n", |
| 63 | + "colors = scipy.io.loadmat('data/color150.mat')['colors']\n", |
74 | 64 | "names = {}\n", |
75 | 65 | "with open('data/object150_info.csv') as f:\n", |
76 | 66 | " reader = csv.reader(f)\n", |
|
90 | 80 | "\n", |
91 | 81 | " # aggregate images and save\n", |
92 | 82 | " im_vis = numpy.concatenate((img, pred_color), axis=1)\n", |
93 | | - " display(Image.fromarray(im_vis))" |
| 83 | + " display(PIL.Image.fromarray(im_vis))" |
94 | 84 | ] |
95 | 85 | }, |
96 | 86 | { |
|
99 | 89 | "source": [ |
100 | 90 | "## Loading the segmentation model\n", |
101 | 91 | "\n", |
102 | | - "Here we load a pretrained segmentation model. Like any pytorch model, we can call it like a function, or example the parameters in all the layers.\n", |
| 92 | + "Here we load a pretrained segmentation model. Like any pytorch model, we can call it like a function, or examine the parameters in all the layers.\n", |
103 | 93 | "\n", |
104 | 94 | "After loading, we put it on the GPU. And since we are doing inference, not training, we put the model in eval mode." |
105 | 95 | ] |
|
144 | 134 | "outputs": [], |
145 | 135 | "source": [ |
146 | 136 | "# Load and normalize one image as a singleton tensor batch\n", |
147 | | - "pil_to_tensor = transforms.Compose([\n", |
148 | | - " transforms.ToTensor(),\n", |
149 | | - " transforms.Normalize(\n", |
| 137 | + "pil_to_tensor = torchvision.transforms.Compose([\n", |
| 138 | + " torchvision.transforms.ToTensor(),\n", |
| 139 | + " torchvision.transforms.Normalize(\n", |
150 | 140 | " mean=[0.485, 0.456, 0.406], # These are RGB mean+std values\n", |
151 | 141 | " std=[0.229, 0.224, 0.225]) # across a large photo dataset.\n", |
152 | 142 | "])\n", |
153 | | - "pil_image = Image.open('ADE_val_00001519.jpg').convert('RGB')\n", |
| 143 | + "pil_image = PIL.Image.open('ADE_val_00001519.jpg').convert('RGB')\n", |
154 | 144 | "img_original = numpy.array(pil_image)\n", |
155 | 145 | "img_data = pil_to_tensor(pil_image)\n", |
156 | 146 | "singleton_batch = {'img_data': img_data[None].cuda()}\n", |
|
0 commit comments