python - TypeError: “NoneType” object is not callable in Google Colab
问题描述
I am trying to train my model using Keras and TensorFlow.
Code where I'm getting the error.
def build_model():
# define the model, use pre-trained weights for image_net
base_model = InceptionV3(input_shape=(resized_height, resized_width, num_channel), weights='imagenet', include_top=False, pooling='avg')
x = base_model.output
# x = Dense(100, activation='relu')(x)
# predictions = Dense(6, activation='sigmoid', name='final_classifier')(x)
# model = Model(inputs = base_model.input, outputs= predictions)
model = Sequential()
# # model.add(LSTM(1024, return_sequences=False, kernel_initializer='he_normal', dropout=0.15, recurrent_dropout=0.15, implementation=2))
model = Sequential()
model.add(Dense(1024, activation='relu', input_shape=(51200,)))(x)
model.add(Dropout(0.5))
model.add(Dense(512, activation='relu'))(x)
model.add(Dropout(0.5))
model.add(Dense(256, activation='relu'))(x)
model.add(Dropout(0.5))
model.add(Dense(128, activation='relu'))(x)
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))(x)
model.add(Dropout(0.5))
model.add(Dense(6, activation='softmax', name='final_classifier'))(x)
return model
Build and Run the Model
model = build_model()
model_checkpoint = ModelCheckpoint(weight_file, monitor='val_loss', save_weights_only=False, save_best_only=True)
num_workers = 2
model.compile(optimizer=Adam(lr=initial_lr), loss='categorical_crossentropy', metrics=['accuracy'])
callbacks = [model_checkpoint, reduce_lr_on_plateau, tensor_board]
labels = labels_all
partition = partition_dict
model.fit_generator(generator=DataGenSequence(labels, partition['train'], current_state='train'),
steps_per_epoch=100,
epochs = 200,
verbose=1,
workers = num_workers,
callbacks=callbacks,
shuffle=False,
# maz_queue_size=32,
validation_data=DataGenSequence(labels, partition['valid'], current_state='validation'),
validation_steps=5
)
ERROR
Note: I am suffering from this error , I can't solved it and advanced thanks who are try to solve it and comment here for sharing the answer
解决方案
Sequentail().add()
does not have a return value or if speaking in Python: return None wich is an object of the Type NoneType. So when you are calling like this: Sequential().add()(x)
you are calling the method .add()
from the class Sequential
and then you are trying to call its return value. This does not work since the return value is not a function but None
from the NoneType
.
推荐阅读
- solr - SOLR:facet.field 对字段中的每个单词的工作方式不同,如何将 facet.field 应用于整个字段句子?
- r - 给定组开始指示符,分配顺序组 ID
- python - TypeError: my_task() 接受 2 个位置参数,但给出了 3 个
- .net-core - .net 瞬态数据库上下文被过早处理
- python - 每次打开终端(Ubuntu 16.04)时都会出现“找不到命令'pew'”
- awk - 使用报告中的 awk 匹配文件路径
- java - 如何在 Android Studio 中运行纯 java 代码?
- python-3.x - 如何从 python 向 AppSync 发送 GraphQL 查询?
- react-native - 仅从平面列表中设置文本输入中的文本
- react-native - 如何在 const 模式下更改状态值?