简体   繁体   English

我的 ResNet 迁移学习模型在训练时始终保持 0.5 准确度 - 怎么了?

[英]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:我解决了它:

  1. train images wasn't RGB火车图像不是 RGB
  2. 'preprocess_input' was imported by different cnn model not resnet 'preprocess_input' 是由不同的 cnn 模型而不是 resnet 导入的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Keras 模型不是训练层,验证准确率始终为 0.5 - Keras model not training layers, validation accuracy always 0.5 深度学习模型的验证精度停留在 0.5,而训练精度正在提高 - Validation accuracy of deep learning model is stuck at 0.5 whereas training accuracy is improving Tensorflow/Keras:训练期间的模型准确率始终为 0.5,输入大小与第一个官方教程不同 - Tensorflow/Keras: Model accuracy during training is always 0.5 with input size different from first official tutorial 使用转移学习进行物体检测的训练顺序模型期间,训练和验证准确性保持恒定 - Training and validation accuracy remains constant during training sequential model for object detection using transfer learning Model 在迁移学习期间收敛到 0.5 - Model converges to 0.5 during transfer learning 使用 Inception Resnet v2(乳腺癌)进行迁移学习,准确率低 - Transfer learning with Inception Resnet v2 (breast cancer) low accuracy 迁移学习 - 将我的顶层与预训练模型合并,将准确率降至 0% - Transfer Learning - Merging my top layers with pretrained model drops accuracy to 0% Inception Resnet v2 使用迁移学习测试准确率不佳 - Inception Resnet v2 bad test accuracy with transfer learning 我在所有机器学习模型上都获得了 100% 的准确率。 我的模型有什么问题 - I am getting a 100% accuracy on all my machine learning models. What is wrong with my model 如何提高我的迁移学习 BERT 的 model 的验证和测试的准确性 - How to improve an accuracy of validation and test of my model of Transfer Learning BERT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM