zerohertzLib.vision.loader ¶
Classes:
| Name | Description |
|---|---|
CocoLoader | COCO format의 dataset을 읽고 시각화하는 class |
ImageLoader | 경로와 image의 수를 지정하여 경로 내 image를 return하는 class |
JsonImageLoader | JSON file을 통해 image와 JSON file 내 정보를 불러오는 class |
YoloLoader | YOLO format의 dataset을 읽고 시각화하는 class |
CocoLoader ¶
CocoLoader(data_path: str, vis_path: str | None = None, class_color: dict[int | str, tuple[int, int, int]] | None = None)
COCO format의 dataset을 읽고 시각화하는 class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path | str | Image 및 annotation이 존재하는 directory 경로 | required |
vis_path | str | None | 시각화 image들이 저장될 경로 | None |
class_color | dict[int | str, tuple[int, int, int]] | None | 시각화 결과에 적용될 class에 따른 색상 | None |
Examples:
>>> data_path = "train"
>>> class_color = {"label1": (0, 255, 0), "label2": (255, 0, 0)}
>>> coco = zz.vision.CocoLoader(data_path, vis_path="tmp", class_color=class_color)
>>> image, class_list, bboxes, polys = coco(0, False, True)
>>> type(image)
<class 'str'>
>>> image
'{IMAGE_PATH}.jpg'
>>> class_list
[0, 1]
>>> type(bboxes)
<class 'numpy.ndarray'>
>>> bboxes.shape
(2, 4)
>>> image, class_list, bboxes, polys = coco[0]
>>> type(image)
<class 'numpy.ndarray'>
>>> class_list
['label1', 'label2']
>>> type(bboxes)
<class 'numpy.ndarray'>
>>> bboxes.shape
(2, 4)
>>> type(polys)
<class 'list'>
Methods:
| Name | Description |
|---|---|
__call__ | Index에 따른 image와 annotation에 대한 정보 return ( |
__getitem__ | Index에 따른 image와 annotation에 대한 정보 return ( |
__len__ | Image 수를 반환 |
yolo | COCO format을 YOLO format으로 변환 |
Attributes:
| Name | Type | Description |
|---|---|---|
annotations | | |
class_color | | |
classes | | |
data_path | | |
image2annotation | | |
images | | |
vis_path | |
Source code in zerohertzLib/vision/loader.py
__call__ ¶
__call__(idx: int, read: bool = False, int_class: bool = False) -> tuple[str | NDArray[uint8], list[int | str], NDArray[DTypeLike], list[NDArray[DTypeLike]]]
Index에 따른 image와 annotation에 대한 정보 return (vis_path 와 class_color 입력 시 시각화 image vis_path 에 저장)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx | int | 입력 index | required |
read | bool | Image 읽음 여부 | False |
int_class | bool | 출력될 class의 type 지정 | False |
Returns:
| Type | Description |
|---|---|
tuple[str | NDArray[uint8], list[int | str], NDArray[DTypeLike], list[NDArray[DTypeLike]]] | Image 경로 혹은 읽어온 image와 그에 따른 |
Source code in zerohertzLib/vision/loader.py
__getitem__ ¶
__getitem__(idx: int) -> tuple[NDArray[uint8], list[str], NDArray[DTypeLike], list[NDArray[DTypeLike]]]
Index에 따른 image와 annotation에 대한 정보 return (vis_path 와 class_color 입력 시 시각화 image vis_path 에 저장)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx | int | 입력 index | required |
Returns:
| Type | Description |
|---|---|
tuple[NDArray[uint8], list[str], NDArray[DTypeLike], list[NDArray[DTypeLike]]] | 읽어온 image와 그에 따른 |
Source code in zerohertzLib/vision/loader.py
_visualization ¶
_visualization(file_name: str, img: NDArray[uint8], class_list: list[str], bboxes: NDArray[DTypeLike], polys: list[NDArray[DTypeLike]]) -> None
Source code in zerohertzLib/vision/loader.py
yolo ¶
COCO format을 YOLO format으로 변환
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_path | str | YOLO format data가 저장될 경로 | required |
label | list[str] | None | COCO에서 사용한 label을 정수로 변환하는 list (index 사용) | None |
poly | bool | Segmentation format 유무 | False |
Returns:
| Type | Description |
|---|---|
None |
|
Examples:
>>> coco = zz.vision.CocoLoader(data_path)
>>> coco.yolo(target_path)
100%|█████████████| 476/476 [00:00<00:00, 78794.25it/s]
>>> label = ["label1", "label2"]
>>> cooc.yolo(target_path, label)
100%|█████████████| 476/476 [00:00<00:00, 78794.25it/s]
Source code in zerohertzLib/vision/loader.py
ImageLoader ¶
경로와 image의 수를 지정하여 경로 내 image를 return하는 class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Image들이 존재하는 경로 | './' |
cnt | int | 호출 시 return 할 image의 수 | 1 |
Attributes:
| Name | Type | Description |
|---|---|---|
image_paths | 지정한 경로 내 image들의 경로 |
Examples:
>>> il = zz.vision.ImageLoader()
>>> len(il)
510
>>> il[0][0]
'./1.2.410.200001.1.9999.1.20220513101953581.1.1.jpg'
>>> il[0][1].shape
(480, 640, 3)
>>> il = zz.vision.ImageLoader(cnt=4)
>>> len(il)
128
>>> il[0][0]
['./1.2.410.200001.1.9999.1.20220513101953581.1.1.jpg', '...', '...', '...']
>>> il[0][1][0].shape
(480, 640, 3)
>>> len(il[0][0])
4
>>> len(il[0][1])
4
Methods:
| Name | Description |
|---|---|
__getitem__ | Index에 따른 image 정보를 반환 |
__len__ | Image 수를 반환 |
Source code in zerohertzLib/vision/loader.py
__getitem__ ¶
Index에 따른 image 정보를 반환
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx | int | 입력 index | required |
Returns:
| Type | Description |
|---|---|
tuple[str, NDArray[uint8]] | tuple[list[str], list[NDArray[uint8]]] |
|
Source code in zerohertzLib/vision/loader.py
JsonImageLoader ¶
JSON file을 통해 image와 JSON file 내 정보를 불러오는 class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path | str | 목표 data가 존재하는 directory 경로 | required |
json_path | str | 목표 JSON file이 존재하는 directory 경로 | required |
json_key | str |
| required |
Attributes:
| Name | Type | Description |
|---|---|---|
json | JSON file들을 읽어 data 구축 시 활용 |
Examples:
>>> jil = zz.vision.JsonImageLoader(data_path, json_path, json_key)
100%|█████████████| 17248/17248 [00:04<00:00, 3581.22it/s]
>>> img, js = jil[10]
>>> img.shape
(600, 800, 3)
>>> js.tree()
└─ info
└─ name
└─ date_created
...
Methods:
| Name | Description |
|---|---|
__getitem__ | 읽어온 JSON file들을 list와 같이 indexing 후 해당하는 image return |
__len__ | Image 수를 반환 |
Source code in zerohertzLib/vision/loader.py
__getitem__ ¶
읽어온 JSON file들을 list와 같이 indexing 후 해당하는 image return
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx | int | 입력 index | required |
Returns:
| Type | Description |
|---|---|
tuple[NDArray[uint8], Json] | Image와 JSON 내 정보 |
Source code in zerohertzLib/vision/loader.py
YoloLoader ¶
YoloLoader(data_path: str = 'images', txt_path: str = 'labels', poly: bool = False, absolute: bool = False, vis_path: str | None = None, class_color: dict[int | str, tuple[int, int, int]] | None = None)
YOLO format의 dataset을 읽고 시각화하는 class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path | str | Image가 존재하는 directory 경로 | 'images' |
txt_path | str | YOLO format의 | 'labels' |
poly | bool |
| False |
absolute | bool |
| False |
vis_path | str | None | 시각화 image들이 저장될 경로 | None |
class_color | dict[int | str, tuple[int, int, int]] | None | 시각화 결과에 적용될 class에 따른 색상 | None |
Examples:
>>> data_path = ".../images"
>>> txt_path = ".../labels"
>>> class_color = {0: (0, 255, 0), 1: (255, 0, 0), 2: (0, 0, 255)}
>>> yolo = zz.vision.YoloLoader(data_path, txt_path, poly=True, absolute=False, vis_path="tmp", class_color=class_color)
>>> image, class_list, objects = yolo[0]
>>> type(image)
<class 'numpy.ndarray'>
>>> class_list
[1, 1]
>>> len(objects)
2
Methods:
| Name | Description |
|---|---|
__getitem__ | Index에 따른 image와 |
__len__ | Image 수를 반환 |
labelstudio | YOLO format의 data를 Label Studio에서 확인 및 수정할 수 있게 변환 |
Attributes:
| Name | Type | Description |
|---|---|---|
absolute | | |
class_color | | |
data_path | | |
data_paths | | |
poly | | |
txt_path | | |
vis_path | |
Source code in zerohertzLib/vision/loader.py
__getitem__ ¶
Index에 따른 image와 .txt file에 대한 정보 return (vis_path 와 class_color 입력 시 시각화 image vis_path 에 저장)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx | int | 입력 index | required |
Returns:
| Type | Description |
|---|---|
tuple[NDArray[uint8], list[int], list[NDArray[DTypeLike]]] | 읽어온 image와 그에 따른 |
Source code in zerohertzLib/vision/loader.py
_annotation ¶
Source code in zerohertzLib/vision/loader.py
_convert ¶
Source code in zerohertzLib/vision/loader.py
_value ¶
Source code in zerohertzLib/vision/loader.py
_visualization ¶
_visualization(file_name: str, img: NDArray[uint8], class_list: list[int], objects: list[NDArray[DTypeLike]]) -> None
Source code in zerohertzLib/vision/loader.py
labelstudio ¶
YOLO format의 data를 Label Studio에서 확인 및 수정할 수 있게 변환
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory | str | Label Studio 내 | 'image' |
labels | list[str | None] | YOLO format의 | None |
mp_num | int | 병렬 처리에 사용될 process의 수 ( | 0 |
Returns:
| Type | Description |
|---|---|
None |
|
Examples >>> yolo.labelstudio("images", mp_num=10, labels=["t1", "t2", "t3", "t4"])