Skip to content

Commit 784c292

Browse files
Dhull442sglvladi
authored andcommitted
Update training.rst
Adding option for multiple labels in images. Also the import object_detection.utils is working now. Added img_path flag to the file. Removed all errors.
1 parent d20150e commit 784c292

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

docs/source/training.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ Now that we have obtained our ``*.csv`` annotation files, we will need to conver
296296
import io
297297
import pandas as pd
298298
import tensorflow as tf
299-
299+
import sys
300+
sys.path.append("../../models/research")
301+
300302
from PIL import Image
301303
from object_detection.utils import dataset_util
302304
from collections import namedtuple, OrderedDict
@@ -305,13 +307,24 @@ Now that we have obtained our ``*.csv`` annotation files, we will need to conver
305307
flags.DEFINE_string('csv_input', '', 'Path to the CSV input')
306308
flags.DEFINE_string('output_path', '', 'Path to output TFRecord')
307309
flags.DEFINE_string('label', '', 'Name of class label')
310+
# if your image has more labels input them as
311+
# flags.DEFINE_string('label0', '', 'Name of class[0] label')
312+
# flags.DEFINE_string('label1', '', 'Name of class[1] label')
313+
# and so on.
314+
flags.DEFINE_string('img_path', '', 'Path to images')
308315
FLAGS = flags.FLAGS
309316
310317
311318
# TO-DO replace this with label map
319+
# for multiple labels add more else if statements
312320
def class_text_to_int(row_label):
313321
if row_label == FLAGS.label: # 'ship':
314322
return 1
323+
# comment upper if statement and uncomment these statements for multiple labelling
324+
# if row_label == FLAGS.label0:
325+
# return 1
326+
# elif row_label == FLAGS.label1:
327+
# return 0
315328
else:
316329
None
317330
@@ -331,6 +344,7 @@ Now that we have obtained our ``*.csv`` annotation files, we will need to conver
331344
332345
filename = group.filename.encode('utf8')
333346
image_format = b'jpg'
347+
# check if the image format is matching with your images.
334348
xmins = []
335349
xmaxs = []
336350
ymins = []
@@ -365,7 +379,7 @@ Now that we have obtained our ``*.csv`` annotation files, we will need to conver
365379
366380
def main(_):
367381
writer = tf.python_io.TFRecordWriter(FLAGS.output_path)
368-
path = os.path.join(os.getcwd(), 'images')
382+
path = os.path.join(os.getcwd(), FLAGS.img_path)
369383
examples = pd.read_csv(FLAGS.csv_input)
370384
grouped = split(examples, 'filename')
371385
for group in grouped:
@@ -387,11 +401,11 @@ Now that we have obtained our ``*.csv`` annotation files, we will need to conver
387401
388402
# Create train data:
389403
python generate_tfrecord.py --label=<LABEL> --csv_input=<PATH_TO_ANNOTATIONS_FOLDER>/train_labels.csv
390-
--img_path=<PATH_TO_IMAGES_FOLDER> --output_path=<PATH_TO_ANNOTATIONS_FOLDER>/train.record
404+
--img_path=<PATH_TO_IMAGES_FOLDER>/train --output_path=<PATH_TO_ANNOTATIONS_FOLDER>/train.record
391405
392406
# Create test data:
393407
python generate_tfrecord.py --label=<LABEL> --csv_input=<PATH_TO_ANNOTATIONS_FOLDER>/test_labels.csv
394-
--img_path=<PATH_TO_IMAGES_FOLDER>
408+
--img_path=<PATH_TO_IMAGES_FOLDER>/test
395409
--output_path=<PATH_TO_ANNOTATIONS_FOLDER>/test.record
396410
397411
# For example

0 commit comments

Comments
 (0)