更改训练数据集的长宽比和大小
我有一个 640x512 图像的训练数据集,我想将其与 320x240 相机一起使用。 是否可以将训练图像的长宽比和大小更改为相机的长宽比和大小? 升级相机画幅会更好吗?
I have a training dataset of 640x512 images that I would like to use with a 320x240 camera.
Is it ok to change the aspect ratio and the size of the training images to that of the camera?
Would it be better to upscale the camera frames?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好保持图像的纵横比,因为您将人为地修改图像中对象的组成。您可以将图像缩小 2 倍,使其大小为 320 x 256,然后从中心进行裁剪,得到 320 x 240 的图像。您可以通过简单地删除图像的前 8 列和最后 8 列来将其变为 320 x 240 来实现此目的。删除前 8 列和最后 8 列应该是安全的,因为您不太可能在 8 像素内看到有意义的信息图像两侧的带。
如果您使用的是 Tensorflow 或 PyTorch 等深度学习框架,有一些预处理方法可以自动让您从中心裁剪并将图像缩小 2 倍。您只需要设置一个预处理管道并将这两件事准备就绪。您尚未建立任何代码,因此我无法帮助您了解实现细节,但希望我所说的足以帮助您入门。
最后,不要对图像进行上采样。不会有任何好处,因为您将使用现有信息插值到不准确的更大空间。你可以缩小规模,但永远不能扩大规模。唯一有用的情况是您使用超分辨率,但这适用于特定情况,并且很大程度上取决于您使用的图像。一般来说,我不建议升级。将训练集缩小到相机的分辨率,因为相机中的图像将用于推理和该分辨率。
It is better if you keep the aspect ratio of the images because you will be artificially modifying the composition of the objects in the image. What you can do is downscale the image by a factor of 2, so it's 320 x 256, then crop from the center so you have a 320 x 240 image. You can do this by simply removing the first 8 and last 8 columns of the image to get it to 320 x 240. Removing the first 8 and last 8 columns should be safe because it is very unlikely you will see meaningful information within an 8 pixel band on either side of the image.
If you are using a deep learning framework such as Tensorflow or PyTorch, there are pre-processing methods to automatically allow you to crop from the center as well as downscale the image by a factor of 2 for you. You just need to set up a pre-processing pipeline and have these two things in place. You don't have any code established so I can't help you with implementation details, but hopefully what I've said is enough to get you started.
Finally, do not upsample the images. There will be no benefit because you will be using existing information to interpolate to a larger space which is inaccurate. You can scale down, but never scale up. The only situation where this could be useful is if you use superresolution, but that would be for specific cases and it highly depends on what images you use. In general, I do not recommend upscaling. Take your training set and downscale to the resolution of the camera as the images from the camera would be what is used at inference and at that resolution.