简体   繁体   中英

scipy.misc.imresize not working in GCP ml-engine

I'm trying to submit the following toy snippet as a job in GCP ml-engine:

import tensorflow as tf
import numpy as np
import scipy.misc

x = np.zeros([10, 10, 1])
y = scipy.misc.imresize(x[:, :, 0], [50, 50, 1], interp='nearest')
print(y)
print(y.shape)

It is giving the following error after the job starts on server:

File "/root/.local/lib/python2.7/site-packages/teste/test.py", line 6, in <module>
y = scipy.misc.imresize(x[:, :, 0], [50, 50, 1], interp='nearest')
AttributeError: 'module' object has no attribute 'imresize'

It works perfectly on local, and according to Cloud-ML docs, the scipy package is supported. Apparently it is not an issue with the module itself, as the import statement is not giving any error.

scipy.misc.imresize requires PIL to be installed, which you probably have installed locally (since it works).

To ensure your code runs correctly in the cloud, you need to ensure pillow is installed. If you have created your own setup.py include pillow in the list of requirements. If you have to create your own, create a setup.py like this:

from setuptools import find_packages
from setuptools import setup

REQUIRED_PACKAGES = ['pillow']

setup(
    name='trainer',
    version='0.1',
    install_requires=REQUIRED_PACKAGES,
    packages=find_packages(),
    include_package_data=True,
    description='My trainer application package.'
)

( source , with one important modification, the packages attribute)

See the official CloudML Engine documentation for more information about recommended directory layout and packaging instructions.

It was deprecated in 1.3.0. Contrary to using Pillow, reinstall scipy 1.0.0

pip install scipy==1.0.0

Or

pip3 install scipy==1.0.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM