Python 凯拉斯 | 类型错误:__init__() 缺少 1 个必需的位置参数:'nb_col'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42947295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 22:18:02  来源:igfitidea点击:

Keras | TypeError: __init__() missing 1 required positional argument: 'nb_col'

pythonkeras

提问by Gertjan Brouwer

I am currently trying to implement this tutorial code into my own convnet.py but I get an error. Tutorial

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

This is the full error:

这是完整的错误:

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'

Here are the first 10 lines on which the program goes wrong:

以下是程序出错的前 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)))

The code is located in the file convnet.py and I run the file like this: python convnet.py

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

回答by Fábio Perez

You are probably using an old version of Keras that had the following signature:

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

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

With this old version, you would define the conv layer as:

使用这个旧版本,您可以将 conv 层定义为:

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

You can check the version you are using with:

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

import keras
print(keras.__version__)

I suggest that you update your Keras.

我建议你更新你的 Keras。