文章目录
【笔记内容】:
本篇笔记旨在剖析dvc常见指令,请大家和我一起来学习吧!
一:dvc remote
#普遍建立和修改url的方法
dvc remote add -d myremote [URL]
dvc remote modify myremote url s3://mybucket/new/path
# 下面是Amazon S3的专用options,因为我搭建了S3 cloud services
#DVC will determine the type of remote based on the url provided.
#This may affect which parameters you can access later via dvc remote modify
#(note that the url itself can be modified).
dvc remote add -d myremote s3://dvc#与s3建立联系
dvc remote modify myremote endpointurl http://ceph01#修改访问s3的URL端点
#列出remote列表
dvc remote list
#You can overwrite existing remotes using -f with dvc remote add:
dvc remote add -f myremote s3://mybucket/another-path
#修改S3的config,可以使用remote modify也可以设置环境变量
dvc remote modify --local myremote access_key_id 'mykey'
#access_key_id - AWS Access Key ID. May be used (along with secret_access_key)
#instead of credentialpath
dvc remote modify --local myremote secret_access_key 'mysecret'
#secret_access_key - AWS Secret Access Key. May be used (along with access_key_id)
#instead of credentialpath
# or 设置环境变量
dvc remote add -d myremote s3://mybucket/path
export AWS_ACCESS_KEY_ID='mykey'
export AWS_SECRET_ACCESS_KEY='mysecret'
dvc push
#default操作
dvc remote default #打印出当前的defalut remote
dvc remote dafault [name] #使某个remote为默认remote,对于缺省的dvc pull/push等操作很关键
#remove操作,Remove a data remote. This command affects DVC configuration files only, it does not physically remove data files stored remotely.
#This command removes a section in the DVC config file. Alternatively, it is possible to edit config files manually.
dvc remote remove myremote
二:dvc add
#The dvc add command is analogous to git add, in that it makes DVC aware of the target #data, in order to start versioning it. It creates a .dvc file to track the added data.
#his command can be used to track large files, models, dataset directories, etc.
#that are too big for Git to handle directly. This enables versioning them indirectly with Git.
dvc add [file/dir] #新建了.dvc文件,存放元数据。同时向.gitignore中添加了该file/dir路径
三:dvc cache / cache-ignore
#To set the cache directory location: dir.
dvc cache dir [dir]
# if [file/dir] is written in .dvcignore,they will be excluded while working with the project by DVC
dvc cache-ignore [file/dir]
四:dvc list
#会列出对应高路径下所有dvc和git跟踪的文件、文件夹、模型、数据等
dvc list url [path]
五: dvc get
#将该url对应的仓库下dvc跟踪的actual data下载下来,这里的path不能直接写一个.dvc文件,而应该写包含.dvc文件的dir
dvc get url [path]
广泛应用于想从其他repo下载一个dataset。下载完成后工作区会有一个dir,里面只包括原数据和.gitignore。
但是这个api有个弊端,回头我想查看这个data是dvc从哪儿个repo跟踪来的,是查看不到的,所以就有了import方法。
六: dvc import
#这里的path需要写dir/原数据文件(例子中就是dvc import /... dataset/1.txt),而不是写dir,这里和dvc get不同,最后出来的效果也不同
dvc import url path
import方法和get不同的点,除了path填写不同,还有一点就是它还会自动track这个被导入的文件从而生成.dvc文件,等于在dvc get后面又加了一步dvc add。
还有一点不同,dvc import甚至可以从一个非dvc的git库中加载任意数据,然后track生成,dvc文件。
所以由此可见,dvc import 和python中的import很像,就是在后面又加了一步dvc add,对其跟踪。
七: dvc.api
#如果使用pip安装dvc,那么我们还可以把dvc.api当作一个包进行调用
import dvc.api
with dvc.api.open(
"get-started/data.xml",
repo = 'https://github.com/iterarive/dataset-registry'
) as fd:
# fd.read()
运用上述的方法,只有在脚本运行的时候才会将data加载到工作区,并且脚本运行结束后,将不再存在于工作区中,除非主动包保存。