问题描述
嗨,我正在运行一个稍微昂贵的 aws...并试图将旧的 scipy.imread 解析为新的 imagio.read 标准。
在这个文件中 https://github.com/ml5js/training-styletransfer/blob/master/src/utils.py
import scipy.misc,numpy as np,os,sys
def save_img(out_path,img):
img = np.clip(img,255).astype(np.uint8)
scipy.misc.imsave(out_path,img)
def scale_img(style_path,style_scale):
scale = float(style_scale)
o0,o1,o2 = scipy.misc.imread(style_path,mode='RGB').shape
scale = float(style_scale)
new_shape = (int(o0 * scale),int(o1 * scale),o2)
style_target = _get_img(style_path,img_size=new_shape)
return style_target
def get_img(src,img_size=False):
img = scipy.misc.imread(src,mode='RGB') # misc.imresize(,(256,256,3))
if not (len(img.shape) == 3 and img.shape[2] == 3):
img = np.dstack((img,img,img))
if img_size != False:
img = scipy.misc.imresize(img,img_size)
return img
def exists(p,msg):
assert os.path.exists(p),msg
def list_files(in_path):
files = []
for (dirpath,dirnames,filenames) in os.walk(in_path):
files.extend(filenames)
break
return files
有 imresize 我如何将其转换为新标准。
(还有几个错误显示,比如 mode 应该是 pilmode?)
运行项目代码时出现很多问题。
但这是一个我似乎无法修复
WARNING:tensorflow:From /home/ubuntu/mlquinten/lib/python3.7/site-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
ml5.js Style Transfer Training!
Note: This traning will take a couple of hours.
Training is starting!...
Train set has been trimmed slightly..
(1,708,500,3)
UID: 97
Traceback (most recent call last):
File "style.py",line 179,in <module>
main()
File "style.py",line 156,in main
for preds,losses,i,epoch in optimize(*args,**kwargs):
File "src/optimize.py",line 107,in optimize
X_batch[j] = get_img(img_p,3)).astype(np.float32)
File "src/utils.py",line 22,in get_img
img = scipy.misc.imresize(img,img_size)
AttributeError: module 'scipy.misc' has no attribute 'imresize'
解决方法
imresize
不再是 scipy 的一部分。您可以降级到 scipy,即 1.2.1 或安装 scikit-image
并改为调用 skimage.transform.resize