简体   繁体   English

我不断收到错误 TypeError: 'Tensor' object is not callable

[英]I keep getting the error TypeError: 'Tensor' object is not callable

global_average_layer = keras.layers.GlobalAveragePooling2D()
feature_batch_average = global_average_layer(feature_batch)
print(feature_batch_average.shape)
flatten = keras.layers.Flatten()(base_model.layers[-1].output)
dense1 = keras.layers.Dense(256, activation = "relu")(flatten)
prediction_layer = keras.layers.Dense(3, activation = "softmax")(dense1)
x = base_model(inputs, training=False)
x = global_average_layer(x)
x = keras.layers.Dropout(0.5)(x)
outputs = prediction_layer(x)
model = keras.Model(inputs, outputs)
model.summary()

I keep getting TypeError: 'Tensor' object is not callable at the line outputs = prediction_layer(x) .我不断收到 TypeError: 'Tensor' object is not callable at line outputs = prediction_layer(x) Any clue what I may be doing wrong?任何线索我可能做错了什么?

Edit: Added a few more lines to make it clear what I am doing编辑:添加了几行以明确我在做什么

base_model = keras.applications.DenseNet121(input_shape=IMG_SHAPE,
                                               include_top=False,
                                               weights='imagenet')

image_batch, label_batch = next(iter(train_dataset))
feature_batch = base_model(image_batch)
global_average_layer = keras.layers.GlobalAveragePooling2D()
feature_batch_average = global_average_layer(feature_batch)
print(feature_batch_average.shape)
flatten = keras.layers.Flatten()(base_model.layers[-1].output)
dense1 = keras.layers.Dense(256, activation = "relu")(flatten)
prediction_layer = keras.layers.Dense(3, activation = "softmax")(dense1)
x = base_model(inputs, training=False)
x = global_average_layer(x)
x = keras.layers.Dropout(0.5)(x)
outputs = prediction_layer(x)
model = keras.Model(inputs, outputs)
model.summary()

prediction_layer , as mentioned on line 5, would be the output of the Dense layer, and hence be just a Tensor and not a layer. prediction_layer ,如第 5 行所述,将是Dense层的 output,因此只是Tensor而不是层。
You do not require the flatten layer on base_model.layers[-1].output , and can just do it on x .您不需要base_model.layers[-1].output上的展平层,只需在x上进行即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我不断收到 TypeError: 'int' object is not callable - I keep getting TypeError: 'int' object is not callable 在激活 function 中出现错误“TypeError: 'Tensor' object is not callable” - Getting an error in Activation function “TypeError: 'Tensor' object is not callable” 每次尝试运行此项目时,我都会收到“TypeError:'pygame.Surface'对象不可调用”错误 - I keep getting the "TypeError: 'pygame.Surface' object is not callable" error every time I try to run this project 我不断收到TypeError:'str'对象不可调用(python 2.7) - I keep getting TypeError: 'str' object is not callable (python 2.7) 尝试按照 python 中的教程进行操作,但我不断收到此错误 - istart = _int(start) TypeError: 'str' object is not callable - Trying to follow a tutorial in python and I keep getting this error - istart = _int(start) TypeError: 'str' object is not callable 不断收到TypeError:“列表”对象不可调用 - Keep getting TypeError: 'list' object is not callable TypeError: 'Tk' object is not callable 为什么我会收到此错误消息 - TypeError: 'Tk' object is not callable Why am i Getting this error message 我收到错误 TypeError: 'int' object is not callable - I'm getting the error TypeError: 'int' object is not callable 我不断收到这个错误,称为“框架对象不可调用” - I keep on getting this error called "frame object is not callable" 我不断收到 TypeError: 'str' object is not callable 我不知道如何修复它 - I keep getting TypeError: 'str' object is not callable and I am not sure how to fix it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM