Installation problem with TensorFlow 1.4

1,164 views
Skip to first unread message

Jim Lloyd

unread,
Nov 11, 2017, 11:06:48 PM11/11/17
to Keras-users
I've installed TensorFlow 1.4 and would like to be able to use Keras from tensorflow.keras... But something with the module paths isn't right. While I can access the module path tensorflow.keras, I can't access any of the nested modules as expected. After a little experimentation, I discovered that I can access them if I insert ".python." into the path, e.g.

from tensorflow.python.keras.callbacks import ModelCheckpoint

Otherwise, my installation seems to be working just fine. By adjusting my imports this way, my applications are now working with Keras from the TensorFlow 1.4 install. But I'd like to understand what is wrong and fix it. Anyone have any ideas?

FYI, I'm developing on Mac. I did the install in a pyenv virtualenv environment.

Jim Lloyd

unread,
Nov 12, 2017, 6:04:40 PM11/12/17
to Keras-users
After more experimentation, I have to conclude that this is expected behavior. I tried a "native pip" install in a fresh environment and got the same results. If there was a bug here, it would likely be in tensorflow/__init__.py, but that file didn't change in any significant way recently. It seems to me that the expectation is that we do a single import:

import tensorflow as tf

and then always use full paths to reference any nested symbols in the tf namespace, which I suppose is somewhat better than inserting `.python.` inside the paths when importing.

And of course, none of this is specific to Keras.





--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/ab02a7da-4ead-4247-b80a-8f6d2a74b1c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daπid

unread,
Nov 13, 2017, 3:19:31 AM11/13/17
to Jim Lloyd, Keras-users
It works for me. How have you installed it? I built it from source, since I want XLA.

Reading the source, lib/python3.5/site-packages/tensorflow/__init__.py, L24 you can see "from tensorflow.python import *", and that in turn imports Keras.


In [1]: import tensorflow
tenso
In [2]: tensorflow.keras
Out[2]: <module 'tensorflow.python.keras' from '/home/david/.virtualenvs/py35/lib/python3.5/site-packages/tensorflow/python/keras/__init__.py'>

In [3]: dir(tensorflow.keras)
Out[3]:
['Input',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 '__version__',
 '_impl',
 'activations',
 'applications',
 'backend',
 'callbacks',
 'constraints',
 'datasets',
 'estimator',
 'initializers',
 'layers',
 'losses',
 'metrics',
 'models',
 'optimizers',
 'preprocessing',
 'regularizers',
 'utils',
 'wrappers']

In [4]: tensorflow.keras.utils
Out[4]: <module 'tensorflow.python.keras.utils' from '/home/david/.virtualenvs/py35/lib/python3.5/site-packages/tensorflow/python/keras/utils/__init__.py'>

In [5]: tensorflow.keras.models
Out[5]: <module 'tensorflow.python.keras.models' from '/home/david/.virtualenvs/py35/lib/python3.5/site-packages/tensorflow/python/keras/models/__init__.py'>


On 13 November 2017 at 00:04, Jim Lloyd <jim....@gmail.com> wrote:
After more experimentation, I have to conclude that this is expected behavior. I tried a "native pip" install in a fresh environment and got the same results. If there was a bug here, it would likely be in tensorflow/__init__.py, but that file didn't change in any significant way recently. It seems to me that the expectation is that we do a single import:

import tensorflow as tf

and then always use full paths to reference any nested symbols in the tf namespace, which I suppose is somewhat better than inserting `.python.` inside the paths when importing.

And of course, none of this is specific to Keras.




On Sat, Nov 11, 2017 at 8:06 PM Jim Lloyd <jim....@gmail.com> wrote:
I've installed TensorFlow 1.4 and would like to be able to use Keras from tensorflow.keras... But something with the module paths isn't right. While I can access the module path tensorflow.keras, I can't access any of the nested modules as expected. After a little experimentation, I discovered that I can access them if I insert ".python." into the path, e.g.

from tensorflow.python.keras.callbacks import ModelCheckpoint

Otherwise, my installation seems to be working just fine. By adjusting my imports this way, my applications are now working with Keras from the TensorFlow 1.4 install. But I'd like to understand what is wrong and fix it. Anyone have any ideas?

FYI, I'm developing on Mac. I did the install in a pyenv virtualenv environment.

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/CAHqficggV8AMQ8aDUaXUS-Oi26VWLWRJ3NHge1gdY_jApj3JZw%40mail.gmail.com.

Didier Dumet

unread,
Nov 14, 2017, 4:02:07 PM11/14/17
to Keras-users
Hi,

Same issue here.

From an Anaconda 5.0.1 install on windows 10:

- virtualenv env_tensorflow
- source env_tensorflow/Scripts/activate
- pip install --upgrade tensorflow-gpu
- pip install jupyter

from tensorflow.keras.preprocessing.text import Tokenizer

gives:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-7052d53d8620> in <module>()
      1 # tensorflow
      2 # from tensorflow.python.keras.preprocessing.text import Tokenizer
----> 3 from tensorflow.keras.preprocessing.text import Tokenizer

ModuleNotFoundError: No module named 'tensorflow.keras'

whereas "from tensorflow.python.keras.preprocessing.text import Tokenizer" works.

Is this an install problem in some way?

Daπid

unread,
Nov 15, 2017, 3:04:15 AM11/15/17
to Didier Dumet, Keras-users
I see the error now:


from tensorflow.keras.preprocessing.text import Tokenizer

fails for me too, but

import tensorflow
tensorflow.keras.preprocessing.text.Tokenizer

works. It don't know exactly how the import machinery works, but it seems like something easy to fix.

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages