Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 628
K Vijayaprabakaran Avatar asked Aug 02 '18 11:08

K Vijayaprabakaran


4 Answers

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.

like image 196
Xu Pan Avatar answered Oct 13 '22 03:10

Xu Pan


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

like image 32
Buddhi Avatar answered Oct 13 '22 03:10

Buddhi


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
like image 36
Gadosey P. Avatar answered Oct 13 '22 04:10

Gadosey P.


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
like image 24
Tiến Nguyễn Avatar answered Oct 13 '22 03:10

Tiến Nguyễn