【问题标题】:How to convert RGB input to grayscale for YOLO v3 Training?如何将 RGB 输入转换为 YOLO v3 训练的灰度?
【发布时间】:2020-12-17 11:43:58
【问题描述】:

我使用的是 YOLO V3,我的数据集是 RGB 图像,但是我想在同一数据集的灰度版本上训练网络。所以我的问题是 YOLO v3 中是否有任何方法可以将我的 RGB 数据集自动转换为灰度进行训练,或者我必须首先将我的数据集从 RGB 转换为灰度然后馈送到网络?或者是否可以使用 OpenCV 或任何其他库进行任何预处理或转换?

【问题讨论】:

    标签: rgb grayscale yolo


    【解决方案1】:

    如果您已经有灰度数据集,我认为在 cfg 文件中设置 channels=1 会起作用。

    根据这个问题:https://github.com/AlexeyAB/darknet/issues/3201,如果你想对灰度图像进行推理(检测),你必须使用灰度数据集训练你的模型。因此,使用 opencv 进行预处理可能是最简单的:cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    【讨论】:

      【解决方案2】:

      你必须先写一个程序,内容如下:( 它可以帮助您完成从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')
      

      这样你就能得到你想要的结果

      【讨论】:

      • 请描述一下你的代码,写一个如下内容的程序并不是真正的解决方案
      • 你好,@Abilogos 谢谢你的建议,因为我昨天刚加入stackoverflow,所以对这里的规则不熟悉。在提供其他人的建议时,我会更加注意。再次感谢您。
      猜你喜欢
      • 1970-01-01
      • 2020-04-29
      • 1970-01-01
      • 2010-10-15
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多