Skip to content

Commit

Permalink
adding template library.
Browse files Browse the repository at this point in the history
  • Loading branch information
ouyanglinke authored and HanxSmile committed Apr 10, 2023
1 parent a2b4e26 commit a3f93e5
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 10 deletions.
36 changes: 26 additions & 10 deletions dsdl/converter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@
from skimage import measure
from pycocotools import mask as mask_util
import xml.etree.ElementTree as ET
import shutil

DSDL_TASK_NAMES_TEMPLATE = {
"Image Classification": "class_template",
"Object Detection": "detection_template",
"Semantic Segmentation": None,
"Instance Segmentation": None,
"Panoptic Segmentation": None,
"Keypoint Detection": None,
"Multi-Object Tracking": None,
"Single-Object Tracking": None,
"Image Classification": "Image_Classification-template.yam",
"Object Detection": "Object_Detection-template.yaml",
"Semantic Segmentation": "Semantic_Segmentation-template.yaml",
"Instance Segmentation-segmap": "Instance_Segmentation_segmap-template.yaml",
"Instance Segmentation-polygon": "Instance_Segmentation_polygon-template",
"Panoptic Segmentation": "Panoptic_Segmentation-template.yaml",
"Keypoint Detection": "Keypoint_Detection-template.yaml",
"Object Tracking": "Object_Tracking-template.yaml",
"Image Generation": None,
"Optical Character Recognition": None,
"Rotated Object Detection": None,
"Optical Character Recognition-detection": "OCR_detection-template.yaml",
"Optical Character Recognition-segmentation": "OCR_segmap-template.yaml",
"Optical Character Recognition-recognition": "OCR_recog-template.yaml",
"Optical Character Recognition-end_to_end": "OCR_end2end-template.yaml",
"Rotated Object Detection": "Rotated_Object_Detection-template.yaml",
}

DSDL_MODALITYS = ("Images", "Texts", "Videos", "Audio", "3D")
Expand Down Expand Up @@ -263,6 +267,18 @@ def generate_global_info(dsdl_root_path, class_info_list):
else:
print(f"The {global_info_path} already exists !")

def get_dsdl_template_from_lib(task_name, save_path):
template_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "dsdl_library")
print('__file__ is ', __file__)
try:
template_file = os.path.join(template_path, DSDL_TASK_NAMES_TEMPLATE[task_name])
except:
raise ValueError(f"The template of {task_name} not exists in library, the avaliable template list is {DSDL_TASK_NAMES_TEMPLATE.keys()}. Please check.")
save_path_p = Path(save_path)
save_defs_p = save_path_p.joinpath("defs")
if not os.path.exists(save_defs_p):
os.mkdir(save_defs_p)
shutil.copyfile(template_file, os.path.join(save_defs_p, "template.yaml"))

def get_dsdl_template_file_name(dsdl_root_path):
save_path_p = Path(dsdl_root_path)
Expand Down
9 changes: 9 additions & 0 deletions dsdl/dsdl_library/Image_Classification-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$dsdl-version: "0.5.0"

ClassificationSample:
$def: struct
$params: ['cdom']
$fields:
image: Image
label: Label[dom=$cdom]
$optional: ['label']
16 changes: 16 additions & 0 deletions dsdl/dsdl_library/Instance_Segmentation_polygon-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$dsdl-version: "0.5.0"

LocalInstanceEntry:
$def: struct
$params: ['cdom']
$fields:
label: Label[dom=$cdom]
bbox: BBox
polygon: Polygon

InstanceSegmentationSample:
$def: struct
$params: ['cdom']
$fields:
image: Image
instances: List[LocalInstanceEntry[cdom=$cdom]]
9 changes: 9 additions & 0 deletions dsdl/dsdl_library/Instance_Segmentation_segmap-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$dsdl-version: "0.5.0"

InstanceSegmentationSample:
$def: struct
$params: ['cdom']
$fields:
image: Image
instance_map: InsMap
semantic_map: LabelMap[dom=$cdom]
16 changes: 16 additions & 0 deletions dsdl/dsdl_library/Keypoint_Detection-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$dsdl-version: "0.5.0"

KeyPointLocalObject:
$def: struct
$params: ['cdom1', 'cdom2']
$fields:
keypoint: Keypoint[dom=$cdom2]
label: Label[dom=$cdom1]
$optional: ["label"]

KeyPointSample:
$def: struct
$params: ['cdom1', 'cdom2']
$fields:
image: Image
annotations: List[etype=LocalObjectEntry[cdom1=$cdom1, cdom2=$cdom2]]
7 changes: 7 additions & 0 deletions dsdl/dsdl_library/OCR_detection-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$dsdl-version: "0.5.0"

OCRSample:
$def: struct
$fields:
image: Image
instances: List[Bbox]
13 changes: 13 additions & 0 deletions dsdl/dsdl_library/OCR_end2end-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$dsdl-version: "0.5.0"

LocalInstanceEntry:
$def: struct
$fields:
location: Polygon/Bbox
text: Text

OCRSample:
$def: struct
$fields:
image: Image
instances: List[LocalInstanceEntry]
7 changes: 7 additions & 0 deletions dsdl/dsdl_library/OCR_recog-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$dsdl-version: "0.5.0"

OCRSample:
$def: struct
$fields:
word_image: Image
text: Text
14 changes: 14 additions & 0 deletions dsdl/dsdl_library/OCR_segmap-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$dsdl-version: "0.5.0"

SegClassDom:
$def: class_domain
classes:
- text

OCRSample:
$def: struct
$params: ["cdom"]
$fields:
image: Image
word_segmap: LabelMap[dom=$cdom]
chr_segmap: LabelMap[dom=$cdom]
15 changes: 15 additions & 0 deletions dsdl/dsdl_library/Object_Detection-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$dsdl-version: "0.5.0"

LocalObjectEntry:
$def: struct
$params: ['cdom']
$fields:
bbox: BBox
label: Label[dom=$cdom]

ObjectDetectionSample:
$def: struct
$params: ['cdom']
$fields:
image: Image
objects: List[LocalObjectEntry[cdom=$cdom]]
24 changes: 24 additions & 0 deletions dsdl/dsdl_library/Object_Tracking-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$dsdl-version: "0.5.0"

LocalObjectEntry:
$def: struct
$params: ["cdom"]
$fields:
instance_id: InstanceID
bbox: BBox
category: Label[dom=$cdom]

FrameSample:
$def: struct
$params: ["cdom"]
$fields:
frame_id: UniqueID
media_path: Image
objects: List[etype=LocalObjectEntry[cdom=$cdom]]

VideoFrame:
$def: struct
$params: ["cdom"]
$fields:
video_name: Str
videoframes: List[etype=FrameSample[cdom=$cdom]]
9 changes: 9 additions & 0 deletions dsdl/dsdl_library/Panoptic_Segmentation-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$dsdl-version: "0.5.0"

PanopticSegmentationSample:
$def: struct
$params: ['cdom']
$fields:
image: Image
instance_map: InsMap
semantic_map: LabelMap[dom=$cdom]
15 changes: 15 additions & 0 deletions dsdl/dsdl_library/Rotated_Object_Detection-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$dsdl-version: "0.5.0"

LocalObjectEntry:
$def: struct
$params: ['cdom']
$fields:
rbbox: RotatedBBox[mode="xyxy"]
label: Label[dom=$cdom]

OrientedObjectDetectionSample:
$def: struct
$params: ['cdom']
$fields:
image: Image
objects: List[LocalObjectEntry[cdom=$cdom]]
8 changes: 8 additions & 0 deletions dsdl/dsdl_library/Semantic_Segmentation-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$dsdl-version: "0.5.0"

SemanticSegmentationSample:
$def: struct
$params: ['cdom']
$fields:
image: Image
semantic_map: LabelMap[dom=$cdom]

0 comments on commit a3f93e5

Please sign in to comment.