使用VGG16预处理模型进行灰度图像的错误
我正在使用带有灰度图像的VGG16预训练模型进行手语检测。当我尝试运行型号。FIT命令时,我会收到以下错误。
澄清
我已经有图像作为RGB表格,但我想将它们用作灰度,以检查它们是否可以与灰度一起使用。原因是,使用彩色图像,我没有得到我期望的准确性。它的测试准确性仅为最大40%,并且在数据集中被过度拟合。
另外,这是我的模型命令
vgg = vgg = vgg16(input_shape = [128,128,128] + [3 ],weights ='imageNet',include_top = false)
这是我的模型
history = model.fit(
train_x,
train_y,
epochs=15,
validation_data=(test_x, test_y),
callbacks=[early_stop, checkpoint],
batch_size=32,shuffle=True)
。我是与预训练模型一起工作的新手。当我尝试使用3个频道的颜色图像运行代码时,我的模型正在变得过于拟合,而val_accuracy不会上升到40%以上,因此我想尝试尝试灰度图像,因为我添加了许多数据增强技术,但是准确性是准确性是不改善。当我很长一段时间以来,任何线索都受到欢迎。
I am working on sign language detection using VGG16 pre-trained model with grayscale images. When I am trying to run the model.fit command, I am getting the following error.
CLARIFICATION
I already have images as RGB form but I want to use them as grayscale to check if they would work with grayscale. The reason being, with color images, I am not getting the accuracy which I am expecting. It is having test accuracy of max 40% only and getting overfitted on dataset.
Also, this is my model command
vgg = VGG16(input_shape= [128, 128] + [3], weights='imagenet', include_top=False)
This is my model.fit command
history = model.fit(
train_x,
train_y,
epochs=15,
validation_data=(test_x, test_y),
callbacks=[early_stop, checkpoint],
batch_size=32,shuffle=True)
I am new to working with pre-trained models. When I am trying to run the code with color images with 3 channels, my model is getting into overfitting and val_accuracy doesn't rise above 40% so I want to give try the grayscale images as I have added many data augmentation techniques but accuracy is not improving. Any leads are welcomed as I am stuck into this for long time now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能想到的最简单的解决方案是将您的图像转换为RGB。您可以作为模型的一部分来执行此操作。
这将解决您的VGG问题。我还看到您缺少图像的最后一个维度。灰度中的图像预计将具有形状
[高度,宽度,1]
,但您只有[高度,宽度]
。您可以使用tf.expand_dims
:请注意,该解决方案在图中中求解问题,因此它可以在线运行。意思是,在运行时,您可以按照现在的方式完全相同的方式馈送数据(在形状
[128,128]
中,没有通道维度),并且它仍然可以在功能上工作。如果这是您在运行时的预期维度,那么将数据扔入模型之前,这将比操作数据更快。顺便说一句,鉴于VGG经过专门用于最佳颜色图像的培训,这都不是理想的选择。只是以为我应该加。
The simplest (and likely fastest) solution I can think of is to just convert your image to rgb. You can do this as part of your model.
This will fix your issue with VGG. I also see that you're missing the last dimensionality for your images. Images in grayscale are expected to be of shape
[height, width, 1]
, but you simply have[height, width]
. You can fix this usingtf.expand_dims
:Note that this solution solves the problem in the graph, so it runs online. Meaning, at runtime, you can feed data exactly the same way you have it now (in the shape
[128, 128]
, without a channels dimension) and it will still functionally work. If this is your expected dimensionality during runtime, this will be faster than manipulating your data before throwing it into the model.By the way, none of this is ideal, given that VGG was trained specifically to work best with color images. Just thought I should add that.
您为什么要过度拟合?
也许是出于不同的原因:
如何将灰度图像输入
vgg16
?用于使用
vgg16
,您需要输入3个通道图像。因此,您需要像下面的图像一样加入图像,以获取灰度的三个频道图像:训练示例
vgg16
在灰度映像上来自fastion> fashion_mnist
dataSet:输出:
Why are you getting overfitting?
Maybe for different reasons:
How can you input grayscale images to
VGG16
?For Using
VGG16
, you need to input 3 channels images. For this reason, you need to concatenate your images like below to get three channels images from grayscale:Example of training
VGG16
on grayscale images fromfashion_mnist
dataset:Output: