> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

> W&B로 데이터셋 아티팩트를 생성하고, 추적하고, 사용하는 방법을 알아봅니다.

# 튜토리얼: 데이터셋 아티팩트 생성, 추적 및 사용

이 워크스루에서는 데이터셋 아티팩트를 생성하고, 추적하고, 사용하는 방법을 알아봅니다.

<h2 id="1-log-into-wb">
  1. W\&B에 로그인
</h2>

W\&B 라이브러리를 임포트하고 W\&B에 로그인하세요. 아직 가입하지 않았다면 무료 W\&B 계정을 만들어야 합니다.

```python theme={"system"}
import wandb

wandb.login()
```

<h2 id="2-initialize-a-run">
  2. run 초기화
</h2>

[`wandb.init()`](/ko/products/wandb/ref/python/functions/init)을 사용하여 run을 초기화하세요. 이 함수는 데이터를 동기화하고 로깅하는 백그라운드 프로세스를 생성합니다. 프로젝트 이름과 작업 유형을 지정하세요:

```python theme={"system"}
# W&B run을 생성합니다. 이 예제에서는 데이터셋 아티팩트를 생성하는 방법을
# 보여 주므로 작업 유형을 'dataset'으로 지정합니다.
with wandb.init(project="artifacts-example", job_type="upload-dataset") as run:
    # 여기에 코드를 작성하세요
```

<h2 id="3-create-an-artifact-object">
  3. 아티팩트 객체 만들기
</h2>

[`wandb.Artifact()`](/ko/products/wandb/ref/python/experiments/artifact)으로 아티팩트 객체를 만드세요. `name`과 `type` 매개변수에 각각 아티팩트 이름과 파일 유형에 대한 설명을 제공하세요.

예를 들어, 다음 코드 스니펫은 `‘dataset’` 레이블이 지정된 `‘bicycle-dataset’`이라는 아티팩트를 만드는 방법을 보여줍니다:

```python theme={"system"}
artifact = wandb.Artifact(name="bicycle-dataset", type="dataset")
```

아티팩트를 생성하는 방법에 대한 자세한 내용은 [아티팩트 생성](/ko/products/wandb/artifacts/construct-an-artifact)을 참조하세요.

<h2 id="4-add-the-dataset-to-the-artifact">
  4. 아티팩트에 데이터셋 추가
</h2>

아티팩트에 파일을 추가하세요. 일반적인 파일 유형에는 모델과 데이터셋이 포함됩니다. 다음 예시는 로컬 컴퓨터에 저장된 `dataset.h5`라는 데이터셋을 아티팩트에 추가합니다:

```python theme={"system"}
# 아티팩트의 내용에 파일 추가
artifact.add_file(local_path="dataset.h5")
```

이전 코드 스니펫의 파일 이름 `dataset.h5`를 아티팩트에 추가할 파일의 경로로 바꾸세요.

<h2 id="5-log-the-dataset">
  5. 데이터셋 로깅하기
</h2>

W\&B run 객체의 `wandb.Run.log_artifact()` 방법을 사용하여 아티팩트 버전을 저장하고 아티팩트를 [run의 출력](/ko/products/wandb/artifacts/explore-and-traverse-an-artifact-graph)으로 선언하세요.

```python theme={"system"}
# 아티팩트 버전을 W&B에 저장하고
# 이 run의 출력으로 표시합니다
run.log_artifact(artifact)
```

아티팩트를 로깅하면 기본적으로 `'latest'` [별칭](/ko/products/wandb/artifacts/create-a-custom-alias)이 생성됩니다. 아티팩트 별칭과 버전에 대한 자세한 내용은 각각 [맞춤형 별칭 만들기](/ko/products/wandb/artifacts/create-a-custom-alias)와 [새 아티팩트 버전 만들기](/ko/products/wandb/artifacts/create-a-new-artifact-version)를 참조하세요.

지금까지의 내용을 모두 합치면 스크립트는 다음과 같아야 합니다.

```python theme={"system"}
import wandb

wandb.login()

with wandb.init(project="artifacts-example", job_type="upload-dataset") as run:
    artifact = wandb.Artifact(name="bicycle-dataset", type="dataset")
    artifact.add_file(local_path="dataset.h5")
    run.log_artifact(artifact)
```

<h2 id="6-download-and-use-the-artifact">
  6. 아티팩트 다운로드 및 사용
</h2>

다음 코드 예시는 W\&B 서버에 로깅하고 저장한 아티팩트를 사용하는 단계를 보여줍니다.

1. 먼저, \*\*`wandb.init()`.\*\*으로 새 run 객체를 초기화하세요.
2. 다음으로, run 객체의 [`wandb.Run.use_artifact()`](/ko/products/wandb/ref/python/experiments/run#use_artifact) 방법을 사용하여 W\&B에 사용할 아티팩트를 지정하세요. 이 방법은 아티팩트 객체를 반환합니다.
3. 마지막으로, 아티팩트의 [`wandb.Artifact.download()`](/ko/products/wandb/ref/python/experiments/artifact#download) 방법을 사용하여 아티팩트의 내용을 다운로드하세요.

```python theme={"system"}
# W&B run을 생성합니다. 여기서 'type'에 'training'을 지정합니다.
# 트레이닝을 추적하기 위해 이 run을 사용하기 때문입니다.
with wandb.init(project="artifacts-example", job_type="training") as run:

  # 이 run의 입력으로 표시할 아티팩트를 W&B에서 쿼리합니다.
  artifact = run.use_artifact("bicycle-dataset:latest")

  # 아티팩트의 내용을 다운로드합니다.
  artifact_dir = artifact.download()
```

또는 Public API(`wandb.Api`)를 사용하여 run 외부에서 W\&B에 이미 저장된 데이터를 내보내거나 업데이트할 수 있습니다. 자세한 내용은 [외부 파일 추적](/ko/products/wandb/artifacts/track-external-files)을 참조하세요.
