我是机器学习和深度学习的新手,为了学习目的,我尝试使用Resnet.我试图过度填充小数据(3个不同的图像),看看我是否可以获得几乎0的损失和1.0的准确度 - 我做到了.
问题是对训练图像的预测(即用于训练的相同3个图像)不正确.
训练图像
图像标签
[1,0,0],[0,1,0],[0,0,1]
我的python代码
#loading 3 images and resizing them
imgs = np.array([np.array(Image.open("./Images/train/" + fname)
.resize((197, 197), Image.ANTIALIAS)) for fname in
os.listdir("./Images/train/")]).reshape(-1,197,197,1)
# creating labels
y = np.array([[1,0,0],[0,1,0],[0,0,1]])
# create resnet model
model = ResNet50(input_shape=(197, 197,1),classes=3,weights=None)
# compile & fit model
model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['acc'])
model.fit(imgs,y,epochs=5,shuffle=True)
# predict on training data
print(model.predict(imgs))
Run Code Online (Sandbox Code Playgroud)
该模型过度拟合数据:
3/3 [==============================] - 22s - loss: 1.3229 - acc: 0.0000e+00
Epoch 2/5
3/3 [==============================] - 0s - …Run Code Online (Sandbox Code Playgroud)