Skip to content

Commit

Permalink
Fix to_tensorflow bugs
Browse files Browse the repository at this point in the history
This patch fixes 2 to_tensorflow bugs
1. to_tensorflow fails when the meta information for a tensor includes
dtype="object"
2. to_tensorflow also fails when it gets shape=(1,) in meta and the
actual object has multiple dimensions

Signed-off-by: Aditya Srivastava <adityasrivastava301199@gmail.com>
  • Loading branch information
ADI10HERO committed Oct 26, 2020
1 parent 77f54b4 commit b56a9a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions examples/coco/upload_coco2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ def __init__(self, args, tag):

def meta(self):
return {
"segmentation": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"area": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"iscrowd": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"segmentation": {"shape": (1,), "dtype": "uint32", "chunksize": 1000},
"area": {"shape": (1,), "dtype": "uint32", "chunksize": 1000},
"iscrowd": {"shape": (1,), "dtype": "uint8", "chunksize": 1000},
"image_id": {"shape": (1,), "dtype": "int64"},
"bbox": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"category_id": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"id": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"image": {"shape": (1,), "dtype": "object", "chunksize": 100},
"bbox": {"shape": (1,), "dtype": "uint16", "chunksize": 1000},
"category_id": {"shape": (1,), "dtype": "uint32", "chunksize": 1000},
"id": {"shape": (1,), "dtype": "uint32", "chunksize": 1000},
"image": {"shape": (1,), "dtype": "uint32", "chunksize": 100},
}

def __call__(self, input):
Expand All @@ -36,21 +36,22 @@ def __call__(self, input):
# print(f"Image id: {input['image_id']}")
ds["image_id"] = input["image_id"]
info = input["info"]
ds["image"] = np.empty(1, object)
ds["image"] = np.empty(1, "uint32")
ds["image"][0] = np.array(
Image.open(
os.path.join(
self._args.dataset_path,
get_image_name(self._args, self._tag, input["image_id"]),
)
)
),
dtype="uint32",
)
ds["segmentation"] = np.empty(1, object)
ds["area"] = np.empty(1, object)
ds["iscrowd"] = np.empty(1, object)
ds["bbox"] = np.empty(1, object)
ds["category_id"] = np.empty(1, object)
ds["id"] = np.empty(1, object)
ds["segmentation"] = np.empty(1, "uint32")
ds["area"] = np.empty(1, "uint32")
ds["iscrowd"] = np.empty(1, "uint8")
ds["bbox"] = np.empty(1, "uint16")
ds["category_id"] = np.empty(1, "uint32")
ds["id"] = np.empty(1, "uint32")

ds["segmentation"][0] = [anno["segmentation"] for anno in info]
ds["area"][0] = [anno["area"] for anno in info]
Expand Down
2 changes: 1 addition & 1 deletion hub/collections/dataset/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def tf_dtype(np_dtype):
return tf.data.Dataset.from_generator(
tf_gen,
output_types=output_types,
output_shapes=output_shapes,
# output_shapes=output_shapes,
)


Expand Down

0 comments on commit b56a9a3

Please sign in to comment.