python - 凯拉斯 |类型错误 : __init__() missing 1 required positional argument: 'nb_col'

标签 python keras

我目前正在尝试将本教程代码实现到我自己的 convnet.py 中,但出现错误。 Tutorial

这是完整的错误:

Traceback (most recent call last):
    File "convnet.py", line 6, in <module>
        model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150)))
TypeError: __init__() missing 1 required positional argument: 'nb_col'

这是程序出错的前 10 行:

from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense

model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

代码位于文件 convnet.py 中,我这样运行文件: python convnet.py

最佳答案

您可能正在使用具有以下签名的旧版本 Keras:

Conv2D(self, nb_filter, nb_row, nb_col, ...)

对于这个旧版本,您可以将转换层定义为:

model.add(Conv2D(32, 3, 3, input_shape=(3, 150, 150)))

您可以检查您使用的版本:

import keras
print(keras.__version__)

我建议您更新 Keras。

关于python - 凯拉斯 |类型错误 : __init__() missing 1 required positional argument: 'nb_col' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42947295/

相关文章:

python - 如何在 Keras python 中输入 LSTM 模型?

python - 在 Pelican 中从文件名自动生成标题

python - 如何禁用外部库功能的打印日志?

python - 在 matplotlib 中创建曲面并抛出线条

Keras Hypermodel - 使用默认参数构建

machine-learning - 多标签图像分类: is it necessary to have training data for each combination of labels?

python - Keras ImageDataGenerator 具有用于旋转和平移的中心裁剪

python - 在 .py 文件中引用 django 中的静态文件(不在模板中)

python - 为什么 Serverless 在尝试打包或部署时会产生 Invalid Cross-device link 错误?

python - 兼容 Keras 和 Tensorflow 版本