Christian
Christian

Reputation: 13

Module error trying to import keras.metrics

The following code (being run in a notebook in IBM Cloud Pak for Data):

#!pip install --upgrade tensorflow
from tensorflow import keras;    from tensorflow.keras import layers;
import keras.metrics

is giving me the following error (see below): ultimately, "No module named 'tensorflow.compat.v2' I'm fairly a newbie with this stuff and issues dealing with the environment tends to be a bit of a pain. I'm unsure whether this is an environment issue or if something in the source code for TensorFlow is making a call to something that no longer exists. Either way, I am able to install and import these packages and submodules just fine in a Jupyter notebook that's hosted local to my laptop. Please advise. Thanks...

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-163-966f980cdeb6> in <module>
      1 #!pip install --upgrade tensorflow
      2 from tensorflow import keras;    from tensorflow.keras import layers;
----> 3 import keras.metrics

/opt/conda/envs/Python-3.7-main/lib/python3.7/site-packages/keras/__init__.py in <module>
     20 # pylint: disable=unused-import
     21 from tensorflow.python import tf2
---> 22 from keras import distribute
     23 
     24 # See b/110718070#comment18 for more details about this import.

/opt/conda/envs/Python-3.7-main/lib/python3.7/site-packages/keras/distribute/__init__.py in <module>
     16 
     17 # pylint: disable=unused-import
---> 18 from keras.distribute import sidecar_evaluator

/opt/conda/envs/Python-3.7-main/lib/python3.7/site-packages/keras/distribute/sidecar_evaluator.py in <module>
     16 """Python module for evaluation loop."""
     17 
---> 18 import tensorflow.compat.v2 as tf
     19 
     20 import re

ModuleNotFoundError: No module named 'tensorflow.compat.v2'

Upvotes: 0

Views: 3765

Answers (1)

user11530462
user11530462

Reputation:

Use below import statements

from tensorflow import keras;    from tensorflow.keras import layers;
from tensorflow.keras import metrics

Upvotes: 1

Related Questions