#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time: 2018/9/20
# @Author: xfLi
# ==============================================================================
r"""Convert raw COCO dataset to TFRecord for object_detection.
Please note that this tool creates sharded output files.
Example usage:
python create_coco_tf_record.py --logtostderr \
--train_image_dir="${TRAIN_IMAGE_DIR}" \
--val_image_dir="${VAL_IMAGE_DIR}" \
--test_image_dir="${TEST_IMAGE_DIR}" \
--train_annotations_file="${TRAIN_ANNOTATIONS_FILE}" \
--val_annotations_file="${VAL_ANNOTATIONS_FILE}" \
--testdev_annotations_file="${TESTDEV_ANNOTATIONS_FILE}" \
--output_dir="${OUTPUT_DIR}"
"""
#from __future__ import absolute_import
#from __future__ import division
#from __future__ import print_function
import io
import json
import os
import contextlib2
import numpy as np
import PIL.Image
import sys
sys.path.append('/home/workspace/tensorflow/detector')
import options as opt
from utils.label_dict import id_to_label_map
from pycocotools import mask
import tensorflow as tf
from utils.dataset_utils import label_map_util
flags = tf.app.flags
tf.flags.DEFINE_boolean('include_masks', False,
'Whether to include instance segmentations masks '
'(PNG encoded) in the result. default: False.')
tf.flags.DEFINE_string('train_image_dir', '',
'Training image directory.')
tf.flags.DEFINE_string('val_image_dir', '',
'Validation image directory.')
tf.flags.DEFINE_string('test_image_dir', '',
'Test image directory.')
tf.flags.DEFINE_string('train_annotations_file', '',
'Training annotations JSON file.')
tf.flags.DEFINE_string('val_annotations_file', '',
'Validation annotations JSON file.')
tf.flags.DEFINE_string('testdev_annotations_file', '',
'Test-dev annotations JSON file.')
tf.flags.DEFINE_string('output_dir', '/tmp/', 'Output data directory.')
FLAGS = flags.FLAGS
tf.logging.set_verbosity(tf.loggin
【COCO】coco数据集转化为tfrecord(目标检测)
最新推荐文章于 2024-08-13 16:25:59 发布
本文详细介绍了如何将COCO数据集转换为TensorFlow的TFRecord格式,用于目标检测任务。首先,文章讲解了COCO数据集的结构,然后阐述了TFRecord格式的重要性,接着提供了具体的转换步骤,包括解析COCO JSON标注文件,编码图像数据,以及写入TFRecord文件。最后,还给出了验证转换结果和使用转换后的数据进行训练的指南。
摘要由CSDN通过智能技术生成