Skip to content

Commit dca9002

Browse files
committed
replace scipy.misc.imresize (suggested by @grochefort)
1 parent 27c4ec0 commit dca9002

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

scripts/eval_cityscapes/evaluate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def main():
4343
label = CS.load_label(args.split, city, idx)
4444
im_file = args.result_dir + '/' + idx + '_leftImg8bit.png'
4545
im = np.array(Image.open(im_file))
46-
# im = scipy.misc.imresize(im, (256, 256))
4746
im = scipy.misc.imresize(im, (label.shape[1], label.shape[2]))
4847
out = segrun(net, CS.preprocess(im))
4948
hist_perframe += fast_hist(label.flatten(), out.flatten(), n_cl)

util/util.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,21 @@ def diagnose_network(net, name='network'):
4646
print(mean)
4747

4848

49-
def save_image(image_numpy, image_path):
49+
def save_image(image_numpy, image_path, aspect_ratio=1.0):
5050
"""Save a numpy image to the disk
5151
5252
Parameters:
5353
image_numpy (numpy array) -- input numpy array
5454
image_path (str) -- the path of the image
5555
"""
56+
5657
image_pil = Image.fromarray(image_numpy)
58+
h, w, _ = image_numpy.shape
59+
60+
if aspect_ratio > 1.0:
61+
image_pil = image_pil.resize((h, int(w * aspect_ratio)), Image.BICUBIC)
62+
if aspect_ratio < 1.0:
63+
image_pil = image_pil.resize((int(h / aspect_ratio), w), Image.BICUBIC)
5764
image_pil.save(image_path)
5865

5966

util/visualizer.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import time
66
from . import util, html
77
from subprocess import Popen, PIPE
8-
from scipy.misc import imresize
8+
99

1010
if sys.version_info[0] == 2:
1111
VisdomExceptionBase = Exception
@@ -36,13 +36,7 @@ def save_images(webpage, visuals, image_path, aspect_ratio=1.0, width=256):
3636
im = util.tensor2im(im_data)
3737
image_name = '%s_%s.png' % (name, label)
3838
save_path = os.path.join(image_dir, image_name)
39-
h, w, _ = im.shape
40-
if aspect_ratio > 1.0:
41-
im = imresize(im, (h, int(w * aspect_ratio)), interp='bicubic')
42-
if aspect_ratio < 1.0:
43-
im = imresize(im, (int(h / aspect_ratio), w), interp='bicubic')
44-
util.save_image(im, save_path)
45-
39+
util.save_image(im, save_path, aspect_ratio=aspect_ratio)
4640
ims.append(image_name)
4741
txts.append(label)
4842
links.append(image_name)

0 commit comments

Comments
 (0)