Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'tf'

I'm having problem with tensorflow. I want to use ImageDataGenerator, but I'm receiving error ModuleNotFoundError: No module named 'tf'. Not sure what is the problem. I added this tf.version to test will it work, and it shows the version of tensorflow.

    import tensorflow as tf
    from tensorflow import keras
    print(tf.__version__)
    from tf.keras.preprocessing.image import ImageDataGenerator

When I run this code, I get this:

2.1.0
Traceback (most recent call last):
  File "q:/TF/Kamen papir maaze/rks.py", line 14, in <module>
    from tf.keras.preprocessing.image import ImageDataGenerator
ModuleNotFoundError: No module named 'tf'
like image 352
Ademir Omercehajic Avatar asked Apr 08 '20 15:04

Ademir Omercehajic


1 Answers

The line

import tensorflow as tf 

means you are importing tensorflow with an alias as tf to call it modules/functions.

You cannot use the alias to import other modules.

For your case, if you call directly

tf.keras.preprocessing.image.ImageDataGenerator(...) 

then it will work.

or

you need to import the module with the right module name. i.e.

from tensorflow.keras.preprocessing.image import ImageDataGenerator
like image 136
venkata krishnan Avatar answered Nov 07 '22 11:11

venkata krishnan