Data Version Control(DVC)使用概述

基本介绍

Data Version Control | Git for Data & Models

image alt

Data Version Control (DVC):
专门为资料科学及机器学习所开发的版本控制工具,主要有以下特色:

基本操作指令皆与 Git 使用方式相同,不需要另外安装或者维护任何资料库,同时也不依赖任何专有的线上服务模型和数据资料的档案版本可以直接串连 S3, Google cloud, Azure, Alibaba cloud, SSH server, HDFS 甚至直接储存在本地端硬碟专案技术具有可複制性和共享性,帮助了解模型差异及建构方式使用Git标籤/分支和指标跟踪帮助团队管理专案内容更多DVC特色介绍

:+1: 实用文章推荐:

Data science 的版控 → DVC 的建立与使用Difference between Git-LFS and DVCIntroduction to Data Version Control(DVC)

使用情境

DVC官方提供了几个实用的使用範例(如下图所示-Versioning Data and Model Files),其中大多摘录资料科学的处理流程,包含了机器学习的流程以及资料管理等方案,透过官方手把手教学文件让使用者能够更快速的建立DVC实务应用

image alt

为对应架构内容,目前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
本段落须事先準备下列项目:

取得服务帐户金钥建立Cloud Storage bucket
:::

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

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章