Commit f98f000a authored by Zhichao Lu's avatar Zhichao Lu Committed by pkulzc
Browse files

Update create_pascal_tf_record.py and create_pet_tf_record.py

PiperOrigin-RevId: 192494267
parent 2151c447
...@@ -104,7 +104,7 @@ def dict_to_tf_example(data, ...@@ -104,7 +104,7 @@ def dict_to_tf_example(data,
truncated = [] truncated = []
poses = [] poses = []
difficult_obj = [] difficult_obj = []
if data.has_key('object'): if 'object' in data:
for obj in data['object']: for obj in data['object']:
difficult = bool(int(obj['difficult'])) difficult = bool(int(obj['difficult']))
if ignore_difficult_instances and difficult: if ignore_difficult_instances and difficult:
......
...@@ -136,35 +136,36 @@ def dict_to_tf_example(data, ...@@ -136,35 +136,36 @@ def dict_to_tf_example(data,
poses = [] poses = []
difficult_obj = [] difficult_obj = []
masks = [] masks = []
for obj in data['object']: if 'object' in data:
difficult = bool(int(obj['difficult'])) for obj in data['object']:
if ignore_difficult_instances and difficult: difficult = bool(int(obj['difficult']))
continue if ignore_difficult_instances and difficult:
difficult_obj.append(int(difficult)) continue
difficult_obj.append(int(difficult))
if faces_only:
xmin = float(obj['bndbox']['xmin']) if faces_only:
xmax = float(obj['bndbox']['xmax']) xmin = float(obj['bndbox']['xmin'])
ymin = float(obj['bndbox']['ymin']) xmax = float(obj['bndbox']['xmax'])
ymax = float(obj['bndbox']['ymax']) ymin = float(obj['bndbox']['ymin'])
else: ymax = float(obj['bndbox']['ymax'])
xmin = float(np.min(nonzero_x_indices)) else:
xmax = float(np.max(nonzero_x_indices)) xmin = float(np.min(nonzero_x_indices))
ymin = float(np.min(nonzero_y_indices)) xmax = float(np.max(nonzero_x_indices))
ymax = float(np.max(nonzero_y_indices)) ymin = float(np.min(nonzero_y_indices))
ymax = float(np.max(nonzero_y_indices))
xmins.append(xmin / width)
ymins.append(ymin / height) xmins.append(xmin / width)
xmaxs.append(xmax / width) ymins.append(ymin / height)
ymaxs.append(ymax / height) xmaxs.append(xmax / width)
class_name = get_class_name_from_filename(data['filename']) ymaxs.append(ymax / height)
classes_text.append(class_name.encode('utf8')) class_name = get_class_name_from_filename(data['filename'])
classes.append(label_map_dict[class_name]) classes_text.append(class_name.encode('utf8'))
truncated.append(int(obj['truncated'])) classes.append(label_map_dict[class_name])
poses.append(obj['pose'].encode('utf8')) truncated.append(int(obj['truncated']))
if not faces_only: poses.append(obj['pose'].encode('utf8'))
mask_remapped = (mask_np != 2).astype(np.uint8) if not faces_only:
masks.append(mask_remapped) mask_remapped = (mask_np != 2).astype(np.uint8)
masks.append(mask_remapped)
feature_dict = { feature_dict = {
'image/height': dataset_util.int64_feature(height), 'image/height': dataset_util.int64_feature(height),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment