from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras.optimizers import SGD
model = Sequential()
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(100, 100,3)))
输入:带3个通道的100x100图像 32个卷积滤波器,每个大小为3x3 得到以下错误:
AttributeError Traceback (most recent call last)
<ipython-input-1-8045ebb1a70a> in <module>()
7 # input: 100x100 images with 3 channels -> (100, 100, 3) tensors.
8 # this applies 32 convolution filters of size 3x3 each.
----> 9 model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(100, 100, 3)))
/usr/local/lib/python2.7/dist-packages/keras/models.pyc in add(self, layer)
420 # and create the node connecting the current layer
421 # to the input layer we just created.
--> 422 layer(x)
423
424 if len(layer.inbound_nodes) != 1:
/usr/local/lib/python2.7/dist-packages/keras/engine/topology.pyc in __call__(self, inputs, **kwargs)
552
553 # Actually call the layer, collecting output(s), mask(s), and shape(s).
--> 554 output = self.call(inputs, **kwargs)
555 output_mask = self.compute_mask(inputs, previous_mask)
556
/usr/local/lib/python2.7/dist-packages/keras/layers/convolutional.pyc in call(self, inputs)
162 padding=self.padding,
163 data_format=self.data_format,
--> 164 dilation_rate=self.dilation_rate)
165 if self.rank == 3:
166 outputs = K.conv3d(
/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.pyc in conv2d(x, kernel, strides, padding, data_format, dilation_rate)
2854 x = _preprocess_conv2d_input(x, data_format)
2855 padding = _preprocess_padding(padding)
-> 2856 x = tf.nn.convolution(
2857 input=x,
2858 filter=kernel,
AttributeError: 'module' object has no attribute 'convolution'
任何人都可以帮忙吗?这个问题是因为新的分发keras 2.0吗?
答案 0 :(得分:2)
Keras 2.0 将TensorFlow升级为 TensorFlow 1.0 是先决条件。 虽然在Keras官方网站上没有提及。
只需升级到Tensorflow 1.0即可解决上述问题
要升级Tensorflow,请按照此link。