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

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.

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.

Related

save pyspark model with MLflow

I'm working on Dataiku notebook and I'm trying to save pyspark model from my notebook to dataiku managed folder with MLflow
import mlflow
mlflow.spark.save_model(model, "/opt/dataiku/design/managed_folders/PROJET_TEST/9KeBcUKy/ML_SAVED_V26_01_2023")
I'm getting this warning
2023/01/26 15:11:44 WARNING mlflow.utils.environment: Encountered an unexpected error while inferring pip requirements (model URI: /opt/dataiku/design/managed_folders/PROJET_TEST/9KeBcUKy/ML_SAVED_V26_01_2023, flavor: spark), fall back to return ['pyspark==3.3.1']. Set logging level to DEBUG to see the full traceback.
And there are not part-00000 files
requirements.txt
mlflow<3,>=2.1
pyspark==3.3.1
:)
I tried to change python version from 3.7 to 3.8

How can I fix the attribute error in VS code when the same code runs perfectly on colab?

I was running the PySINDy package and I kept on getting the module not found-error when I ran this:
pip install pysindy
import pysindy as ps
I fixed this by downgrading the Python in my VS code to 3.8.9. But I do get the following note:
note: This error originates from a subprocess, and is likely not a problem with pip.Note: you may need to restart the kernel to use updated packages.
I am now getting the attribute error when I run the following:
differentiation_method = ps.FiniteDifference(order=2)
Here's the error:
AttributeError: module 'pysindy' has no attribute 'differentiation'
Can someone please help me with this? (I successfully ran the entire code earlier on google colab and the online Jupyter, but I am unable to do it locally. I use MAC os and Jupyter via VS Code.)

Why can't I import and use machine.SoftI2C in Micropython v.1.13 on ESP32?

This relates to an ESP32 development module (from Amazon, similar to the DoIt module). I have Micropython v1.13 (Sep 2020) installed. According to the Micropython documentation
http://docs.micropython.org/en/latest/library/machine.I2C.html?highlight=i2c#machine.I2C
there is a class 'machine.SoftI2C(scl, sda, *, freq=400000, timeout=255)'. By my reckoning, I should be able to do:
'from machine import SoftI2C'
But it gives the error:
ImportError: 'can't import name SoftI2C'
SoftI2C is not listed when using 'help(machine)' (after 'import machine'), whereas I2C is. SoftI2C does not seem to exist.
This also applied to MicroPython v1.12
Any thoughts, anyone??
You're running version 1.13, but it looks like the SoftI2C name was introduced in commit c35deb2, which post-dates the 1.13 release.
It may be that the "latest" documentation tracks the head of the repository rather than the most current stable release. You can find the 1.13 docs here, and you'll note there is no notice of SoftI2C.
Try running a more recent build (I'm running one I downloaded today), which seems to be working fine).

PIL thinks every image I give it is corrupted

I'm trying to get an array of RGB values for a jpeg. Using the code
from PIL import Image
im = Image.open('lion.jpg')
pix = list(im.getdata())
gives the error
IOError: broken data stream when reading image file
The picture in the code is this one, which I got from google for testing:
but the code returns the same error for every picture I've tried, from a variety of sources (google, phone, etc...). When I push forward and load the image anyway, all the pixel values are black.
I've tried doing
from PIL import Image, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
but all that does is suppress the error; the pixel values are still black.
It seems other people have had this problem elsewhere, like here, but so far other solutions have failed me. Any suggestions?
I'm on Mac 10.10, with python 2.7.8. I first installed Pillow with pip, and then from the source. I have confirmed that libjpeg is installed.
I don't really have an answer, but I can give you the setup of mine for which this is working fine.
The following script:
from PIL import Image
if __name__ == '__main__':
im = Image.open('lion.jpg'))
pix = list(im.getdata())
print('The image has {} pixels'.format(len(pix)))
import PIL, sys
print('Using Python version {}'.format(sys.version))
print('Using PIL version {}'.format(PIL.VERSION))
print('Using Pillow version {}'.format(PIL.PILLOW_VERSION))
Gives as a result on my Macbook with OS X El Capitan (10.11.6):
The image has 1183000 pixels
Using Python version 3.5.1 |Continuum Analytics, Inc.| (default, Dec 7 2015, 11:24:55)
[GCC 4.2.1 (Apple Inc. build 5577)]
Using PIL version 1.1.7
Using Pillow version 3.1.0
Process finished with exit code 0

Installing Tensorflow from source

I've been trying to install Tensorflow and get it working over the past few days. Whilst I have managed to install TF and get it working as tested by opening Python in the terminal and typing,
import tensorflow as tf
I have not been successful attempting to retrain Inception v3. I managed to install it from source once by following the instructions laid out here however I am no longer able to do so. When I get to the section 'Create the pip package and install' and go to run bazel build -c opt //tensorflow/tools/pip_package:build_pip_package in the root of my Tensorflow directiory I get the following error.
kieran#kieranUbuntu:~/tensorflow$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
ERROR: /home/kieran/tensorflow/tensorflow/core/BUILD:1068:1: no such target '//tensorflow/tools/git:gen/spec.json': target 'gen/spec.json' not declared in package 'tensorflow/tools/git' defined by /home/kieran/tensorflow/tensorflow/tools/git/BUILD and referenced by '//tensorflow/core:version_info_gen'.
ERROR: /home/kieran/tensorflow/tensorflow/core/BUILD:1068:1: no such target '//tensorflow/tools/git:gen/head': target 'gen/head' not declared in package 'tensorflow/tools/git' defined by /home/kieran/tensorflow/tensorflow/tools/git/BUILD and referenced by '//tensorflow/core:version_info_gen'.
ERROR: /home/kieran/tensorflow/tensorflow/core/BUILD:1068:1: no such target '//tensorflow/tools/git:gen/branch_ref': target 'gen/branch_ref' not declared in package 'tensorflow/tools/git' defined by /home/kieran/tensorflow/tensorflow/tools/git/BUILD and referenced by '//tensorflow/core:version_info_gen'.
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted.
INFO: Elapsed time: 3.063s
This is the same error I ran into when I managed to install it and then attempted retaining the classifier following this tutorial. At the section, bazel build tensorflow/examples/image_retraining:retrain.
I just can't figure out what is going wrong and I have been trying for so long.
I'm using this pip version, # Ubuntu/Linux 64-bit, CPU only, Python 2.7
I think you should search before ask, This link can probably solve your issue.
The issue lied in the incorrect use of ./configure. Whilst it was ran I currently have two versions of python on my computer, both of which are stored in different locations, when running ./configure I pointed it to the wrong python version. After rectifying the issue everything worked correctly.