Skip to content

Commit 5cf5cca

Browse files
committed
cleanup
1 parent 9bfe7fa commit 5cf5cca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+30
-18
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

supporting_scripts/create_mask_rcnn_tf_record.py

+30-18
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515

16-
r"""Convert your custom dataset to TFRecord for object_detection.
16+
r"""
17+
Convert your custom dataset to TFRecord for object_detection.
1718
18-
Base of this script is create_pet_tf_record.py
19-
provided by tensorflow repository on github
20-
create_pet_tf_record.py could be found under
21-
tensorflow/models/research/object_detection/dataset_tools
19+
Base of this script is create_pet_tf_record.py provided by tensorflow repository on github
20+
create_pet_tf_record.py could be found under tensorflow/models/research/object_detection/dataset_tools
2221
23-
Example usage:
22+
Minimal Example usage:
2423
Python object_detection/dataset_tools/create_mask_rcnn_tf_record.py
2524
--data_dir_path=<path to directory containing dataset>
26-
--use_xmls=<true if you are providing bounding box annoations as xml file>
27-
--num_shrads=<number of tfrecord file in which you want to split your data>
25+
--bboxes_provided=<True if you are providing bounding box annoations as xml file>
2826
"""
2927

3028
import hashlib
3129
import io
3230
import logging
3331
import os
32+
import sys
3433

3534
import contextlib2
3635
import numpy as np
@@ -42,10 +41,19 @@
4241
from object_detection.utils import dataset_util
4342
from object_detection.utils import label_map_util
4443

44+
4545
flags = tf.app.flags
4646
flags.DEFINE_string('data_dir_path', '', 'Path to root directory to dataset.')
47-
flags.DEFINE_bool('use_xmls', True,
47+
flags.DEFINE_bool('bboxes_provided', None,
4848
'True if xmls with bouding box is provided')
49+
flags.DEFINE_string('images_dir', 'train_images',
50+
'Name of directory containing images')
51+
flags.DEFINE_string('masks_dir', 'train_masks',
52+
'Name of directory containing masks corresponding to images')
53+
flags.DEFINE_string('bboxes_dir', 'train_bboxes',
54+
'Name of directory containing bboxes annotations corresponding to images')
55+
flags.DEFINE_string('tfrecord_filename', 'train_data',
56+
'Name of the generated TFRecord file')
4957
flags.DEFINE_integer('num_shards', 1, 'Number of TFRecord shards')
5058
FLAGS = flags.FLAGS
5159

@@ -61,12 +69,11 @@ def image_to_tf_data(img_path,
6169
then xmls files with bounding box annotation need to be provided
6270
6371
Args:
64-
img_path: String specifying subdirectory within the
65-
dataset directory holding the actual image data.
72+
img_path: String specifying subdirectory within the dataset directory holding the actual image data.
6673
mask_path: String path to PNG encoded mask.
6774
xml_path: String path to XML file holding bounding box annotations
6875
label_map_dict: A map from string label names to integers ids.
69-
filename: name of the image
76+
filename: Name of the image
7077
7178
Returns:
7279
example: The converted tf.tf_data
@@ -101,7 +108,7 @@ def image_to_tf_data(img_path,
101108
ymaxs = []
102109
encoded_mask_png_list = []
103110

104-
if(True == FLAGS.use_xmls):
111+
if(True == FLAGS.bboxes_provided):
105112
if not os.path.exists(xml_path):
106113
logging.warning('Could not find %s, ignoring example.', xml_path)
107114
return
@@ -233,7 +240,12 @@ def create_tf_record(label_map_dict,
233240

234241

235242
def main(_):
236-
logging.basicConfig(format='%(levelname)s-%(message)s')
243+
# force to pass bboxes_provided flag
244+
if FLAGS.bboxes_provided == None:
245+
print("ERROR: Please set bboxes_provided flag to True or False")
246+
print("INFO: use xmls flag helps the program know if xmls file bounding boxes annotations is provided or not")
247+
sys.exit()
248+
237249
# read label mapping
238250
print('INFO: Reading label mapping')
239251
label_map_dict_path = os.path.join(FLAGS.data_dir_path, 'label.pbtxt')
@@ -247,10 +259,10 @@ def main(_):
247259

248260
# create tfrecord of data
249261
create_tf_record(label_map_dict,
250-
'train_images',
251-
'masks',
252-
'bboxes',
253-
'train_data')
262+
FLAGS.images_dir,
263+
FLAGS.masks_dir,
264+
FLAGS.bboxes_dir,
265+
FLAGS.tfrecord_filename)
254266

255267

256268
if __name__ == '__main__':

0 commit comments

Comments
 (0)