fewshot-face-translation-GAN icon indicating copy to clipboard operation
fewshot-face-translation-GAN copied to clipboard

ImportError: cannot import name 'keras_export'

Open atinesh-s opened this issue 4 years ago • 7 comments

I am trying to run this notebook, but I am getting below error at this line from models import FaceTranslationGANInferenceModel

Using TensorFlow backend.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-13-e0f766e65a9c> in <module>()
----> 1 from models import FaceTranslationGANInferenceModel

13 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/initializers/initializers_v1.py in <module>()
     21 from tensorflow.python.framework import dtypes
     22 from tensorflow.python.ops import init_ops
---> 23 from tensorflow.python.util.tf_export import keras_export
     24 
     25 keras_export(v1=['keras.initializers.Zeros', 'keras.initializers.zeros'])(

ImportError: cannot import name 'keras_export'

Libraries: tensorflow-gpu==1.13.1, keras==2.2.4

atinesh-s avatar Dec 14 '20 06:12 atinesh-s

I tried with pip install keras==2.2.4 tensorflow==1.13.1 and it works well.

amrzv avatar Jan 07 '21 16:01 amrzv

I tried with pip install keras==2.2.4 tensorflow==1.13.1 and it works well.

Are you sure you able to run whole code successfully. I am getting below error with tensorflow==1.13.1 (CPU)

Building FAN for landmarks detection...
WARNING:tensorflow:No training configuration found in save file: the model was *not* compiled. Compile it manually.
Done.
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-19-a57db805edd7> in <module>()
----> 1 src, mask, aligned_im, (x0, y0, x1, y1), landmarks = utils.get_src_inputs(fn_src, fd, fp, idet)
      2 tar, emb_tar = utils.get_tar_inputs(fns_tar, fd, fv)

10 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/errors_impl.py in __exit__(self, type_arg, value_arg, traceback_arg)
    526             None, None,
    527             compat.as_text(c_api.TF_Message(self.status.status)),
--> 528             c_api.TF_GetCode(self.status.status))
    529     # Delete the underlying status object from memory otherwise it stays alive
    530     # as there is a reference to status from this from the traceback due to

InvalidArgumentError: Default AvgPoolingOp only supports NHWC on device type CPU
	 [[{{node 0.3562700616991372/AvgPool}}]]

Here is the notebook I am using

atinesh-s avatar Jan 09 '21 05:01 atinesh-s

@atinesh-s Yes, my bad, now I'm getting same error. Try intel-tensorflow==1.15.2, now it should work.

amrzv avatar Jan 09 '21 21:01 amrzv

@atinesh-s Yes, my bad, now I'm getting same error. Try intel-tensorflow==1.15.2, now it should work.

@amrzv Thanks, it solved the problem but it runs very slow on the CPU.

It's strange why on colab I was getting the error with tensorflow-gpu==1.13.1, keras==2.2.4 though code runs fine on cloud machine with the same libraries

atinesh-s avatar Jan 12 '21 06:01 atinesh-s

I solve this issue by using these command pip uninstall -y tensorflow pip install tensorflow-gpu==1.13.1

ibtehajali67 avatar Feb 15 '21 07:02 ibtehajali67

now throw this

/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-e0f766e65a9c> in <module>()
----> 1 from models import FaceTranslationGANInferenceModel

3 frames
/usr/local/lib/python3.7/dist-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'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

molo32 avatar Jun 13 '21 19:06 molo32

now throw this

/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-e0f766e65a9c> in <module>()
----> 1 from models import FaceTranslationGANInferenceModel

3 frames
/usr/local/lib/python3.7/dist-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'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

Try this https://github.com/shaoanlu/fewshot-face-translation-GAN/pull/32#issuecomment-873562887

amrzv avatar Jul 04 '21 10:07 amrzv