tensorflow ssd执行tf_convert_dat报错ValueError: You must supply the dataset directory with --dataset_dir

错误一:

Traceback (most recent call last):
  File "D:/work/SSD-Tensorflow-master/tf_convert_data.py", line 63, in
    tf.app.run()
  File "C:\Users\11327\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\platform\app.py", line 125, in run
    _sys.exit(main(argv))
  File "D:/work/SSD-Tensorflow-master/tf_convert_data.py", line 53, in main
    raise ValueError('You must supply the dataset directory with --dataset_dir')
ValueError: You must supply the dataset directory with --dataset_dir

Process finished with exit code 1

win10 pycharm需要手动添加参数,添加参数后此错误解决。

参数:

--dataset_name=pascalvoc  #暂时不能改

--dataset_dir=./VOC2007/test/ #改为自己的目录

--output_name=voc_2007_train  #一般不需要改,特殊情况根据自己需要改名字

--output_dir=./tfrecords #根据自己执行目录

 然后又出了这个错误(以下)之前执行此文件也出过此错误:

 

错误二:

Converting image 1626/2008Traceback (most recent call last):
  File "D:/work/SSD-Tensorflow-master/tf_convert_data.py", line 63, in
    tf.app.run()
  File "C:\Users\11327\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\platform\app.py", line 125, in run
    _sys.exit(main(argv))
  File "D:/work/SSD-Tensorflow-master/tf_convert_data.py", line 58, in main
    pascalvoc_to_tfrecords.run(FLAGS.dataset_dir, FLAGS.output_dir, FLAGS.output_name)
  File "D:\work\SSD-Tensorflow-master\datasets\pascalvoc_to_tfrecords.py", line 218, in run
    _add_to_tfrecord(dataset_dir, img_name, tfrecord_writer)
  File "D:\work\SSD-Tensorflow-master\datasets\pascalvoc_to_tfrecords.py", line 177, in _add_to_tfrecord
    _process_image(dataset_dir, name)
  File "D:\work\SSD-Tensorflow-master\datasets\pascalvoc_to_tfrecords.py", line 116, in _process_image
    bboxes.append((float(bbox.find('ymin').text) / shape[0],
ZeroDivisionError: float division by zero

Process finished with exit code 1
解决:就是程序本身是没有错的,错的是图像,点开错误的标注文件,查看异常情况。

暂时删除第1626张图片,1626的错误过去了,然后到1697张图又是这个问题,把1698图删后又变成1697是这个问题。。。一直到1679,一直删一直是这个问题,气的牙痒痒~

解决方案:1按照网上参考修改:将这个:

bboxes.append((float(bbox.find('ymin').text) / shape[0],
                   float(bbox.find('xmin').text) / shape[1],
                   float(bbox.find('ymax').text) / shape[0],
                   float(bbox.find('xmax').text) / shape[1]
                   ))
   改为这个:
bboxes.append((max(float(bbox.find('ymin').text) / shape[0],0.0),
                   max(float(bbox.find('xmin').text) / shape[1],0.0),
                   min(float(bbox.find('ymax').text) / shape[0],1.0),
                   min(float(bbox.find('xmax').text) / shape[1],1.0)
                   ))

但是对于我来说不管用

2,清楚缓存,重启电脑,还是不管用。

3,最终查到是因为我标注集里删除了两张图片,图像集没有删除,读的第1697的图片其实是编号为1699的图像的数据,删除污点数据编号为1699的图片,重新编号。(谨慎重新编码)编号程序如下:

# -*- coding:utf8 -*-

import os
class BatchRename():
    '''
    批量重命名文件夹中的图片文件
    '''
    def __init__(self):
        # 我的图片文件夹路径horse
        self.path = 'D:/work/SSD-Tensorflow-master/VOC2007/test/JPEGImages'
    def rename(self):
        filelist = os.listdir(self.path)
        total_num = len(filelist)
        i = 1
        n = 6
        for item in filelist:
            if item.endswith('.xml'):
                n = 6 - len(str(i))
                src = os.path.join(os.path.abspath(self.path), item)
                dst = os.path.join(os.path.abspath(self.path), str(0) * n + str(i) + '.xml')
                try:
                    os.rename(src, dst)
                    print
                    'converting %s to %s ...' % (src, dst)
                    i = i + 1
                except:
                    continue
        print
        'total %d to rename & converted %d jpgs' % (total_num, i)

if __name__ == '__main__':
    demo = BatchRename()

    demo.rename()
#参考其他人的,挺好用不是自己写,具体是哪个csdn忘了

错误三:

Converting image 1697/2005Traceback (most recent call last):
  File "D:/work/SSD-Tensorflow-master/tf_convert_data.py", line 63, in 
    tf.app.run()
  File "C:\Users\11327\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\platform\app.py", line 125, in run
    _sys.exit(main(argv))
  File "D:/work/SSD-Tensorflow-master/tf_convert_data.py", line 58, in main
    pascalvoc_to_tfrecords.run(FLAGS.dataset_dir, FLAGS.output_dir, FLAGS.output_name)
  File "D:\work\SSD-Tensorflow-master\datasets\pascalvoc_to_tfrecords.py", line 227, in run
    _add_to_tfrecord(dataset_dir, img_name, tfrecord_writer)
  File "D:\work\SSD-Tensorflow-master\datasets\pascalvoc_to_tfrecords.py", line 186, in _add_to_tfrecord
    _process_image(dataset_dir, name)
  File "D:\work\SSD-Tensorflow-master\datasets\pascalvoc_to_tfrecords.py", line 83, in _process_image
    image_data=tf.gfile.FastGFile(filename, 'rb').read()
  File "C:\Users\11327\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\lib\io\file_io.py", line 125, in read
    self._preread_check()
  File "C:\Users\11327\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\lib\io\file_io.py", line 85, in _preread_check
    compat.as_bytes(self.__name), 1024 * 512, status)
  File "C:\Users\11327\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\errors_impl.py", line 519, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: NewRandomAccessFile failed to Create/Open: ./VOC2007/test/JPEGImages/001697.jpg : ϵͳ\udcd5Ҳ\udcbb\udcb5\udcbdָ\udcb6\udca8\udcb5\udcc4\udcceļ\udcfe\udca1\udca3
; No such file or directory

解决办法:

1,上述重新编码搞出的错误,一个xml标注文件如下。错误三是因为检测到的filname名字和文件名字不一样,因此导致错误。所以错误数据直接删除,xml文件和对应的图片都删除!


	JPEGImages
	001863.jpg
	D:\work\SSD-Tensorflow-master\VOC2007\test\JPEGImages\001863.jpg
	
		Unknown
	
	
		0
		0
		3
	
	0
	
		Photovoltaic
		Unspecified
		0
		0
		
			5
			26
			250
			216
		
	

2,错误二的原因是标注文件有错,如上述xml文件的宽高都为0,整个的图片大小是识别不出来的,所以会报错。方法也是直接删除,手动改这次能通过转换为tf格式的文件程序,但是测试还是污点图片,所以直接删除xml文件和对应的图片即可。

错误二说,删除图像后还是报错,且数字一直前移原因是,那个数字前面表示的是数据集里的第几张图,而不是图的编号,后面的数字是数据集总共的数据量。因此删除一张,错误的那个号会前移,因为删错了文件,总是在删除的后一张报错,真是难为菜鸟了~

你可能感兴趣的:(tensorflow ssd执行tf_convert_dat报错ValueError: You must supply the dataset directory with --dataset_dir)