Skip to content

Commit 71463b2

Browse files
Fix save img error and two function
First,scipy.misc.imsave is nosupport scipy.misc,so using imageio.imwrite replacement can effectively avoid "one pic error!..." errors Second,function center_crop and transform will run an error, I fixed errors due to format and parameters. I am very happy to make my own contribution to this project, I hope you can adopt it, and good luck
1 parent 842dd27 commit 71463b2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

utils.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def merge(images, size):
8282

8383
def imsave(images, size, path):
8484
image = np.squeeze(merge(images, size))
85-
return scipy.misc.imsave(path, image)
85+
return imageio.imwrite(path,image)
8686

8787
def center_crop(x, crop_h, crop_w,
8888
resize_h=64, resize_w=64):
@@ -91,18 +91,20 @@ def center_crop(x, crop_h, crop_w,
9191
h, w = x.shape[:2]
9292
j = int(round((h - crop_h)/2.))
9393
i = int(round((w - crop_w)/2.))
94-
im = Image.fromarray(x[j:j+crop_h, i:i+crop_w])
95-
return np.array(im.resize([resize_h, resize_w]), PIL.Image.BILINEAR)
94+
im = Image.fromarray(np.uint8(x[j:j + crop_h, i:i + crop_w]))
95+
return np.array(im.resize([resize_h, resize_w], PIL.Image.BILINEAR))
9696

97-
def transform(image, input_height, input_width,
97+
def transform(image, input_height, input_width,
9898
resize_height=64, resize_width=64, crop=True):
9999
if crop:
100100
cropped_image = center_crop(
101-
image, input_height, input_width,
101+
image, input_height, input_width,
102102
resize_height, resize_width)
103-
else:
104-
im = Image.fromarray(image[j:j+crop_h, i:i+crop_w])
105-
return np.array(im.resize([resize_h, resize_w]), PIL.Image.BILINEAR)/127.5 - 1.
103+
h, w = image.shape[:2]
104+
j = int(round((h - input_height) / 2.))
105+
i = int(round((w - input_width) / 2.))
106+
im = Image.fromarray(np.uint8(image[j:j + input_height, i:i + input_width]))
107+
return np.array(im.resize([resize_height, resize_width]), np.uint8(Image.BILINEAR)) / 127.5 - 1.
106108

107109
def inverse_transform(images):
108110
return (images+1.)/2.

0 commit comments

Comments
 (0)