From 3b03f2f7f18470c1da30d1d27d50fd7da8d91f26 Mon Sep 17 00:00:00 2001 From: Breno Batista da Silva Date: Sun, 24 Jan 2021 00:57:54 -0300 Subject: [PATCH 1/2] fix:: replace scipy.misc with imageio and skimage As state by @ML-Chen, `scipy.misc.imread` and `scipy.misc.imresize` has been deprecated and is no longer available with recent versions of scipy. Instead, we can replace it with `from imageio import imread` and `from skimage.transform import resize`. This should close #2. --- is_fid_pytorch.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/is_fid_pytorch.py b/is_fid_pytorch.py index a6bfdff..aaec078 100644 --- a/is_fid_pytorch.py +++ b/is_fid_pytorch.py @@ -83,24 +83,28 @@ * https://paperswithcode.com/sota/image-generation-generative-models-of-ci * https://paperswithcode.com/task/conditional-image-generation """ +import os +import sys +import random +import pathlib +import numpy as np import torch import torch.nn as nn +import torch.utils.data + from torch.autograd import Variable from torch.nn import functional as F -import torch.utils.data from torchvision.models.inception import inception_v3 +from imageio import imread +from skimage.transform import resize from scipy.stats import entropy -import scipy.misc from scipy import linalg -import numpy as np + from tqdm import tqdm from glob import glob -import pathlib -import os -import sys -import random + CUR_DIRNAME = os.path.dirname(os.path.abspath(__file__)) @@ -376,8 +380,8 @@ def read_folder(foldername): img_list = [] print('Reading Images from %s ...' % foldername) for file in tqdm(files): - img = scipy.misc.imread(file, mode='RGB') - img = scipy.misc.imresize(img, (299, 299), interp='bilinear') + img = imread(file, pilmode='RGB') + img = resize(img, (299, 299), mode='symmetric', preserve_range=True) img = np.cast[np.float32]((-128 + img) / 128.) # 0~255 -> -1~1 img = np.expand_dims(img, axis=0).transpose(0, 3, 1, 2) # NHWC -> NCHW img_list.append(img) From 7e395f2ba3529a7c717f42ac119045d51b14a4b7 Mon Sep 17 00:00:00 2001 From: Breno Batista da Silva Date: Mon, 1 Mar 2021 21:52:13 -0300 Subject: [PATCH 2/2] replace imageio with PIL changes suggested by @ludgerpaehler --- is_fid_pytorch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/is_fid_pytorch.py b/is_fid_pytorch.py index aaec078..5bbf4c8 100644 --- a/is_fid_pytorch.py +++ b/is_fid_pytorch.py @@ -97,7 +97,7 @@ from torch.nn import functional as F from torchvision.models.inception import inception_v3 -from imageio import imread +from PIL import Image from skimage.transform import resize from scipy.stats import entropy from scipy import linalg @@ -380,8 +380,8 @@ def read_folder(foldername): img_list = [] print('Reading Images from %s ...' % foldername) for file in tqdm(files): - img = imread(file, pilmode='RGB') - img = resize(img, (299, 299), mode='symmetric', preserve_range=True) + img = Image.open(file) + img = np.array(img.resize((299, 299), resample=Image.BILINEAR)) img = np.cast[np.float32]((-128 + img) / 128.) # 0~255 -> -1~1 img = np.expand_dims(img, axis=0).transpose(0, 3, 1, 2) # NHWC -> NCHW img_list.append(img)