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 吗?
升级TensorFlow到TensorFlow 1.0是先决条件为Keras 2.0。虽然 Keras 官方网站上没有提到它。
只需升级到 Tensorflow 1.0 即可解决上述问题
要升级 Tensorflow,请点击此链接。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句