1. 问题
yolov5(v6.0)训练自己数据集(VOC格式)时出现警告:libpng warning: iCCP: known incorrect sRGB profile
虽然不影响训练,但看起来不爽。
2.解决办法
把数据集里的‘.png’图片转为‘.jpg’.
同时也要将’.xml’里的文件名修改过来。
3 附录
以下是使用到的代码
‘.png’----->‘.jpg’
import os
import cv2
path="VOC/JPEGImages/"
# list all the files
files = os.listdir(path)
s=''
for filename in files:
portion = os.path.splitext(filename)
if portion[1] == ".png":
img = cv2.imread(path+s.join(portion))
print(path+s.join(portion))
newname = portion[0] + ".jpg"
cv2.imwrite(path+newname,img)
修改‘.xml里的文件名’
#修改xml里的filename
import os.path
import xml.dom.minidom
path = 'VOC2007/Annotations/'
files = os.listdir(path)
s = []
count = 0
for xmlFile in files:
if not os.path.isdir(xmlFile):
name1 = xmlFile.split('.')[0]
dom = xml.dom.minidom.parse(path + '/' + xmlFile)
root = dom.documentElement
newfilename = root.getElementsByTagName('filename')
newfilename[0].firstChild.data = name1 + '.jpg'
with open(os.path.join(path, xmlFile), 'w') as fh:
dom.writexml(fh)
print('写入name/pose OK!')
count = count + 1
在此,感谢提供参考的优快云博主们,由于时间有点久,忘记具体参考的是哪位大神的资料,因此不附链接了,再次表示感谢,希望以上内容对大家有所帮助!