最近学习复现Faster_Rcnn,复现后用自己的数据集训练时出现以下的问题。
问题1:'NoneType' object has no attribute 'shape'
环境:python3.5 +tensorflow1.1.0+ Keras2.0.3
问题:使用cv2.imread读取含有中文路径的图片时,返回None。
原因: opencv不接受non-ascii的路径。
解决方法: 先用np.fromfile()读取为np.uint8格式,再使用cv2.imdecode()解码。
其中在使用cv2.imdecode()解码时需要注意输入参数的意义,否者会图像的通道可能会出问题,具体参数含义如下
cv2.imdecode(buf, flags)
# buf - Input array or vector of bytes.
# flags - The same flags as in cv2.imread().
# - >0 Return a 3-channel color image.
# - =0 Return a grayscale image.
# - <0 Return the loaded image as is (with alpha channel).
问题代码:
filepath=r'E:文件1.jpg'
img = cv2.imread(filepath) #如果路径有中文,则会返回none
修改后的代码:
img = cv2.imdecode(np.fromfile(filepath, dtype=np.uint8), 1) # 1>0 代表3通道
参考:
opencv-python读取中文路径,cv2.imdecode()_Python_两个轮子的博客-CSDN博客blog.csdn.net![8d2786a16e0b6e26268e16d2cbc865a3.png](https://i-blog.csdnimg.cn/blog_migrate/bfd8a2d1f2a343f1e586a188ad37edce.jpeg)
问题2: no element found:line 1,colum 0
![4f4c280cf457fbc81e711207f8299ef1.png](https://i-blog.csdnimg.cn/blog_migrate/c24aa3eca4d7588e2b9d5c080875cd91.png)
原因:在做vocal数据集时,先做空的xml,然后再写数据,造成有些xml是空文件,才出现如图问题
解决思路来源:
https://stackoverflow.com/questions/56724590/parseerror-no-element-found-line-1-column-0stackoverflow.comThat error message suggests that a non-XML file is being parsed as XML. Check the list of files you're processing. An empty file can trigger that error as well.
如有问题,欢迎指正