Updated keras version causes problem!

1,064 views
Skip to first unread message

Loser

unread,
Mar 17, 2017, 9:43:17 PM3/17/17
to Keras-users
I just reviewed the API for keras, and could see that function names for convoution was changed and so on. 

So to be up to date i decided to update my keras version by sudo pip install git+git://github.com/fchollet/keras.git --upgrade

This resulted in I am being unable to train my neural network... I am received this error message: 


AttributeError: 'module' object has no attribute 'convolution'


My imports:

import glob, os
import sys
import ast
from os import listdir
from os.path import isfile, join
import numpy as np
import re
import itertools
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import seaborn as sb
from keras.utils import np_utils
from matplotlib import cm
from PIL import Image
from shutil import copyfile
import keras
from keras.models import Sequential
import scipy
from keras.layers.core import Dense, Activation, Lambda, Reshape,Flatten
from keras.layers.convolutional import Conv2D, MaxPooling2D, ZeroPadding2D, SeparableConv2D
#from keras.utils.visualize_util import plot
from keras.utils import np_utils
from keras.layers.advanced_activations import PReLU
from keras.layers.advanced_activations import ELU
from keras.layers import Dropout
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
from keras import backend as K
from keras.callbacks import ReduceLROnPlateau
from keras.callbacks import CSVLogger
from keras.callbacks import EarlyStopping
from sklearn.cross_validation import train_test_split
from sklearn.model_selection import KFold
from sklearn.preprocessing import MaxAbsScaler,MinMaxScaler
from keras.models import load_model
from skimage.util.shape import view_as_blocks
from keras.wrappers.scikit_learn import KerasRegressor
from keras.constraints import maxnorm
from sklearn.model_selection import GridSearchCV
import shutil, errno
import math
import pickle

and network structure:


def create_model(init_mode='uniform',activation_mode='linear',optimizer_mode="adam", activation_mode_conv = 'linear'):
        model
= Sequential()




        model
.add(ZeroPadding2D((6,4),input_shape=(6,3,3)))
        model
.add(Conv2D(filters = 32,kernel_size=(3,3) , activation=activation_mode_conv))
       
print model.output_shape
        model
.add(Conv2D(filters = 32, kernel_size=(3,3), activation=activation_mode_conv))
       
print model.output_shape
        model
.add(Conv2D(pool_size=(2,2),strides=(2,1)))
       
print model.output_shape
        model
.add(Conv2D(filters = 64, kernel_size=(3,3) , activation=activation_mode_conv))
       
print model.output_shape
        model
.add(Conv2D(filters = 64, kernel_size=(3,3) , activation=activation_mode_conv))
       
print model.output_shape
        model
.add(Conv2D(pool_size=(2,2),strides=(2,1)))
        model
.add(Flatten())
       
print model.output_shape
        model
.add(Dense(output_dim=32, input_dim=64, init=init_mode,activation=activation_mode))
        model
.add(Dense(output_dim=13, input_dim=50, init=init_mode,activation=activation_mode))
        model
.add(Dense(output_dim=1, input_dim=13, init=init_mode,activation=activation_mode))
        model
.add(Dense(output_dim=1,  init=init_mode, activation=activation_mode))
       
#print model.summary()
        model
.compile(loss='mean_squared_error',optimizer=optimizer_mode)


       
return model

Daπid

unread,
Mar 18, 2017, 2:58:46 AM3/18/17
to Loser, Keras-users
Your script doesn't give the error you say.

This line fails, though:

Conv2D(pool_size=(2,2),strides=(2,1))


I think you mean to add a max pooling there.

In the future, please, try to send a simple self contained example,
that will make easier to help you. For example, of your long list of
imports, you are only using

from keras.models import Sequential
from keras.layers.core import Dense, Activation, Lambda, Reshape,Flatten
from keras.layers.convolutional import Conv2D, MaxPooling2D,
ZeroPadding2D, SeparableConv2D

The rest is noise.
> --
> You received this message because you are subscribed to the Google Groups
> "Keras-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to keras-users...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/keras-users/4aa02d52-9efb-49a3-a27c-f034c36148c9%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

angeloa...@gmail.com

unread,
Mar 19, 2017, 5:50:55 PM3/19/17
to Keras-users, nof...@gmail.com
I'm having the problem that he stated when running the cifar10_cnn.py example in the github repo.

AttributeError: 'module' object has no attribute 'convolution'

I'm currently using Keras v2.0.1 and TensorFlow v0.11. I know there has been a lot incompatible changes from v1.0 to v0.11 but I can't seem to find whether Keras v2.0 requires TensorFlow v1.0. Can you confirm? Thank you.

François Chollet

unread,
Mar 19, 2017, 5:57:05 PM3/19/17
to angeloa...@gmail.com, Keras-users, nof...@gmail.com
Keras 2 is not meant to be used with versions of TF earlier than 1.0.
TF 1.0 is not backwards compatible with earlier versions of TF.
The right move here is to upgrade TF to the latest available version.

To unsubscribe from this group and stop receiving emails from it, send an email to keras-users+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/7c3c7d31-0d86-49e5-b905-5b5977fd8fb0%40googlegroups.com.

Carlton Banks

unread,
Mar 19, 2017, 6:01:43 PM3/19/17
to François Chollet, angeloa...@gmail.com, Keras-users
I did end up upgrading TF, and everything worked out in the end. 
I used pip upgrade, but can i see now that i should probably have done it from the sources as it didn’t install SSEx and AVX.
Reply all
Reply to author
Forward
0 new messages