Python 从Tensorflow为对象检测教程创建我自己的数据集的问题

Python 从Tensorflow为对象检测教程创建我自己的数据集的问题,python,tensorflow,jupyter-notebook,object-detection,Python,Tensorflow,Jupyter Notebook,Object Detection,我正试图为tensorflow的对象检测教程构建自己的数据集,我的代码如下: import tensorflow as tf import os from PIL import Image from resizeimage import resizeimage from object_detection.utils import dataset_util flags = tf.app.flags flags.DEFINE_string('output_path', '', 'Path to o

我正试图为tensorflow的对象检测教程构建自己的数据集,我的代码如下:

import tensorflow as tf
import os
from PIL import Image
from resizeimage import resizeimage
from object_detection.utils import dataset_util

flags = tf.app.flags
flags.DEFINE_string('output_path', '', 'Path to output TFRecord')
FLAGS = flags.FLAGS

def create_tf_example(label_and_data_info):
    # TODO START: Populate the following variables from your example.
    height = 200 # Image height
    width = 200 # Image width
    filename = 'asc.0.jpg' # Filename of the image. Empty if image is not from file
    encoded_image_data = None # Encoded image bytes
    image_format = b'jpg' # b'jpeg' or b'png'

    xmins = [] # List of normalized left x coordinates in bounding box (1 per box)
    xmaxs = [] # List of normalized right x coordinates in bounding box
         # (1 per box)
    ymins = [] # List of normalized top y coordinates in bounding box (1 per box)
    ymaxs = [] # List of normalized bottom y coordinates in bounding box
         # (1 per box)
    classes_text = ['Ascaris'] # List of string class name of bounding box (1 per box)
    classes = [1] # List of integer class id of bounding box (1 per box)
    # TODO END
    tf_label_and_data = tf.train.Example(features=tf.train.Features(feature={
        'image/height': dataset_util.int64_feature(height),
        'image/width': dataset_util.int64_feature(width),
        'image/filename': dataset_util.bytes_feature(filename),
        'image/source_id': dataset_util.bytes_feature(filename),
        'image/encoded': dataset_util.bytes_feature(encoded_image_data),
        'image/format': dataset_util.bytes_feature(image_format),
        'image/object/bbox/xmin': dataset_util.float_list_feature(xmins),
        'image/object/bbox/xmax': dataset_util.float_list_feature(xmaxs),
        'image/object/bbox/ymin': dataset_util.float_list_feature(ymins),
        'image/object/bbox/ymax': dataset_util.float_list_feature(ymaxs),
        'image/object/class/text': dataset_util.bytes_list_feature(classes_text),
        'image/object/class/label': dataset_util.int64_list_feature(classes),
        }))
    return tf_label_and_data

def main(_):
    writer = tf.python_io.TFRecordWriter(FLAGS.output_path)

    # TODO START: Write code to read in your dataset to examples variable
    file_loc = 'NematodeConvImagesResimensionadas/train_images'
    all_data_and_label_info = LOAD(file_loc)
    # TODO END

    for data_and_label_info in all_data_and_label_info:
        tf_example = create_tf_example(data_and_label_info)
        writer.write(tf_example.SerializeToString())

    writer.close()

if __name__ == '__main__':
    tf.app.run()
但当我尝试运行脚本时,出现以下错误:

NotFoundError                             Traceback (most recent call last)
<ipython-input-4-658e1dd88560> in <module>()
      14 
      15 if __name__ == '__main__':
 ---> 16     tf.app.run()
/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py in run(main, argv)
      122   # Call the main function, passing through any arguments
      123   # to the final program.
 ---> 124   _sys.exit(main(argv))
      125 
      126 
<ipython-input-4-658e1dd88560> in main(_)
      1 def main(_):
----> 2     writer = tf.python_io.TFRecordWriter(FLAGS.output_path)
      3 
      4     # TODO START: Write code to read in your dataset to examples variable
      5     file_loc = 'NematodeConvImagesResimensionadas/train_images'
/usr/local/lib/python3.5/dist-packages/tensorflow/python/lib/io/tf_record.py in __init__(self, path, options)
      104     with errors.raise_exception_on_not_ok_status() as status:
      105       self._writer = pywrap_tensorflow.PyRecordWriter_New(
  --> 106           compat.as_bytes(path), compat.as_bytes(compression_type), status)
      107 
      108   def __enter__(self):
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors_impl.py in __exit__(self, type_arg, value_arg, traceback_arg)
      471             None, None,
      472             compat.as_text(c_api.TF_Message(self.status.status)),
  --> 473             c_api.TF_GetCode(self.status.status))
      474     # Delete the underlying status object from memory otherwise it stays alive
      475     # as there is a reference to status from this from the traceback due to

NotFoundError: ; No such file or directory
NotFoundError回溯(最近一次调用)
在()
14
15如果uuuu name uuuuuu=='\uuuuuuuuu main\uuuuuuuuuu':
--->16 tf.app.run()
/运行中的usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py(main,argv)
122#通过任何参数调用main函数
123#到最后的节目。
--->124 _系统出口(主(argv))
125
126
主要的
1个def干管(u3;):
---->2 writer=tf.python\u io.TFRecordWriter(FLAGS.output\u路径)
3.
4#TODO START:编写代码,将数据集中的数据读取到示例变量
5文件\u loc='NematedoVimagesResimensionadas/train\u images'
/usr/local/lib/python3.5/dist-packages/tensorflow/python/lib/io/tf_record.py in_u_init__;(self、path、options)
104有错误。将\u异常\u on \u not \u ok \u status()作为状态引发:
105 self.\u writer=pywrap\u tensorflow.PyRecordWriter\u New(
-->106兼容as_字节(路径),兼容as_字节(压缩类型),状态)
107
108定义输入(自我):
/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors\u impl.py in\uuuuuuuuu exit\uuuuuuuu(self、type\u arg、value\u arg、traceback\u arg)
没有,没有,
472 compat.as_text(c_api.TF_消息(self.status.status)),
-->473 c_api.TF_GetCode(self.status.status))
474#从内存中删除基础状态对象,否则它将保持活动状态
475#由于以下原因,在回溯中有一个状态参考:
NotFoundError:;没有这样的文件或目录

我不知道如何解决这个问题,我已经尝试更改我的图像路径,但它似乎仍然找不到目录。非常感谢您的帮助。

标志中的第二个参数。DEFINE_string('output_path','''path to output TFRecord')应指向您计算机上的输出文件夹。您将其留空。

调试看不见的代码并不容易。:-)@我很抱歉!我刚才添加了我的代码。
标志的值是多少。输出路径
?作为补充说明,您可能应该使用Python的
argsparse
而不是
tf.flags