[英]My ResNet transfer learning model is always stays 0.5 accuracy when training - What's wrong?
I am a student beginning study ML.我是一名开始学习 ML 的学生。 what i'm doing was using ResNet50 transfer-learning for simple classification with Keras.
我正在做的是使用 ResNet50 迁移学习与 Keras 进行简单分类。 the result output i want is just "face or not ( like this )".
我想要的结果输出只是“脸与否(像这样)”。 i really don't care about model's performance.
我真的不在乎模型的表现。 but my accuracy always stays 0.5 when training.
但训练时我的准确率始终保持在 0.5。 what's wrong with my code?
我的代码有什么问题? please help.
请帮忙。
data is like:数据是这样的:
X = face_images + animal_images # 10 face_images and 10 animal_images
# if image is face :1, else: 0
y = [[1]]* len(face_images) + [[0]] * len(animal_images)
X = np.array(X)
y = np.array(y)
print(X.shape, y.shape)
(30, 75, 75, 3) (30, 1)
my pre-trained model is:我的预训练模型是:
# pre-trained model
input_layer = layers.Input(shape=(75,75,3))
base_model = ResNet50(weights='imagenet',
input_tensor=input_layer,
include_top=False)
base_model.summary()
and transfer-model:和转移模型:
# transfer
# flatten last layer, and added dense layer
last_layer = base_model.output
flatten = layers.Flatten()(last_layer)
my_layer = layers.Dense(256, activation='relu')(flatten)
my_layer = layers.Dense(256, activation='relu')(my_layer)
output_layer = layers.Dense(1,activation='sigmoid')(my_layer)
# input_layer = layers.Input(shape="75,75,3")
model = Model(inputs=input_layer, outputs=output_layer)
model.summary()
and compiled with:并编译:
model.compile(loss='mse', optimizer='adam',metrics=['accuracy'])
print("model compile completed.")
result of history = model.fit(X_p, y, epochs=100, shuffle=True)
历史结果
history = model.fit(X_p, y, epochs=100, shuffle=True)
Epoch 1/100
1/1 [==============================] - 4s 4s/step - loss: 0.2589 - accuracy: 0.5000
Epoch 2/100
1/1 [==============================] - 1s 613ms/step - loss: 0.2570 - accuracy: 0.5000
Epoch 3/100
1/1 [==============================] - 1s 611ms/step - loss: 0.2553 - accuracy: 0.5000
Epoch 4/100
1/1 [==============================] - 1s 612ms/step - loss: 0.2538 - accuracy: 0.5000
Epoch 5/100
1/1 [==============================] - 1s 620ms/step - loss: 0.2526 - accuracy: 0.5000
Epoch 6/100
1/1 [==============================] - 1s 610ms/step - loss: 0.2516 - accuracy: 0.5000
.
.
.
Epoch 96/100
1/1 [==============================] - 1s 608ms/step - loss: 0.2500 - accuracy: 0.5000
Epoch 97/100
1/1 [==============================] - 1s 607ms/step - loss: 0.2500 - accuracy: 0.5000
Epoch 98/100
1/1 [==============================] - 1s 925ms/step - loss: 0.2500 - accuracy: 0.5000
Epoch 99/100
1/1 [==============================] - 1s 916ms/step - loss: 0.2500 - accuracy: 0.5000
Epoch 100/100
1/1 [==============================] - 1s 913ms/step - loss: 0.2500 - accuracy: 0.3333
I solved it:我解决了它:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.