การติดตั้งและเริ่มต้นใช้งาน DVC

การจัดการเวอร์ชันข้อมูลด้วย DVC เบื้องต้น

Ravi Bhadauria

Machine Learning Engineer

การติดตั้ง

  • DVC เป็น Python package
    • ติดตั้งได้ทุกระบบด้วย pip
$ pip install dvc
  • ควรติดตั้งใน virtual environment
  • ตรวจสอบให้แน่ใจว่าติดตั้ง Git แล้ว
การจัดการเวอร์ชันข้อมูลด้วย DVC เบื้องต้น

ตรวจสอบการติดตั้ง

$ dvc version
DVC version: 3.40.1 (pip)

Platform: Python 3.9.16 on macOS-14.2.1-arm64-arm-64bit
Config: Global: /Users/<username>/Library/Application Support/dvc System: /Library/Application Support/dvc
Repo: dvc, git
1 https://dvc.org/doc/command-reference/version
การจัดการเวอร์ชันข้อมูลด้วย DVC เบื้องต้น

การเริ่มต้น DVC

  • ตรวจสอบให้แน่ใจว่าเริ่มต้น Git แล้ว
$ git init
Initialized empty Git repository in /path/to/repo/.git/
  • เริ่มต้น DVC ใน repository
$ dvc init
Initialized DVC repository.

You can now commit the changes to git.
1 https://dvc.org/doc/command-reference/init
การจัดการเวอร์ชันข้อมูลด้วย DVC เบื้องต้น

ไฟล์ที่ซ่อนของ DVC

  • การเริ่มต้นใช้งานจะสร้างไฟล์ภายในที่ต้องติดตามด้วย Git
$ git status
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    new file:   .dvc/.gitignore
    new file:   .dvc/config
    new file:   .dvcignore
  • Commit การเปลี่ยนแปลง
$ git commit -m "initialized dvc"
การจัดการเวอร์ชันข้อมูลด้วย DVC เบื้องต้น

ไฟล์ .dvcignore

  • คล้ายกับไฟล์ .gitignore

    • ใช้รูปแบบเดียวกัน
    • ระบุไฟล์/ไดเรกทอรีที่ DVC จะข้ามไป
  • มีประโยชน์เมื่อมีไฟล์ข้อมูลจำนวนมากที่ไม่จำเป็นต้องติดตาม

    • ช่วยเพิ่มความเร็วในการทำงานของ DVC
1 https://dvc.org/doc/user-guide/project-structure/dvcignore-files 2 https://git-scm.com/docs/gitignore
การจัดการเวอร์ชันข้อมูลด้วย DVC เบื้องต้น

ตัวอย่าง

# .dvcignore
# Ignore all files in the 'data' directory
data/*

# But don't ignore 'data/data.csv' !data/data.csv
# Ignore all .tmp files *.tmp
1 https://dvc.org/doc/user-guide/project-structure/dvcignore-files
การจัดการเวอร์ชันข้อมูลด้วย DVC เบื้องต้น

การตรวจสอบไฟล์ที่ถูกข้ามไป

  • ใช้คำสั่ง dvc check-ignore
$ dvc check-ignore data/file.txt
data/file.txt
  • ใช้ flag -d เพื่อดูรายละเอียด
$ dvc check-ignore -d data/file.txt
.dvcignore:3:data/*    data/file.txt
1 https://dvc.org/doc/command-reference/check-ignore
การจัดการเวอร์ชันข้อมูลด้วย DVC เบื้องต้น

สรุป

  • ติดตั้ง DVC ด้วย pip install dvc
  • ตรวจสอบเวอร์ชัน แพลตฟอร์ม ฯลฯ ของ DVC
    • dvc version
  • เริ่มต้น DVC ใน workspace
    • dvc init
    • เริ่มต้น Git ก่อน
  • ไฟล์ .dvcignore ใช้ระบุไฟล์ที่ต้องการยกเว้น
    • คล้ายกับ .gitignore ใช้ syntax เดียวกัน
    • ตรวจสอบว่าไฟล์ถูกยกเว้นหรือไม่
      • dvc check-ignore <filename>
การจัดการเวอร์ชันข้อมูลด้วย DVC เบื้องต้น

มาฝึกกันเถอะ!

การจัดการเวอร์ชันข้อมูลด้วย DVC เบื้องต้น

Preparing Video For Download...