Skip to content

Commit c79252c

Browse files
committed
Simplify imports further.
1 parent d6d91db commit c79252c

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

notebooks/DemoSegmenter.ipynb

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"source": [
4646
"## Imports and utility functions\n",
4747
"\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."
4949
]
5050
},
5151
{
@@ -55,22 +55,12 @@
5555
"outputs": [],
5656
"source": [
5757
"# 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",
6459
"# Our libs\n",
65-
"from mit_semseg.dataset import TestDataset\n",
6660
"from mit_semseg.models import ModelBuilder, SegmentationModule\n",
6761
"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",
7262
"\n",
73-
"colors = loadmat('data/color150.mat')['colors']\n",
63+
"colors = scipy.io.loadmat('data/color150.mat')['colors']\n",
7464
"names = {}\n",
7565
"with open('data/object150_info.csv') as f:\n",
7666
" reader = csv.reader(f)\n",
@@ -90,7 +80,7 @@
9080
"\n",
9181
" # aggregate images and save\n",
9282
" im_vis = numpy.concatenate((img, pred_color), axis=1)\n",
93-
" display(Image.fromarray(im_vis))"
83+
" display(PIL.Image.fromarray(im_vis))"
9484
]
9585
},
9686
{
@@ -99,7 +89,7 @@
9989
"source": [
10090
"## Loading the segmentation model\n",
10191
"\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",
10393
"\n",
10494
"After loading, we put it on the GPU. And since we are doing inference, not training, we put the model in eval mode."
10595
]
@@ -144,13 +134,13 @@
144134
"outputs": [],
145135
"source": [
146136
"# 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",
150140
" mean=[0.485, 0.456, 0.406], # These are RGB mean+std values\n",
151141
" std=[0.229, 0.224, 0.225]) # across a large photo dataset.\n",
152142
"])\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",
154144
"img_original = numpy.array(pil_image)\n",
155145
"img_data = pil_to_tensor(pil_image)\n",
156146
"singleton_batch = {'img_data': img_data[None].cuda()}\n",

0 commit comments

Comments
 (0)