> For the complete documentation index, see [llms.txt](https://docs.unitlab.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unitlab.ai/api-sdk-cli/ko/sdks/data-group-automation.md).

# Data Group 자동화

Python SDK로 한 시점의 카메라 뷰처럼 서로 관련된 라이브러리 파일을 파일 이름 패턴에 따라 Data Group으로 자동 그룹화하는 방법을 설명합니다. 패턴 추천, 직접 정의, 제한 사항을 다룹니다.

Data Group은 여러 파일을 하나의 작업에 담아 어노테이터가 나란히 놓고 라벨링하게 합니다. 대표적인 예로 한 시점에 촬영한 로봇 셀의 카메라 4대 영상이나 의료 검사 하나의 여러 뷰가 있습니다. 그룹은 라이브러리 폴더의 파일 이름으로 구성됩니다.

## Unitlab이 패턴 찾기 <a href="#let-unitlab-find-the-pattern" id="let-unitlab-find-the-pattern"></a>

```python
folder = client.assets.folder("FOLDER_ID")
suggestion = folder.suggest_grouping()
print(suggestion.get("suggested"), suggestion.get("group_name_template"))

result = folder.auto_group()          # uses the suggestion
print(result.created_count, "groups in", result.grouped_folder().name)
```

설정 없이 `auto_group()`을 호출했는데 확실한 패턴을 찾지 못하면 `ValidationError`가 발생합니다. 이 경우 패턴을 직접 정의하세요.

## 패턴 직접 정의 <a href="#describe-the-pattern" id="describe-the-pattern"></a>

`cell04_0001_front.jpg`, `cell04_0001_left.jpg`와 같은 이름의 파일이라면 다음과 같이 합니다.

```python
from unitlab import tiles_from_template

config = tiles_from_template(
    "{cell}_{frame}_{view}",
    tile_values={"view": ["front", "left", "right", "wrist"]},
)
estimate = folder.estimate_grouping(config)
print(estimate)

result = folder.auto_group(config)
```

`tile_values`에 나열한 필드는 타일 이름이 됩니다. 나머지 필드(`cell`, `frame`)는 그룹을 식별합니다. 결과는 일반 dict이므로 전달하기 전에 수정할 수 있습니다.

| 키                           | 기본값                  | 의미                                                     |
| --------------------------- | -------------------- | ------------------------------------------------------ |
| `grouping_keys`             | `tile_values`에 없는 필드 | 파일을 같은 그룹으로 묶는 기준                                      |
| `group_name_template`       | `"{cell} {frame}"`   | 각 그룹의 이름                                               |
| `tiles`                     | 조합마다 하나              | `tile_id`, `title`, `match_rule`(정규 표현식), `exclusions` |
| `minimum_matched_tiles`     | `1`                  | 그룹 생성에 필요한 타일 수                                        |
| `required_tiles`            | `[]`                 | 모든 그룹에 있어야 하는 타일 ID                                    |
| `incomplete_group_handling` | `allow_incomplete`   | 타일이 빠진 그룹의 처리 방식                                       |
| `layout_type`               | `grid`               | Workbench에서 타일을 배치하는 방식                                |
| `recursive`                 | `True`               | 하위 폴더 포함                                               |

## 제한 <a href="#limits" id="limits"></a>

폴더 하나에는 최대 5,000개 파일을 담을 수 있고, 한 번 실행할 때 최대 1,000개 그룹을 만들 수 있습니다. 이를 넘으면 `auto_group()`이 `ValidationError`를 발생시킵니다. 파일을 더 작은 폴더로 나누고 폴더별로 실행하세요.

## 그룹화 이후 <a href="#after-grouping" id="after-grouping"></a>

그룹화된 폴더 또는 그 폴더로 만든 데이터셋을 프로젝트에 연결하세요. 각 그룹은 `kind="group"`인 Data Unit 하나가 됩니다.

## 관련 문서 <a href="#related" id="related"></a>

[폴더](https://docs.unitlab.ai/api-sdk-cli/ko/sdks/folders.md) · [라이브러리 데이터 연결과 해제](https://docs.unitlab.ai/api-sdk-cli/ko/sdks/attach-and-detach-project-sources.md) · [Data Unit](https://docs.unitlab.ai/api-sdk-cli/ko/sdks/data-units.md)
