“张量"对象没有属性“较低" [英] 'Tensor' object has no attribute 'lower'

查看:30
本文介绍了“张量"对象没有属性“较低"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 14 个新类对 MobileNet 进行微调.当我通过以下方式添加新图层时:

I am fine-tuning a MobileNet with 14 new classes. When I add new layers by:

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)之外没有其他参数.

What does lower mean? I saw other fine-tuning scripts and there were no other arguments other than the name of the model which is x in this case.

推荐答案

张量必须在调用时传递给层,而不是作为参数.因此它必须是这样的:

The tensor must be passed to the layer when you are calling it, and not as an argument. Therefore it must be like this:

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

为了更清楚,它等价于:

To make it more clear, it is equivalent to this:

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

这篇关于“张量"对象没有属性“较低"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆