ageron / handson-ml

⛔️ DEPRECATED – See https://github.com/ageron/handson-ml3 instead.
Apache License 2.0
25.2k stars 12.91k forks source link

MNist data problem in chapter 15 autoencoders..having error ImportError: cannot import name 'model_fn' from 'tensorflow_estimator.python.estimator' (unknown location) when i try lines:- #400

Open futuramark opened 5 years ago

futuramark commented 5 years ago

Having issues with chapter 15 autoencoders

ImportError: cannot import name 'model_fn' from
'tensorflow_estimator.python.estimator' (unknown location)

IS it something from the dataset not being available anymore..or from my library installation>? When I input these lines i get the error:-

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/")
from sklearn import datasets
ageron commented 5 years ago

That's odd, I just tested, it works fine for me, so I'm guessing we don't have the same library versions. Could you please update tensorflow and tensorflow_estimator to the latest versions?

pip3 install -U tensorflow
pip3 install -U tensorflow_estimator
pip3 freeze | grep tensorflow

This should install the latest version and display their versions. You should see these versions:

tensorflow==1.13.1
tensorflow-estimator==1.13.0
futuramark commented 5 years ago

I have upgraded tensorflow and tensorflow_estimator...but this is where the problem is coming from i think the estimator.. pip3 never worked for me so i used normal pip. tensorflow is 1.13.0 tensorflow_estimator 1.13.0 [image: image.png]

On Tue, Apr 9, 2019 at 4:09 PM Aurélien Geron notifications@github.com wrote:

That's odd, I just tested, it works fine for me, so I'm guessing we don't have the same library versions. Could you please update tensorflow and tensorflow_estimator to the latest versions?

pip3 install -U tensorflow pip3 install -U tensorflow_estimator pip3 freeze | grep tensorflow

This should install the latest version and display their versions. You should see these versions:

tensorflow==1.13.1 tensorflow-estimator==1.13.0

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ageron/handson-ml/issues/400#issuecomment-481267903, or mute the thread https://github.com/notifications/unsubscribe-auth/AhuYw3XSMznUT_uWJhNBDqvQinSI88t5ks5vfJ8ngaJpZM4ciV13 .

futuramark commented 5 years ago

pip freeze | grep tensorflow 'grep' is not recognized as an internal or external command, operable program or batch file.

On Tue, Apr 9, 2019 at 5:42 PM My Name markhome1980@gmail.com wrote:

I have upgraded tensorflow and tensorflow_estimator...but this is where the problem is coming from i think the estimator.. pip3 never worked for me so i used normal pip. tensorflow is 1.13.0 tensorflow_estimator 1.13.0 [image: image.png]

On Tue, Apr 9, 2019 at 4:09 PM Aurélien Geron notifications@github.com wrote:

That's odd, I just tested, it works fine for me, so I'm guessing we don't have the same library versions. Could you please update tensorflow and tensorflow_estimator to the latest versions?

pip3 install -U tensorflow pip3 install -U tensorflow_estimator pip3 freeze | grep tensorflow

This should install the latest version and display their versions. You should see these versions:

tensorflow==1.13.1 tensorflow-estimator==1.13.0

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ageron/handson-ml/issues/400#issuecomment-481267903, or mute the thread https://github.com/notifications/unsubscribe-auth/AhuYw3XSMznUT_uWJhNBDqvQinSI88t5ks5vfJ8ngaJpZM4ciV13 .

ageron commented 5 years ago

Hi @futuramark , Are you using Windows? What version? What version of Python are you using? Could you please start a python shell and run this:

import sys
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
print(tf.__version__)
print(sys.version_info)
mnist = input_data.read_data_sets("/tmp/data/")
from sklearn import datasets

Then please copy/paste the full output here (you can add ``` before and after the code to make it look good).

futuramark commented 5 years ago

I am using windows 10..python 3 and anaconda.

from tensorflow.examples.tutorials.mnist import input_data

from tensorflow_estimator.python.estimator import model_fn ImportError: cannot import name 'model_fn' from 'tensorflow_estimator.python.estimator' (unknown location)

this line gives an error. the one i mentioned.

On Wed, Apr 10, 2019 at 4:34 AM Aurélien Geron notifications@github.com wrote:

Hi @futuramark https://github.com/futuramark , Are you using Windows? What version? What version of Python are you using? Could you please start a python shell and run this:

import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_dataprint(tf.version) mnist = input_data.read_data_sets("/tmp/data/")from sklearn import datasets

Then please copy/paste the full output here (you can add ``` before and after the code to make it look good).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ageron/handson-ml/issues/400#issuecomment-481509986, or mute the thread https://github.com/notifications/unsubscribe-auth/AhuYw99DdeL-riQZLCctSxUgeWJrojPYks5vfU2ogaJpZM4ciV13 .

ageron commented 5 years ago

Hi @futuramark ,

I see that you sent an image in a previous comment, but the image is not displayed (github filters images out when they are sent by email, you need to go to github.com to upload it).

Also, you initially mentioned that the problem occurred when running this code:

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/")
from sklearn import datasets

But now you are mentioning an additional line of code:

from tensorflow_estimator.python.estimator import model_fn

It makes more sense given the error message, but what I don't understand is that this code is not in chapter 15, or in the Jupyter notebooks. So I'm not sure where you ran into it, but it's not in my book. Perhaps you copied it there by mistake? If so, just remove it and make sure you are using the latest version of the notebook.

Hope this helps.

futuramark commented 5 years ago

This code is not running i tried to send an image to show you. The problem seems to be tensorflow estimator even though i am sure it is installed

On Wed, 10 Apr 2019, 04:34 Aurélien Geron, notifications@github.com wrote:

Hi @futuramark https://github.com/futuramark , Are you using Windows? What version? What version of Python are you using? Could you please start a python shell and run this:

import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_dataprint(tf.version) mnist = input_data.read_data_sets("/tmp/data/")from sklearn import datasets

Then please copy/paste the full output here (you can add ``` before and after the code to make it look good).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ageron/handson-ml/issues/400#issuecomment-481509986, or mute the thread https://github.com/notifications/unsubscribe-auth/AhuYw99DdeL-riQZLCctSxUgeWJrojPYks5vfU2ogaJpZM4ciV13 .

ageron commented 5 years ago

Did you try to delete the line?

from tensorflow_estimator.python.estimator import model_fn
futuramark commented 5 years ago

HI,

By the way well done for the book. It is great I only had minor issues. However this is one issue I can't solve. That is not a line of code but an error message. I think I have some issue with tensorflow_estimator as if it is not installed correctly however i checked the version it is ok i re install i upgraded it to no avail.

On Thu, Apr 11, 2019 at 4:31 AM Aurélien Geron notifications@github.com wrote:

Did you try to delete the line?

from tensorflow_estimator.python.estimator import model_fn

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ageron/handson-ml/issues/400#issuecomment-481941303, or mute the thread https://github.com/notifications/unsubscribe-auth/AhuYwzQSiaqOhurU_SkAB_85YSvMnWESks5vfp6BgaJpZM4ciV13 .

ageron commented 5 years ago

It would help if I could see the full error stacktrace, showing the exact file and line where the exception was raised. Could you please copy/paste the full stacktrace here?

futuramark commented 5 years ago

I dont know exactly.how to do that..?

On Thu, 11 Apr 2019, 15:27 Aurélien Geron, notifications@github.com wrote:

It would help if I could see the full error stacktrace, showing the exact file and line where the exception was raised. Could you please copy/paste the full stacktrace here?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ageron/handson-ml/issues/400#issuecomment-482113339, or mute the thread https://github.com/notifications/unsubscribe-auth/AhuYwyMo4eNSAZ4CVqcQvkVjOuhaHD5lks5vfzgmgaJpZM4ciV13 .

futuramark commented 5 years ago

I will paste all the error later. Thanks

On Thu, 11 Apr 2019, 15:28 My Name, markhome1980@gmail.com wrote:

I dont know exactly.how to do that..?

On Thu, 11 Apr 2019, 15:27 Aurélien Geron, notifications@github.com wrote:

It would help if I could see the full error stacktrace, showing the exact file and line where the exception was raised. Could you please copy/paste the full stacktrace here?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ageron/handson-ml/issues/400#issuecomment-482113339, or mute the thread https://github.com/notifications/unsubscribe-auth/AhuYwyMo4eNSAZ4CVqcQvkVjOuhaHD5lks5vfzgmgaJpZM4ciV13 .

ageron commented 5 years ago

For example, if I run a bad command like this:

>>> import tensorflow as tf
>>> tf.exp("bad argument")

I get an error like this:

>>> tf.exp("bad argument")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../tensorflow/python/ops/gen_math_ops.py", line 3758, in exp
    x, name=name, ctx=_ctx)
  File ".../tensorflow/python/ops/gen_math_ops.py", line 3807, in exp_eager_fallback
    ctx=_ctx, name=name)
  File ".../tensorflow/python/eager/execute.py", line 66, in quick_execute
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InternalError: Could not find valid device for node.
Node: {{node Exp}}
All kernels registered for op Exp :
  device='CPU'; T in [DT_FLOAT]
  device='CPU'; T in [DT_HALF]
  device='CPU'; T in [DT_DOUBLE]
  device='CPU'; T in [DT_COMPLEX64]
  device='CPU'; T in [DT_COMPLEX128]
 [Op:Exp]

This is called the stacktrace. That's what I need you to copy/paste for me, please.

futuramark commented 5 years ago

from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("/tmp/data/")

This is where i get the error, could it be because i am not cloning your data with git.? and the full error is:-

---------------------------------------------------------------------------ImportError Traceback (most recent call last) in ----> 1 from tensorflow.examples.tutorials.mnist import input_data 2 mnist = input_data.read_data_sets("/tmp/data/") ~\Anaconda3\lib\site-packages\tensorflow\examples\tutorials\mnist__init.py in 19 from future__ import print_function 20 ---> 21 from tensorflow.examples.tutorials.mnist import input_data 22 from tensorflow.examples.tutorials.mnist import mnist ~\Anaconda3\lib\site-packages\tensorflow\examples\tutorials\mnist\input_data.py in 28 from six.moves import xrange # pylint: disable=redefined-builtin 29 import tensorflow as tf---> 30 from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets 31 # pylint: enable=unused-import ~\Anaconda3\lib\site-packages\tensorflow\contrib__init__.py in

38 from tensorflow.contrib import data 39 from tensorflow.contrib import deprecated---> 40 from tensorflow.contrib import distribute 41 from tensorflow.contrib import distributions 42 from tensorflow.contrib import estimator ~\Anaconda3\lib\site-packages\tensorflow\contrib\distribute\__init__.py in 31 from tensorflow.contrib.distribute.python.parameter_server_strategy import ParameterServerStrategy 32 from tensorflow.contrib.distribute.python.step_fn import *---> 33 from tensorflow.contrib.distribute.python.tpu_strategy import TPUStrategy 34 from tensorflow.python.distribute.cross_device_ops import * 35 from tensorflow.python.distribute.distribute_config import DistributeConfig ~\Anaconda3\lib\site-packages\tensorflow\contrib\distribute\python\tpu_strategy.py in 25 import functools 26 ---> 27 from tensorflow.contrib.tpu.python.ops import tpu_ops 28 from tensorflow.contrib.tpu.python.tpu import tpu 29 from tensorflow.contrib.tpu.python.tpu import tpu_system_metadata as tpu_system_metadata_lib ~\Anaconda3\lib\site-packages\tensorflow\contrib\tpu\__init__.py in 71 from tensorflow.contrib.tpu.python.tpu.bfloat16 import * 72 from tensorflow.contrib.tpu.python.tpu.device_assignment import *---> 73 from tensorflow.contrib.tpu.python.tpu.keras_support import tpu_model as keras_to_tpu_model 74 from tensorflow.contrib.tpu.python.tpu.keras_support import TPUDistributionStrategy 75 from tensorflow.contrib.tpu.python.tpu.topology import * ~\Anaconda3\lib\site-packages\tensorflow\contrib\tpu\python\tpu\keras_support.py in 60 from tensorflow.contrib.tpu.python.ops import tpu_ops 61 from tensorflow.contrib.tpu.python.tpu import keras_tpu_variables---> 62 from tensorflow.contrib.tpu.python.tpu import tpu 63 from tensorflow.contrib.tpu.python.tpu import tpu_function 64 from tensorflow.contrib.tpu.python.tpu import tpu_optimizer ~\Anaconda3\lib\site-packages\tensorflow\contrib\tpu\python\tpu\tpu.py in 22 from six.moves import xrange # pylint: disable=redefined-builtin 23 ---> 24 from tensorflow.contrib.compiler import xla 25 from tensorflow.contrib.framework.python.framework import experimental 26 from tensorflow.contrib.tpu.python.ops import tpu_ops ~\Anaconda3\lib\site-packages\tensorflow\contrib\compiler\xla.py in 26 from tensorflow.compiler.jit.ops import xla_ops_grad # pylint: disable=unused-import 27 from tensorflow.core.framework import attr_value_pb2---> 28 from tensorflow.python.estimator import model_fn as model_fn_lib 29 from tensorflow.python.framework import ops 30 from tensorflow.python.ops import array_ops ~\Anaconda3\lib\site-packages\tensorflow\python\estimator\model_fn.py in 24 from __future__ import print_function 25 ---> 26 from tensorflow_estimator.python.estimator import model_fn 27 28 # Include attrs that start with single underscore. ImportError: cannot import name 'model_fn' from 'tensorflow_estimator.python.estimator' (unknown location)
ageron commented 5 years ago

The error message seems to indicate that the tensorflow_estimator.python.estimator package exists but it does not contain a module named model_fn.

If tensorflow_estimator did not exist, or if tensorflow_estimator.python or tensorflow_estimator.python.estimator did not exist, you would get a ModuleNotFoundError exception, not an ImportError, for example:

>>> from tensorflow_estimator.does_not_exist import model_fn
[...]
ModuleNotFoundError: No module named 'tensorflow_estimator.does_not_exist'

I checked the TensorFlow Estimator source code: it seems that model_fn.py was not at that location in tensorflow_estimator version 1.12. So I'm guessing you have an old version of tensorflow_estimator, somehow. Perhaps try to uninstall tensorflow and tensorflow_estimator completely (from Anaconda, and perhaps pip, I'm not sure how everything is installed on your machine), and try to reinstall them cleanly (tensorflow version 1.13.1 and tensorflow-estimator version 1.13.0).

futuramark commented 5 years ago

Thanks Aurelien I will definetely try that. I think it is also something to do with tensorflow-estimator.

Love the book really enjoyed it and learned a lot. Thanks Mark.

On Fri, Apr 12, 2019 at 7:36 AM Aurélien Geron notifications@github.com wrote:

The error message seems to indicate that the tensorflow_estimator.python.estimator package exists but it does not contain a module named model_fn.

If tensorflow_estimator did not exist, or if tensorflow_estimator.python or tensorflow_estimator.python.estimator did not exist, you would get a ModuleNotFoundError exception, not an ImportError, for example:

from tensorflow_estimator.does_not_exist import model_fn [...] ModuleNotFoundError: No module named 'tensorflow_estimator.does_not_exist'

I checked the TensorFlow Estimator source code: it seems that model_fn.py was not at that location in tensorflow_estimator version 1.12. So I'm guessing you have an old version of tensorflow_estimator, somehow. Perhaps try to uninstall tensorflow and tensorflow_estimator completely (from Anaconda, and perhaps pip, I'm not sure how everything is installed on your machine), and try to reinstall them cleanly (tensorflow version 1.13.1 and tensorflow-estimator version 1.13.0).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ageron/handson-ml/issues/400#issuecomment-482443803, or mute the thread https://github.com/notifications/unsubscribe-auth/AhuYwxVgG8A8mjjuXO45MHX-BuoyYHTxks5vgBtygaJpZM4ciV13 .