Search code examples
scipygoogle-cloud-platformgoogle-cloud-mlgoogle-cloud-ml-engine

Google Cloud ML scipy.misc.imread returning <PIL.JpegImagePlugin.JpegImageFile>


I am running the following snippet:

import tensorflow as tf
import scipy.misc
from tensorflow.python.lib.io import file_io

file = file_io.FileIO('gs://BUCKET/data/celebA/000007.jpg', mode='r')
img = scipy.misc.imread(file)

If I run that snippet in Cloud Console, I get back a proper array. But when that same snippet runs in Cloud ML, the img object is

<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=178x218 at 0x7F1F8F26DA10>

This stackoverflow answer suggests that libjpeg was not installed when PIL was installed. The Cloud ML Runtime Version list shows that for Tensorflow 0.12, libjpeg-dev is an installed debian package.


Solution

  • I was able to reproduce this issue on Cloud ML, and it seems to be an issue with the version of file_io in Tensorflow 0.12.1, and goes away if Tensorflow 1.0 is installed.

    If you can, upgrade to the 1.0 build of TF.

    If you need a 0.12 version, the Cloud ML "0.12" runtime uses the official 0.12.1 build of TF, but you can upload your own version to install if you like. I did not track down exactly when the issue was fixed but a Nightly Tensorflow build from Feb 2nd seemed to work.