I'm getting the following error while importing Keras:
ImportError: cannot import name 'dtensor' from 'tensorflow.compat.v2.experimental' (C:\Users\User\AppData\Roaming\Python\Python38\site-packages\tensorflow\_api\v2\compat\v2\experimental\__init__.py)
Tensorflow v. 2.6, Keras v. 2.6
Does anyone have an idea how to solve this error?
DTensor is part of the TensorFlow 2.9.0 release. To import dtensor you can upgrade tensorflow 2.6 to tensorflow 2.9 as follows:
pip install --upgrade tensorflow==2.9
Now, you can import dtensor either from tensorflow.experimental or from tensorflow.keras as follows:
#Using tensorflow.experimental
from tensorflow.experimental import dtensor
#Using tensorflow.keras
from tensorflow.keras import dtensor
For more information, please refer to this guide. Thank you.
I'm trying to add utils from keras_unet in google colab, but I have a problem.
import tensorflow as tfs
from keras_unet import utils
keras-unet init: TF version is >= 2.0.0 - using tf.keras instead of Keras
ModuleNotFoundError
You must install keras-unet before importing as follows
!pip install keras-unet
from keras_unet import utils
Let us know if the issue still persists. Thanks!
import sys
import os
import argparse
from setup.settings import hparams
sys.path.append(os.path.realpath(os.path.dirname(__file__)))
sys.path.append(os.path.realpath(os.path.dirname(__file__)) + "/nmt")
from nmt import nmt
import tensorflow.compat.v1 as tf
# Modified autorun from nmt.py (bottom of the file)
# We want to use original argument parser (for validation, etc)
nmt_parser = argparse.ArgumentParser()
nmt.add_arguments(nmt_parser)
# But we have to hack settings from our config in there instead of commandline options
nmt.FLAGS, unparsed = nmt_parser.parse_known_args(['--'+k+'='+str(v) for k,v in hparams.items()])
# And now we can run TF with modified arguments
tf.app.run(main=nmt.main, argv=[os.getcwd() + '\nmt\nmt\nmt.py'] + unparsed)
So i ran this and i got a error which was
ModuleNotFoundError: No module named 'tensorflow.python.layers'
this is my pip list
tb-nightly 2.3.0a20200711
tensorboard 1.14.0
tensorboard-plugin-wit 1.7.0
tensorflow 1.14.0
tensorflow-estimator 1.14.0
termcolor 1.1.0
tf-estimator-nightly 2.4.0.dev2020071101
tqdm 4.47.0
I am trying to use a pre-trained model in Tensorflow. I am using the following code:
import tensorflow as tf
from tensorflow import keras
from keras.applications import mobilenet_v2
I get the following error:
ModuleNotFoundError: No module named 'keras'
However, the following codes do work:
from tensorflow.keras.applications import mobilenet_v2
OR
from keras_applications import mobilenet_v2
The 2 methods mentioned above work but the 1st one doesn't. Why does this happen?
I've solved this problem by downgrading tensorflow to version 2.0 using this command:
pip install tensorflow==2.0
I hope it helps you.
I am very new to use github. I have installed github in ubuntu 16.04, I installed python 2.7.12, tensorflow 1.9 and keras. I want to use my own custom activation and optimizer in keras RNN. I searched in web and came to know i need to install keras-contrib package to use advanced activation and custom activation function.
So, I install the keras-contrib from github. But I don't know how to work with it and how to run the program using keras-contrib.
But i tried with following commands
git clone https://www.github.com/keras-team/keras-contrib.git
cd keras-contrib
python setup.py install
then I tried with this following code
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
from keras_contrib.layers.advanced_activations import PELU
it showing the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "keras_contrib/__init__.py", line 4, in <module>
from . import layers
File "keras_contrib/layers/__init__.py", line 3, in <module>
from .convolutional import *
File "keras_contrib/layers/convolutional.py", line 15, in <module>
from keras.utils.conv_utils import normalize_data_format
ImportError: cannot import name normalize_data_format
Anyone please check this error and help me to sort out this error.
I update the keras contribute source code installed in my linux. Follow the changes:
https://github.com/ekholabs/keras-contrib/commit/0dac2da8a19f34946448121c6b9c8535bfb22ce2
Now, it works well.
I had the same problem. I installed keras 2.2.2 version using the following command and problem solved.
pip install -q keras==2.2.2
Refer this PR.
https://github.com/keras-team/keras-contrib/pull/292
Had the same issue. The problem is that normalize_data_format function was moved to keras.backend.common from keras.utils.conv_utils in later versions of keras. You can use
import keras
and then in your code use
keras.utils.conv_utils.normalize_data_format
I found that in keras version 2.6.0 the normalize function is not lost, it is just "stored" in a file "np_utils.py", so what we need to do is just change
"
from keras.utils import normalize
to
from keras.utils.np_utils import normalize
It must be because the keras_contrib you have downloaded is not compatible with updated version of keras. Check this link https://github.com/keras-team/keras/blob/master/keras/utils/conv_utils.py
There is no function here like normalise_data_format, that is where it is throwing error.
It must be because the keras_contrib you have downloaded is not compatible with updated version of keras. Check this link https://github.com/keras-team/keras/blob/master/keras/utils/conv_utils.py
It does not work...
This bug is reported and fixed here: https://github.com/keras-team/keras-contrib/issues/291
On my Windows 10 system and in Colaboratory, using Python 3.7, I solved this problem updating Keras and installing git version of keras-contrib.
pip install -q keras==2.2.2
pip install git+https://www.github.com/keras-team/keras-contrib.git
Check your Keras version with
import keras
print(keras.__version__)
I had the same problem. I solved it by using this :
from tensorflow.keras.utils import normalize
instead of :
from keras.utils import normalize