在 Keras 的顺序模型中添加 Conv2D 时出现属性错误
Getting Attribute error while adding Conv2D in sequential model of Keras
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,请遵循此 link。
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,请遵循此 link。