'Tensor'对象没有属性'lower'

37

我正在对一个MobileNet进行微调,加入了14个新类别。当我通过以下方式添加新层:

x=mobile.layers[-6].output
x=Flatten(x)
predictions = Dense(14, activation='softmax')(x)
model = Model(inputs=mobile.input, outputs=predictions)

我遇到了错误:

'Tensor' object has no attribute 'lower'

同时也使用:

model.compile(Adam(lr=.0001), loss='categorical_crossentropy', metrics=['accuracy'])
model.fit_generator(train_batches, steps_per_epoch=18,
                validation_data=valid_batches, validation_steps=3, epochs=60, verbose=2)

我收到了错误信息:

Error when checking target: expected dense_1 to have 4 dimensions, but got array with shape (10, 14)

“lower”是什么意思?我看到其他微调脚本,除了模型名称(在这种情况下为x)之外,没有其他参数。

1个回答

74

当您调用层时,必须将张量传递给该层,而不是作为参数传递。因此,应该像这样:

x = Flatten()(x)  # first the layer is constructed and then it is called on x

为了更清晰明确,它等同于这个:

flatten_layer = Flatten()  # instantiate the layer
x = flatten_layer(x)       # call it on the given tensor

我将代码转移到了Jupyter Notebook并发现了错误。我之前使用的是VS Code,但错误信息过于模糊。谢谢。 - Shiro Mier

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接