我正在为特定汽车发动机部件的 7 种不同模型类型训练图像分类器。每个类别都有 308 张灰度图像,分辨率均为 1014x760。这些图像包括
我正在为特定汽车发动机部件的 7 种不同模型类型训练图像分类器。每个类别都有 308 张灰度图像,分辨率均为 1014x760。这些图像主要由白色屏幕上的发动机部件组成,每次拍摄后都会旋转 60 度,因此数据集由看起来彼此非常相似的图片组成。我想训练我的模型 50 个 epoch,但在第 30 个 epoch 之后,准确率达到 1.0,而验证准确率停留在 0.2 左右。为什么结果这么奇怪?可能是因为这些图像彼此太相似了?
import numpy as np
import pickle
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
from tensorflow.keras.callbacks import TensorBoard
from tensorflow.keras.utils import to_categorical
import time
name = "Core_Classifier_{}".format(int(time.time()))
tensorboard = TensorBoard(log_dir="logs/{}".format(name))
X = pickle.load(open("X.pickle", "rb"))
y = pickle.load(open("y.pickle", "rb"))
X = X/255.0 # normalize color values
y = to_categorical(y, num_classes=7)
model = Sequential()
model.add(Conv2D(64, (3, 3), input_shape = X.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Flatten())
model.add(Dense(64))
model.add(Activation("relu")) # idk if needed
model.add(Dense(7))
model.add(Activation("softmax"))
model.compile(loss = "categorical_crossentropy",
optimizer = "adam",
metrics = ["accuracy"])
model.fit(X, y, batch_size = 64, epochs = 50, validation_split = 0.1, callbacks = [tensorboard])
以下是通过 tensorboard 表示的图形
我添加了 2 个 model.add(Dropout(0.2)) 函数,但结果并没有太大变化。
import numpy as np
import pickle
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
from tensorflow.keras.callbacks import TensorBoard
from tensorflow.keras.utils import to_categorical
import time
name = "Core_Classifier_{}".format(int(time.time()))
tensorboard = TensorBoard(log_dir="logs/{}".format(name))
X = pickle.load(open("X.pickle", "rb"))
y = pickle.load(open("y.pickle", "rb"))
X = X/255.0 # normalize color values
y = to_categorical(y, num_classes=7)
model = Sequential()
model.add(Conv2D(64, (3, 3), input_shape = X.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Dropout(0.2))
model.add(Conv2D(64, (3, 3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(64))
model.add(Activation("relu")) # idk if needed
model.add(Dense(7))
model.add(Activation("softmax"))
model.compile(loss = "categorical_crossentropy",
optimizer = "adam",
metrics = ["accuracy"])
model.fit(X, y, batch_size = 64, epochs = 50, validation_split = 0.1, callbacks = [tensorboard])
使用 dropout 函数反馈训练结果