# Hugging Face에서 ML-Agents 사용

`ml-agents`는 Unity로 만든 게임과 시뮬레이션을 지능형 에이전트 학습 환경으로 활용할 수 있도록 하는 오픈소스 툴킷입니다.

## Hub에서 ML-Agents 탐색

[모델 페이지](https://huggingface.co/models?library=ml-agents) 왼쪽에서 필터링하여 `ml-agents` 모델을 찾을 수 있습니다.

Hub의 모든 모델에는 유용한 기능이 함께 제공됩니다:
1. 설명, 학습 구성 및 기타 항목이 포함된 자동 생성된 모델 카드
2. 검색 가능성을 높이는 메타데이터 태그.
3. 학습 메트릭을 시각화하기 위한 Tensorboard summary 파일.
4. 브라우저에서 에이전트가 플레이하는 모습을 시각화할 수 있는 Spaces 웹 데모에 대한 링크입니다.

## 라이브러리 설치

`ml-agents` 라이브러리를 설치하려면 저장소를 클론해야 합니다:

```
# Clone the repository
git clone https://github.com/Unity-Technologies/ml-agents

# Go inside the repository and install the package
cd ml-agents
pip3 install -e ./ml-agents-envs
pip3 install -e ./ml-agents
```

## 기존 모델 사용

`mlagents-load-from-hf`를 사용하여 Hub에서 모델을 다운로드할 수 있습니다.

```
mlagents-load-from-hf --repo-id="ThomasSimonini/MLAgents-Pyramids" --local-dir="./downloads"
```

두 가지 매개변수를 정의해야 합니다:
- `--repo-id`: 다운로드하려는 Hugging Face 저장소의 이름.
- `--local-dir`: 모델을 다운로드할 경로.

## 에이전트가 플레이하는 것을 시각화

브라우저에서 모델을 직접 플레이하는 모습을 쉽게 확인할 수 있습니다:

1. 모델 저장소로 이동합니다.
2. `Watch Your Agent Play` 섹션에서 링크를 클릭합니다.
3. 데모의 1단계에서 모델 저장소, 즉 모델 ID를 선택합니다.
4. 2단계에서 재실행할 모델을 선택합니다.

## 모델 공유

`mlagents-push-to-hf`를 사용하면 모델을 쉽게 업로드할 수 있습니다:

```
mlagents-push-to-hf --run-id="First Training" --local-dir="results/First Training" --repo-id="ThomasSimonini/MLAgents-Pyramids" --commit-message="Pyramids"
```

네 가지 매개변수를 정의해야 합니다:
- `--run-id`: 학습 실행 ID의 이름.
- `--local-dir`: 모델이 저장된 위치.
- `--repo-id`: 생성하거나 업데이트하려는 Hugging Face 저장소의 이름입니다. `<your huggingface username>/<the repo name>` 형식입니다.
- `--commit-message`.

## 추가 리소스

* ML-Agents [문서](https://github.com/Unity-Technologies/ml-agents/blob/develop/docs/Hugging-Face-Integration.md)
* 공식 Unity ML-Agents Spaces [데모](https://huggingface.co/unity)

