3

I want to run tensorflow for image recognition. I have followed all the steps for it and both keras and tensorflow are installed on my computer. Steps in this post: https://github.com/OlafenwaMoses/ImageAI/ But when I try: from imageai.Prediction import ImagePrediction

I keep getting the error: from tensorflow.python.keras.preprocessing import image ModuleNotFoundError: No module named 'tensorflow.python.keras'

I think the error comes from my installation of 'tensorflow'. When I tried the method: pip3 install --upgrade tensorflow I got the error: Could not find a version that satisfies the requirement tensorflow (from versions: ) No matching distribution found for tensorflow

So I used instead: python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

I got it from this post: TensorFlow not found using pip

My guess is that the first error drives me to the second, but I don't know how to fix any of them.

Any suggestions?

My code until the problem is:

import tensorflow

from imageai.Prediction import ImagePrediction

Blanca Calvo
  • 33
  • 1
  • 4
  • That version of TensorFlow does not have Keras, it is just too old, you should install at least TensorFlow 1.0 – Dr. Snoopy Jan 03 '19 at 16:31
  • Can you try pip3 install tensorflow==2.1, if it successfully installs then try "import tensorflow as tf". Then import image as "from tensorflow.keras.preprocessing import image:". One suggestion is please don't use "from tensorflow.python.*" as that is private to tensorflow and could change or affect other imported modules. – Vishnuvardhan Janapati Apr 24 '20 at 15:49

2 Answers2

5

Try writing

from keras.preprocessing import image

Instead of

from tensorflow.python.keras.preprocessing import image

And do the same with all Keras calls.

2

Make sure you have the latest version of tensorflow (2.0)

import tensorflow as tf
print(tf.__version__)

from tensorflow.keras.preprocessessing.text import Tokenizer
BorangeOrange1337
  • 182
  • 1
  • 1
  • 20