Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

python - 'Tensor' object has no attribute 'lower'

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)

I get the error:

'Tensor' object has no attribute 'lower'

Also using:

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)

I get the error:

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...