Skip to content

Commit cab5c53

Browse files
authored
[feat] support semantic segmentation (#17)
1 parent 97bf74f commit cab5c53

File tree

15 files changed

+1121
-11
lines changed

15 files changed

+1121
-11
lines changed

cfgs/vision_model/default.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ mask_rcnn_X_101_32x8d_FPN_3x:
2626
weights: "weights/detectron2/COCO-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_3x/139653917/model_final_2d9806.pkl"
2727
splits : "fpn" #, "c2" or "r2"
2828

29+
panoptic_rcnn_R_101_FPN_3x:
30+
model_path_prefix: ${..model_root_path}
31+
cfg: "models/detectron2/configs/COCO-PanopticSegmentation/panoptic_fpn_R_101_3x.yaml"
32+
weights: "weights/detectron2/COCO-PanopticSegmentation/panoptic_fpn_R_101_3x/139514519/model_final_cafdb1.pkl"
33+
splits : "fpn"
34+
2935
jde_1088x608:
3036
model_path_prefix: ${..model_root_path}
3137
cfg: "models/Towards-Realtime-MOT/cfg/yolov3_1088x608.cfg"

compressai_vision/codecs/encdec_utils/png_yuv.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ def __call__(self, input: Dict, file_prefix: str):
7979
if len(file_names) > 1: # video
8080
# NOTE: using glob for now, should be more robust and look at skipped
8181
# NOTE: somewhat rigid pattern (lowercase png)
82-
filename_pattern = f"{str(Path(file_names[0]).parent)}/*.png"
82+
83+
parent = Path(file_names[0]).parent
84+
ext = next((e for e in ["*.png", "*.jpg"] if list(parent.glob(e))), None)
85+
filename_pattern = f"{parent}/{ext}"
86+
images_in_folder = len(list(parent.glob(ext)))
8387
nb_frames = input["last_frame"] - input["frame_skip"]
84-
images_in_folder = len(
85-
[file for file in Path(file_names[0]).parent.glob("*.png")]
86-
)
88+
8789
assert (
8890
images_in_folder == nb_frames
8991
), f"input folder contains {images_in_folder} images, {nb_frames} were expected"
@@ -302,7 +304,7 @@ def _determine_output_filename(self, output_file_prefix: str):
302304
cmd_suffix = ["-start_number", "0"]
303305
prefix = output_file_prefix.split("qp")[0]
304306
filename = f"{prefix}%03d.png"
305-
elif datacatalog in ["MPEGHIEVE"]:
307+
elif datacatalog in ["MPEGHIEVE", "PANDASET"]:
306308
cmd_suffix = ["-start_number", "0"]
307309
filename = f"%06d.png"
308310
elif datacatalog in ["MPEGTVDTRACKING"]:

compressai_vision/codecs/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"MPEGTVDTRACKING": (-4.722218990325928, 48.58344268798828),
4949
"MPEGHIEVE": (-1.0795, 11.8232),
5050
"SFUHW": (-17.8848, 16.69418),
51+
"PANDASET": (-30.0, 30.0),
5152
}
5253

5354

compressai_vision/datasets/image.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from pathlib import Path
3636
from typing import Dict, List
3737

38+
import numpy as np
3839
from detectron2.data import DatasetCatalog, MetadataCatalog
3940
from detectron2.data.common import DatasetFromList, MapDataset
4041
from detectron2.data.dataset_mapper import DatasetMapper
@@ -681,6 +682,80 @@ def get_min_max_across_tensors(self):
681682
return (minv, maxv)
682683

683684

685+
@register_datacatalog("PANDASET")
686+
class PANDASET(DataCatalog):
687+
"""Load an image folder database with Detectron2 Cfg. testing image samples
688+
and annotations are respectively stored in separate directories
689+
(Currently this class supports none of training related operation ):
690+
691+
.. code-block:: none
692+
- rootdir/
693+
- camera
694+
- front_camera
695+
- 00.jpg
696+
- 01.jpg
697+
- xx.jpg
698+
- annotations
699+
- xxxx.json TODO
700+
Args:
701+
root (string): root directory of the dataset
702+
703+
"""
704+
705+
def __init__(
706+
self,
707+
root,
708+
imgs_folder="camera/front_camera",
709+
annotation_file=None,
710+
seqinfo="seqinfo.ini",
711+
dataset_name="pandaset",
712+
ext="jpg",
713+
):
714+
super().__init__(
715+
root,
716+
imgs_folder=imgs_folder,
717+
annotation_file=annotation_file,
718+
seqinfo=seqinfo,
719+
dataset_name=dataset_name,
720+
ext=ext,
721+
)
722+
723+
img_lists = sorted(self.imgs_folder_path.glob(f"*.{ext}"))
724+
725+
# self.data_type = "mot"
726+
# print(annotation_file)
727+
# seq_id = os.path.splitext(os.path.split(annotation_file)[1])[0]
728+
gt_frame_list = np.load(self.annotation_path, allow_pickle=True)[
729+
"gt"
730+
] # read_results(
731+
gt_frame_dict = {k: v for k, v in enumerate(gt_frame_list)}
732+
# str(self.annotation_path), self.data_type, is_gt=True
733+
# )
734+
735+
self._dataset = []
736+
self._gt_labels = gt_frame_dict
737+
# self._gt_ignore_labels = gt_ignore_frame_dict
738+
739+
for file_name in img_lists:
740+
img_id = file_name.name.split(f".{ext}")[0]
741+
742+
new_d = {
743+
"file_name": str(file_name),
744+
"image_id": img_id,
745+
"annotations": {
746+
"gt": gt_frame_dict.get(int(img_id), []),
747+
# "gt_ignore": gt_ignore_frame_dict.get(int(img_id), []),
748+
},
749+
}
750+
self._dataset.append(new_d)
751+
752+
def get_min_max_across_tensors(self):
753+
# FIXME
754+
minv = -30.0
755+
maxv = 30.0
756+
return (minv, maxv)
757+
758+
684759
@register_datacatalog("COCO")
685760
class COCO(DataCatalog):
686761
"""Load an image folder database with Detectron2 Cfg. testing image samples

compressai_vision/evaluators/base_evaluator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def get_coco_eval_info_name(name=None):
7373
# the not used input is intended to interface with the function computing class-wise peformance
7474
return "coco_instances_results.json"
7575

76+
@staticmethod
77+
def get_miou_eval_info_name(name):
78+
return f"SemanticSegmentationEval_on_PANDASET_{name}.json"
79+
7680
def reset(self):
7781
raise NotImplementedError
7882

0 commit comments

Comments
 (0)