基本介绍
Data Version Control | Git for Data & Models
Data Version Control (DVC):
专门为资料科学及机器学习所开发的版本控制工具,主要有以下特色:
:+1: 实用文章推荐:
Data science 的版控 → DVC 的建立与使用Difference between Git-LFS and DVCIntroduction to Data Version Control(DVC)使用情境
DVC官方提供了几个实用的使用範例(如下图所示-Versioning Data and Model Files),其中大多摘录资料科学的处理流程,包含了机器学习的流程以及资料管理等方案,透过官方手把手教学文件让使用者能够更快速的建立DVC实务应用
为对应架构内容,目前DSU主要选择的方案如下:
程式码(Code)版控方式:Git版控位置:Google Source Repositories训练模型(Model)版控方式:DVC版控位置:Google Cloud Storage使用教学
接下来将会针对订单辨识系统程式码与模型进行简单的版控与教学:
Installing DVC packages
安装DVC非常简单,主要有以下方式:
pip(Python package manger)OS-specific package managersHomeBrew(for apple users)本篇开发环境为Python,因此选择 pip 来安装 DVC(更多安装方式请参考dvc-Installation):
$ pip install dvc
选择Google Cloud Storage为远端储存空间(更多选择方案dvc-remote storage):
$ pip install "dvc[gs]"
Initialising Git & DVC
安装完毕后接着将需要版控的专案资料夹进行初始化
专案资料结构如下:
dvc-test├── main.py└── model └── my_model.h5
1. Git 初始化
$ git init
2. 建立 .gitingore
排除不需透过git版控的档案
$ vi .gitingore
# 请依照使用情况调整model/.vscode.DS_Store__pycache__/
3. DVC 初始化
$ dvc init
成功会看到以下内容:
路径下产生.dvc/
资料夹,其内容包含 .dvc/.gitignore 、 .dvc/cache/ 、 . dvc/config 三份档案,其中最重要的是 .dvc/cache/, DVC 会在这边建立档案的连结,也是最后会 push 到云端的档案。
You can now commit the changes to git.+---------------------------------------------------------------------+| || DVC has enabled anonymous aggregate usage analytics. || Read the analytics documentation (and how to opt-out) here: || https://dvc.org/doc/user-guide/analytics || |+---------------------------------------------------------------------+What's next?------------- Check out the documentation: https://dvc.org/doc- Get help and share ideas: https://dvc.org/chat- Star us on GitHub: https://github.com/iterative/dvc
Versioning Data and Model Files
1. 首先将model资料夹加入dvc版控
$ dvc add model
完成后便会产生相对应的model.dvc(用来连结dvc资料)
dvc-test├── main.py├── model│ └── my_model.h5└── model.dvc
2. 将程式码以dvc相关档案及推送至Source Repositories
Create repositories$ git add .$ git commit -m "v0.0.1"$ git remote add google ssh://[EMAIL]@source.developers.google.com:2022/p/[PROJECT_ID]/r/[REPO_NAME]$ git push --all google
Pushing Data to Goole Cloud Storage
:::warning
本段落须事先準备下列项目:
:::
1. projectname
- project name to use.
$ dvc remote modify myremote projectname myproject
2. url
- remote cloud storage URL.
$ dvc remote modify myremote url gs://bucket/remote
3. credentailpath
- service account credentials.
$ dvc remote modify myremote credentialpath /path/to/my/creds/[FILE_NAME].json
4. Push to GCS
$ dvc pushdvc pushPreparing to upload data to 'gs://bucket/remote'Preparing to collect status from gs://bucket/remoteCollecting information from local cache...[##############################] 100%Collecting information from remote cache...[##############################] 100[##############################] 100% Analysing status[##############################] 100% model/my_model.h5
Pulling data from the cloud
Cloning repositories$ git clone ssh://[EMAIL]@source.developers.google.com:2022/p/[PROJECT_ID]/r/[REPO_NAME]$ dvc pull