Skip to main content

데이터셋 정리 및 시각화 라이브러리

Project description

clean-dataset

데이터셋 정리 및 시각화 라이브러리

train/val/test로 구성된 비디오/이미지 데이터셋을 정리하고 시각화하는 도구입니다.

설치

pip install clean-dataset

또는 소스에서 설치:

git clone https://github.com/haechan/clean-dataset.git
cd clean-dataset
pip install -e .

주요 기능

1. 데이터 정리

이미지 재구성

from clean_dataset import reorganize_images

# train/{video_id}/frame.jpg -> train/image/{video_id}@{frame}.jpg
reorganize_images(
    input_dir="./data",
    output_dir="./output",
    train_json="train.json",
    val_json="val.json",
    test_json="test.json"  # 선택
)

JSON 어노테이션 생성

from clean_dataset import create_annotations, create_annotations_from_masks

# 원본 JSON에서 단순화된 bbox JSON 생성
create_annotations(
    output_dir="./output",
    train_json="train.json",
    val_json="val.json",
    use_thing_only=True  # stuff 제외
)

# 마스크에서 bbox JSON 생성
create_annotations_from_masks(
    mask_dir="./mask_semantic",
    output_dir="./json",
    category_json="train.json",  # 선택
    use_thing_only=True
)

출력 JSON 구조:

[
    {
        "id": 1,
        "tag": "person",
        "xmin": 701,
        "ymin": 0,
        "xmax": 1280,
        "ymax": 709
    }
]

마스크 생성

from clean_dataset import generate_masks

generate_masks(
    annotation_json="train.json",
    output_dir="./output",
    mask_type="instance",  # "instance" | "semantic" | "panoptic"
    split="train"  # 선택
)

카테고리 JSON 생성

from clean_dataset import generate_category_json, generate_category_json_from_mask

# 어노테이션 JSON에서 카테고리 JSON 자동 생성
generate_category_json(
    annotation_json="train.json",
    output_path="categories.json"
)

# 마스크 폴더에서 사용된 클래스만 추출하여 카테고리 JSON 생성
generate_category_json_from_mask(
    mask_dir="./masks",
    output_path="categories.json",
    category_json="train.json"  # 선택: 클래스명 매핑용
)

출력 형식 (isthing 정보가 있는 경우):

{
    "names": {
        "wall": "stuff",
        "person": "thing"
    },
    "ignore": 255
}

출력 형식 (isthing 정보가 없는 경우):

{
    "names": ["wall", "person"],
    "ignore": 255
}

2. 데이터셋 분할

비율 기반 분할

from clean_dataset import split_dataset

# JSON 또는 TXT 파일을 train/val/test로 분할
split_dataset(
    input_file="data.json",  # 또는 data.txt
    output_dir="./output",
    train_ratio=0.8,
    val_ratio=0.1,
    test_ratio=0.1,
    shuffle=True,
    seed=42
)

리스트 기반 분할

from clean_dataset import split_by_list

# 미리 정의된 리스트로 분할
split_by_list(
    input_file="annotations.json",
    train_list="train_ids.txt",
    val_list="val_ids.txt",
    test_list="test_ids.txt",
    output_dir="./output"
)

폴더 분할

from clean_dataset import split_folder

# 폴더 내 파일을 train/val/test로 분할
split_folder(
    input_dir="./images",
    output_dir="./output",
    train_ratio=0.8,
    val_ratio=0.1,
    test_ratio=0.1,
    extensions=['.jpg', '.png'],
    copy_files=True  # True: 파일 복사, False: 리스트만 저장
)

리스트 기반 파일 복사

from clean_dataset import copy_files_by_list

# txt 리스트를 기반으로 파일 복사
copy_files_by_list(
    source_dir="./images",
    output_dir="./output",
    train_list="train.txt",
    val_list="val.txt",
    test_list="test.txt"
)
# 결과: output/train/, output/val/, output/test/ 폴더에 파일 복사

K-Fold 분할

from clean_dataset import create_kfold_splits

# K-Fold 교차 검증용 분할 생성
create_kfold_splits(
    input_file="data.json",
    output_dir="./kfold",
    k=5,
    shuffle=True
)

지원 JSON 형식:

  • YouTube-VOS 형식: {"videos": {...}}
  • COCO 형식: {"images": [...], "annotations": [...]}
  • Annotations 형식: {"annotations": [...]}
  • 리스트 형식: ["item1", "item2"] 또는 [{"id": 1, ...}]

3. 시각화

팔레트 이미지 생성

from clean_dataset import generate_palette_image

generate_palette_image(
    output_path="palette.jpg",
    annotation_json="train.json"
)

Detection 시각화

from clean_dataset import visualize_detection

visualize_detection(
    image_path="image.jpg",
    json_path="annotation.json",
    output_dir="./viz",
    show_class_name=True,
    show_legend=True  # 오른쪽에 팔레트 범례 표시
)

Segmentation 시각화

from clean_dataset import visualize_segmentation

visualize_segmentation(
    image_dir="./images",
    mask_dir="./masks",
    json_dir="./json",
    output_dir="./viz",
    is_video=True,  # True: strip으로 연결, False: 단일 이미지
    alpha=0.5
)

카테고리 관리

from clean_dataset import load_categories, category_manager

# JSON에서 카테고리 로드
load_categories("train.json")

# 카테고리 정보 조회
print(category_manager.get_class_name(1))  # "person"
print(category_manager.is_thing(1))  # True
print(len(category_manager))  # 카테고리 수

지원 형식

  • 입력: YouTube-VOS, VIPSeg, COCO 형식의 JSON
  • 카테고리: 딕셔너리 형식 ({"wall": "stuff"}) 또는 리스트 형식 ([{"id": 1, "name": "person"}])
  • 마스크: RLE 인코딩, RGB panoptic 마스크

의존성

  • numpy >= 1.20.0
  • Pillow >= 8.0.0
  • opencv-python >= 4.5.0
  • sanghyunjo

라이선스

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clean_dataset-0.1.2.tar.gz (26.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clean_dataset-0.1.2-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

Details for the file clean_dataset-0.1.2.tar.gz.

File metadata

  • Download URL: clean_dataset-0.1.2.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for clean_dataset-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8d13fa10247b259a509fe8c8486d349ae21c5ad16c26974ce930006d17698e43
MD5 a0fc156f598edabf43dbd5eddec23a56
BLAKE2b-256 bd34dd5b49c4ca2ccd0d9543d7457e2ffa711d62a980efa49d8f540a62ca8c83

See more details on using hashes here.

File details

Details for the file clean_dataset-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: clean_dataset-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 33.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for clean_dataset-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f472e58efab0914782de202ecd6fa9d13278e05f4ba261da54fcf026501528f7
MD5 03e9ea926dced38e0cb174163eefbdd7
BLAKE2b-256 3f3a0413003cc5c6fe0a6dc348fa5680e2656f0f54407e7182e0bd4296850286

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page