Artifact 만들기 — 데이터와 모델을 버전으로
Artifact 만들기 — 데이터와 모델을 버전으로
Artifact를 만드는 일은 결국 어떤 파일·디렉터리를 버전 객체에 담느냐로 좁혀져요. 여기서는 파이썬 API로 Artifact를 구성하는 기본 방법을 보여드릴게요.
출처: https://docs.wandb.ai/models/artifacts/construct-an-artifact
먼저 wandb.init으로 Run을 시작하고, wandb.Artifact를 이름과 타입으로 만들어요. 그다음 add_file이나 add_dir로 내용물을 담고, log_artifact로 W&B에 올리면 끝이에요.
import wandb
run = wandb.init(project="my-project", job_type="train")
artifact = wandb.Artifact(
name="my-dataset",
type="dataset",
description="처리된 MNIST 데이터셋",
metadata={"source": "Kaggle", "license": "CC0"},
)
artifact.add_file("data/processed/train.csv")
artifact.add_dir("data/images/")
run.log_artifact(artifact)
name은 이 Artifact를 가리키는 식별자예요. 같은 이름으로 다시 로그하면 v0, v1처럼 버전이 자동으로 붙어요. type은 데이터인지 모델인지 구분하는 데 쓰이고, metadata에는 라이선스나 출처 같은 추가 정보를 담을 수 있어요.
add_file은 파일 하나, add_dir은 디렉터리 전체를 추가해요. 디렉터리를 추가하면 그 안의 구조가 그대로 Artifact에 반영되죠. 참고로 job_type을 train처럼 명시해 두면 Run이 무슨 일을 하는지 파악하기 쉬워요.
더 알아보기
- https://docs.wandb.ai/models/artifacts/construct-an-artifact — Artifact 만들기
- https://docs.wandb.ai/models/artifacts/artifacts-walkthrough — Artifacts 단계별 실습