我正在用 14 个新类微调 MobileNet。当我通过以下方式添加新图层时:
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)
降低
是什么意思?我看到了其他微调脚本,除了在本例中为 x
的模型名称外,没有其他参数。
最佳答案
张量必须在调用层时传递给层,而不是作为参数。因此它必须是这样的:
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
关于python - “张量”对象没有属性 'lower',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53153790/