K Vijayaprabakaran
K Vijayaprabakaran

Reputation: 81

ImportError: cannot import name normalize_data_format

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.

Upvotes: 7

Views: 17594

Answers (9)

Tiến Nguyễn
Tiến Nguyễn

Reputation: 21

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

Upvotes: 2

ALI Q SAEED
ALI Q SAEED

Reputation: 521

I had the same problem. I solved it by using this :

from tensorflow.keras.utils import normalize

instead of :

from keras.utils import normalize

Upvotes: 0

Gadosey P.
Gadosey P.

Reputation: 85

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

Upvotes: 3

Isaias Prestes
Isaias Prestes

Reputation: 51

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__)

Upvotes: 0

Buddhi
Buddhi

Reputation: 995

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

Upvotes: 3

Xu Pan
Xu Pan

Reputation: 51

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.

Upvotes: 5

gizzmole
gizzmole

Reputation: 1627

This bug is reported and fixed here: https://github.com/keras-team/keras-contrib/issues/291

Upvotes: 0

Prisy
Prisy

Reputation: 1

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...

Upvotes: 0

Upasana Mittal
Upasana Mittal

Reputation: 2680

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.

Upvotes: 0

Related Questions