Skip to content

Commit

Permalink
flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
ylabbe committed May 22, 2023
1 parent dcf1807 commit 58acf3b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
5 changes: 3 additions & 2 deletions bop_toolkit_lib/dataset/bop_imagewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
bop-imagewise is a format where the image annotations are stored
in individual files. This format is only used as an intermediate step
to convert a bop-scenewise dataset to a bop-webdataset.
to convert a bop-scenewise dataset to a bop-webdataset.
Format is the following:
├─ dataset
Expand All @@ -15,7 +15,8 @@
│ ├─ KEY.mask.json
│ ├─ KEY.mask_visib.json
... ,
where KEY is a unique identifier of an image in the dataset. Typically it is {scene_id:06d}_{image_id:06d}.
where KEY is a unique identifier of an image in the dataset.
Typically it is {scene_id:06d}_{image_id:06d}.
"""

import json
Expand Down
7 changes: 4 additions & 3 deletions bop_toolkit_lib/dataset/bop_scenewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def read_scene_infos(
and optionally:
- image_ids (list of image_ids for this scene)
- n_objects (number of object instances in the scene).
:param scene_dir: Path to the scene directory.
:param read_image_ids: Read list of image ids for this scene.
:param read_n_objects: Read number of objects in this scene.
Expand Down Expand Up @@ -125,7 +125,8 @@ def read_scene_infos(

assert (scene_dir / 'scene_camera.json').exists()
if read_image_ids:
scene_cameras = json.loads((scene_dir / 'scene_camera.json').read_text())
scene_cameras = json.loads(
(scene_dir / 'scene_camera.json').read_text())
image_ids = [int(k) for k in scene_cameras.keys()]
infos['image_ids'] = image_ids

Expand Down Expand Up @@ -249,7 +250,7 @@ def load_image_data(
gray_path = scene_dir / 'gray' / f'{image_id:06d}.tiff'
im_gray = inout.load_im(gray_path).astype(np.uint8)
image_data['im_gray'] = im_gray

if load_depth:
depth_path = scene_dir / 'depth' / f'{image_id:06d}.png'
im_depth = inout.load_im(depth_path).astype(np.float32)
Expand Down
18 changes: 10 additions & 8 deletions bop_toolkit_lib/dataset/bop_webdataset.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
Tools to manipulate bop-webdataset format
bop-webdataset is composed of several shards (a .tar file), each containing
amaximum of 1000 images. Because images and annotations are stored in a .tar file,
they can be read sequentially to achieve faster reading speeds compared to the other
bop-webdataset is composed of several shards (a .tar file),
each containing amaximum of 1000 images. Because images and
annotations are stored in a .tar file,they can be read sequentially
to achieve faster reading speeds compared to the other
file formats.
├─ dataset
Expand All @@ -12,9 +13,9 @@
│ ├─ shard-000001.tar
│ ├─ ...
Each shard contains a chunk of the bop-imagewise format. The images are typically
stored after shuffling, to achieve random sampling of the dataset even if the data
is read sequentially. E.g.
Each shard contains a chunk of the bop-imagewise format.
The images are typically stored after shuffling, to achieve random
sampling of the dataset even if the data is read sequentially. E.g.
├─ shard-000000.tar
│ ├─ 00004_00015.rgb.jpg
Expand All @@ -32,8 +33,9 @@
The file key_to_shard.json maps an image key to the index of the shard
where it is stored. This can be used to read an individual image directly in a
.tar file, but beware that this may be slow because random access in a .tar file
where it is stored. This can be used to read an individual image
directly in a .tar file, but beware that this may be slow because
random access in a .tar file
requires to seek the correpsonding file in the entire byte sequence.
"""

Expand Down
2 changes: 1 addition & 1 deletion bop_toolkit_lib/dataset/convert_imagewise_to_webdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _file_path(ext):
rgb_name = 'rgb' + infos['rgb_suffix']
obj[rgb_name] = open(
_file_path(rgb_name), 'rb').read()

if infos['has_depth']:
obj['depth.png'] = open(
_file_path('depth.png'), 'rb').read()
Expand Down
3 changes: 2 additions & 1 deletion bop_toolkit_lib/dataset/convert_scenewise_to_imagewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def convert_scene_to_imagewise(
):
if scene_infos["has_" + im_modality]:
im_path = list(
(input_scene_dir / im_modality).glob(f"{image_id:06d}.*"))[0]
(input_scene_dir / im_modality
).glob(f"{image_id:06d}.*"))[0]
suffix = im_path.suffix
shutil.copy(
im_path,
Expand Down

0 comments on commit 58acf3b

Please sign in to comment.