【发布时间】:2020-12-17 11:43:58
【问题描述】:
我使用的是 YOLO V3,我的数据集是 RGB 图像,但是我想在同一数据集的灰度版本上训练网络。所以我的问题是 YOLO v3 中是否有任何方法可以将我的 RGB 数据集自动转换为灰度进行训练,或者我必须首先将我的数据集从 RGB 转换为灰度然后馈送到网络?或者是否可以使用 OpenCV 或任何其他库进行任何预处理或转换?
【问题讨论】:
我使用的是 YOLO V3,我的数据集是 RGB 图像,但是我想在同一数据集的灰度版本上训练网络。所以我的问题是 YOLO v3 中是否有任何方法可以将我的 RGB 数据集自动转换为灰度进行训练,或者我必须首先将我的数据集从 RGB 转换为灰度然后馈送到网络?或者是否可以使用 OpenCV 或任何其他库进行任何预处理或转换?
【问题讨论】:
如果您已经有灰度数据集,我认为在 cfg 文件中设置 channels=1 会起作用。
根据这个问题:https://github.com/AlexeyAB/darknet/issues/3201,如果你想对灰度图像进行推理(检测),你必须使用灰度数据集训练你的模型。因此,使用 opencv 进行预处理可能是最简单的:cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
【讨论】:
你必须先写一个程序,内容如下:( 它可以帮助您完成从RBG和BGR颜色空间到灰度空间的转换)
import cv2
import os
path1 = 'Path to your training data'
path2 = 'Path to output grayscale map'
file_list = os.listdir(path1)#Traverse all the files in the folder into a list
for file in file_list:
if file.endswith('.jpg'):#Iterate through all files with the name'file_list' with the extension name'jpg'
img = cv2.imread(path1+file)#Read the image just traversed and save it as a variable named'img'
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#Use the cvtColor('original image', convert from RBG and BGR color space to gray space)method of the cv2 library to convert the original image named'img' into a grayscale image and save it as a variable named'gray'
cv2.imwrite(path2+file,gray)#Use the imwrite ('stored target path', variable named'gray') method of the cv2 library to write to the target path
print(file+'Conversion completed')
这样你就能得到你想要的结果
【讨论】: