CVAT 云存储挂载指南:将 Amazon S3、Backblaze B2、Azure Blob 与 Google Drive 挂载为本地文件系统
【免费下载链接】cvatComputer Vision Annotation Tool (CVAT) is a leading platform for building high-quality visual datasets for vision AI. It offers open-source, cloud, and enterprise products, as well as labeling services, for image, video, and 3D annotation with AI-assisted labeling, quality assurance, team collaboration, analytics, and developer APIs.项目地址: https://gitcode.com/GitHub_Trending/cvat/cvat
本文基于 CVAT 官方管理文档 mounting_cloud_storages.md 编写,面向部署在 Ubuntu 20.04 上的 CVAT 社区版/企业版管理员。在本地运行 CVAT 时,你通常无法直接让服务器进程访问浏览器中的云存储页面,因此需要把远端对象存储"挂载"成本地目录。本文完整覆盖Amazon S3(含 S3 兼容的 Backblaze B2)、Microsoft Azure Blob Storage与Google Drive三种云存储的 FUSE 挂载、开机自动挂载(fstab 与 systemd 两种方案)、挂载验证与卸载操作,并结合 CVAT 仓库源码(cloud_provider.py)与工作区文档(cloud-storages.md、attach-cloud-storage.md)补充了 CVAT 侧对接的原理与注意事项。完成本文的学习后,你将能把云存储挂载为文件系统,进而把云上数据作为本地文件导入 CVAT,或让 CVAT 将标注结果写回云存储。
为什么需要"挂载"云存储:CVAT 的云存储接入方式
CVAT 本身对云存储的接入有两种完全不同的路径,理解它们的区别有助于你判断何时需要本文的挂载方案:
- 原生集成(推荐):CVAT 通过 Cloud storages 页面 直接"附加"(attach)Amazon S3、Azure Blob Storage、Backblaze B2 或 Google Cloud Storage,随后可从云存储创建任务、导入/导出标注数据集,无需本地挂载。具体字段与操作步骤参见 attach-cloud-storage.md。其底层由 cvat/apps/engine/cloud_provider.py 中的
CloudStorageClient抽象类及 S3 / Azure / GCS 三个具体实现类完成。 - 文件系统挂载(本文主题):把云存储通过 FUSE 挂载成
/mnt/...之类的本地目录,之后目录里的内容对 CVAT 而言就是一个普通本地目录,可直接用于创建任务或作为数据集源。此方案适合自托管部署、离线/内网环境或希望复用既有挂载工具链的场景。
需要说明:本文主文档(mounting_cloud_storages.md)中 Google Drive 的挂载工具google-drive-ocamlfuse仅是通用 FUSE 方案;而 CVAT 服务端的云存储客户端(cloud_provider.py)原生支持的 Google 系对象存储是Google Cloud Storage(GCS),通过GcsCloudStorageClient实现。因此若你的目标是"CVAT 服务器进程直接读写云存储",应优先使用 CVAT 原生云存储附加功能;本文的 FUSE 挂载方案则适合把云盘暴露给单机文件系统使用。
认识 CVAT 服务端的云存储客户端抽象
从源码结构看,cloud_provider.py 以CloudStorageClient(抽象基类,cloud_provider.py)统一定义了云存储的读写接口:
get_status()/get_file_status():探测 bucket/容器/文件是否可用(返回AVAILABLE、NOT_FOUND、FORBIDDEN三种状态,对应 Status 枚举);download_fileobj()/download_file()/download_range_of_bytes():支持整文件下载与 HTTP Range 范围下载(供流式读取与图片头解析使用);upload_fileobj()/upload_file()/bulk_delete():上传与批量删除;list_files()/list_files_on_one_page():分页列出 bucket 内容(受BUCKET_CONTENT_MAX_PAGE_SIZE配置控制);supported_actions:通过读取 bucket policy 推断允许的读/写操作。
具体实现包括 S3CloudStorageClient、AzureBlobCloudStorageClient 与 GcsCloudStorageClient。认证信息由 Credentials 类 管理,支持密钥对(Key & secret key)、账号名 + SAS Token、连接字符串、密钥文件以及匿名访问等多种凭据类型。
理解这层抽象后你会发现:无论你选择"原生集成"还是"FUSE 挂载",云存储侧的凭证要求(Access Key、SAS Token、服务账号等)是一致的,本文后续命令中的凭证正是这些字段在本地文件系统层的对应物。
一、将 Amazon S3 桶挂载为文件系统
1.1 准备工作(Ubuntu 20.04)
以下步骤在 Ubuntu 20.04 上验证可用,其他发行版请参考 s3fs-fuse 官方文档调整包管理器命令。
① 安装 s3fs
sudo apt install s3fs② 写入凭据文件并收紧权限
s3fs 通过${HOME}/.passwd-s3fs读取访问凭据,格式为一行ACCESS_KEY_ID:SECRET_ACCESS_KEY。出于安全考虑,该文件必须仅允许当前用户读写(权限 600):
echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fs chmod 600 ${HOME}/.passwd-s3fs③ 允许其他用户访问挂载点
编辑/etc/fuse.conf,取消user_allow_other一行的注释:
sudo nano /etc/fuse.conf该选项配合后续命令中的
-o allow_other使用,使 CVAT 服务器进程(通常以其他用户身份运行)也能读取挂载目录。
④ 执行挂载
s3fs <bucket_name> <mount_point> -o allow_other -o passwd_file=${HOME}/.passwd-s3fs将<bucket_name>替换为 S3 桶名,<mount_point>替换为本地挂载目录(需事先创建,例如/mnt/s3bucket)。
与 CVAT 服务端的对应关系:CVAT 原生集成 S3 时使用 Access Key ID / Secret Access Key(对应 attach-cloud-storage.md 中的 "Key id and secret access key pair"),服务端在 S3CloudStorageClient.init中通过 boto3 会话构造客户端,并以head_bucket探测桶状态(get_status)。s3fs 挂载后,本地路径的读写即等同于对桶内对象的读写,二者凭证语义一致。
1.2 开机自动挂载
完成上述 1.1 的前三步后,可选择以下两种方式之一实现开机自动挂载。
方式 A:使用 fstab
① 创建包装脚本(以 root 身份放到/usr/bin/amazon_s3_fuse):
#!/bin/bash sudo -u <user_name> s3fs <bucket_name> <mount_point> -o passwd_file=/path/to/.passwd-s3fs -o allow_other exit 0其中<user_name>为挂载归属用户,<bucket_name>为桶名,<mount_point>为挂载点,/path/to/.passwd-s3fs为凭据文件绝对路径。
② 赋予执行权限
sudo chmod +x /usr/bin/amazon_s3_fuse③ 在/etc/fstab追加一行
/absolute/path/to/amazon_s3_fuse <mount_point> fuse allow_other,user,_netdev 0 0fuse:文件系统类型;allow_other,user:允许其他用户访问、允许普通用户挂载;_netdev:告知系统该挂载依赖网络,避免在网络就绪前挂载失败。
方式 B:使用 systemd
① 创建 unit 文件/etc/systemd/system/s3fs.service:
[Unit] Description=FUSE filesystem over Amazon S3 bucket After=network.target [Service] Environment="MOUNT_POINT=<mount_point>" User=<user_name> Group=<user_name> ExecStart=s3fs <bucket_name> ${MOUNT_POINT} -o passwd_file=/path/to/.passwd-s3fs -o allow_other ExecStop=fusermount -u ${MOUNT_POINT} Restart=always Type=forking [Install] WantedBy=multi-user.target注意Type=forking:s3fs 以守护进程方式在后台运行,systemd 需据此判定服务启动完成。
② 重载配置、设置开机自启并启动
sudo systemctl daemon-reload sudo systemctl enable s3fs.service sudo systemctl start s3fs.service1.3 验证挂载
已挂载的文件系统记录在/etc/mtab中,可通过 grep 过滤确认:
cat /etc/mtab | grep 's3fs'若输出中包含 s3fs 挂载记录,即表示挂载成功。更直观的验证方式是用ls查看挂载点内容,或尝试读取其中一个文件确认数据可达。
1.4 卸载文件系统
fusermount -u <mount_point>如果此前使用 systemd 方式挂载,应通过 systemd 停止并禁用服务:
sudo systemctl stop s3fs.service sudo systemctl disable s3fs.serviceBackblaze B2 挂载提示:Backblaze B2 是 S3 兼容存储,可直接复用上述 s3fs 全部步骤,只需在挂载命令中通过
-o url=指定 B2 的端点 URL 并使用 B2 Application Keys 作为凭据,例如:
s3fs <bucket_name> <mount_point> -o allow_other -o passwd_file=${HOME}/.passwd-s3fs -o url=https://s3.us-west-004.backblazeb2.com这也与 CVAT 原生集成的行为一致:在 attach-cloud-storage.md 中,Backblaze B2 同样选择 "Amazon S3" 作为 Provider,并在Endpoint URL字段填入 B2 端点;服务端 S3CloudStorageClient 通过endpoint_url参数即可对接任何 S3 兼容服务。
1.5 内网/私有 S3 兼容服务的注意事项
若你挂载或附加的是内网 S3 兼容服务(如 MinIO),需要注意:CVAT 后端的所有出站请求默认经过 Smokescreen 出站代理(见 supervisord/reusable/smokescreen.conf,监听于127.0.0.1:4750),当端点解析到私有/受限 IP 时会被拦截,报错形如:
Failed to connect to proxy URL: "http://localhost:4750"解决方案是向管理员申请放行受信存储 IP,通过SMOKESCREEN_OPTS环境变量指定(该变量在 docker-compose.yml 中默认透传):
export SMOKESCREEN_OPTS=--allow-address=<storage_endpoint_ip> docker compose up -d若使用自定义 compose 覆盖文件,需确保cvat_server、cvat_worker_import、cvat_worker_export、cvat_worker_annotation、cvat_worker_chunks等所有可能访问云存储的后端容器都设置了相同的SMOKESCREEN_OPTS。详细说明见 installation.md 的 "Connecting to private cloud storage endpoints" 一节(对应行号 installation.md)。
二、将 Microsoft Azure Blob Storage 容器挂载为文件系统
2.1 安装 blobfuse 与 fuse(Ubuntu 20.04)
① 配置 Microsoft 软件源
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb sudo apt-get update② 安装 blobfuse 与 fuse
sudo apt-get install blobfuse fuse2.2 挂载容器
① 设置环境变量(替换account_name、account_key、mount_point):
export AZURE_STORAGE_ACCOUNT=<account_name> export AZURE_STORAGE_ACCESS_KEY=<account_key> MOUNT_POINT=<mount_point>② 创建缓存目录
blobfuse 需要一个本地磁盘缓存目录:
sudo mkdir -p /mnt/blobfusetmp③ 确保缓存目录归属挂载用户
sudo chown <user> /mnt/blobfusetmp④ 创建挂载点(若不存在):
mkdir -p ${MOUNT_POINT}⑤ 启用user_allow_other
在/etc/fuse.conf中取消user_allow_other注释:sudo nano /etc/fuse.conf
⑥ 挂载容器(替换your_container):
blobfuse ${MOUNT_POINT} --container-name=<your_container> --tmp-path=/mnt/blobfusetmp -o allow_other与 CVAT 服务端的对应关系:CVAT 原生附加 Azure Blob Storage 时支持"Account name and SAS token"、连接字符串与匿名访问三种凭据(见 attach-cloud-storage.md 的 Azure 小节),服务端 AzureBlobCloudStorageClient 通过BlobServiceClient实现,可用连接字符串(from_connection_string)或 SAS Token 构造客户端。blobfuse 挂载时使用的 Account Key 与 CVAT 侧的 SAS Token 对应同一存储账户的不同认证方式。
2.3 开机自动挂载
完成上述 2.2 的前七步后,可选以下方式实现自动挂载。
方式 A:使用 fstab
① 创建连接配置文件connection.cfg(选择 accountKey 与 sasToken 其中之一,删除另一行):
accountName <account-name-here> # Please provide either an account key or a SAS token, and delete the other line. accountKey <account-key-here-delete-next-line> #change authType to specify only 1 sasToken <shared-access-token-here-delete-previous-line> authType <MSI/SAS/SPN/Key/empty> containerName <insert-container-name-here>其中authType支持 MSI(托管身份)、SAS、SPN(服务主体)、Key 或留空,需与上面保留的凭据类型保持一致。
② 创建包装脚本/usr/bin/azure_fuse:
#!/bin/bash sudo -u <user_name> blobfuse <mount_point> --tmp-path=/path/to/blobfusetmp --config-file=/path/to/connection.cfg -o allow_other exit 0③ 赋予执行权限
sudo chmod +x /usr/bin/azure_fuse④ 在/etc/fstab追加一行
/absolute/path/to/azure_fuse </path/to/desired/mountpoint> fuse allow_other,user,_netdev方式 B:使用 systemd
① 创建 unit 文件/etc/systemd/system/blobfuse.service:
[Unit] Description=FUSE filesystem over Azure Blob Storage container After=network.target [Service] Environment="MOUNT_POINT=<mount_point>" User=<user_name> Group=<user_name> ExecStart=blobfuse ${MOUNT_POINT} --container-name=<container_name> --tmp-path=/mnt/blobfusetmp --config-file=/path/to/connection.cfg -o allow_other ExecStop=fusermount -u ${MOUNT_POINT} Restart=always Type=forking [Install] WantedBy=multi-user.target② 重载配置、设置开机自启并启动
sudo systemctl daemon-reload sudo systemctl enable blobfuse.service sudo systemctl start blobfuse.service2.4 验证挂载
cat /etc/mtab | grep 'blobfuse'2.5 卸载文件系统
fusermount -u <mount_point>若使用 systemd 挂载:
sudo systemctl stop blobfuse.service sudo systemctl disable blobfuse.service若遇到挂载问题,可参考 azure-storage-fuse 官方的 Troubleshoot FAQ 排查常见故障(文档原链接见 mounting_cloud_storages.md 的 Azure 小节)。
三、将 Google Drive 挂载为文件系统
3.1 安装 google-drive-ocamlfuse(Ubuntu 20.04)
Google Drive 可通过 FUSE 挂载为用户空间文件系统,使用的工具是 google-drive-ocamlfuse:
sudo add-apt-repository ppa:alessandro-strada/ppa sudo apt-get update sudo apt-get install google-drive-ocamlfuse3.2 首次授权与挂载
① 运行授权命令
google-drive-ocamlfuse该命令会创建默认应用目录~/.gdfuse/default(内含配置文件config),并自动打开浏览器引导你授权访问 Google Drive。授权完成后即可在挂载前修改默认配置。
② 创建挂载点(替换mount_point):
mountpoint="<mount_point>" mkdir -p $mountpoint③ 启用user_allow_other
在/etc/fuse.conf中取消user_allow_other注释:sudo nano /etc/fuse.conf
④ 挂载文件系统
google-drive-ocamlfuse -o allow_other $mountpoint3.3 开机自动挂载
完成上述 3.2 的前四步后,可选以下方式实现自动挂载。
方式 A:使用 fstab
① 创建包装脚本/usr/bin/gdfuse:
#!/bin/bash sudo -u <user_name> google-drive-ocamlfuse -o allow_other -label <label> <mount_point> exit 0其中<label>用于区分多个 Google Drive 账户配置(对应~/.gdfuse/<label>配置目录)。
② 赋予执行权限
sudo chmod +x /usr/bin/gdfuse③ 在/etc/fstab追加一行
/absolute/path/to/gdfuse <mount_point> fuse allow_other,user,_netdev 0 0方式 B:使用 systemd
① 创建 unit 文件/etc/systemd/system/google-drive-ocamlfuse.service:
[Unit] Description=FUSE filesystem over Google Drive After=network.target [Service] Environment="MOUNT_POINT=<mount_point>" User=<user_name> Group=<user_name> ExecStart=google-drive-ocamlfuse -label <label> ${MOUNT_POINT} ExecStop=fusermount -u ${MOUNT_POINT} Restart=always Type=forking [Install] WantedBy=multi-user.target其中<label>默认为default(即-label default),与首次授权生成的~/.gdfuse/default目录对应。
② 重载配置、设置开机自启并启动
sudo systemctl daemon-reload sudo systemctl enable google-drive-ocamlfuse.service sudo systemctl start google-drive-ocamlfuse.service3.4 验证挂载
cat /etc/mtab | grep 'google-drive-ocamlfuse'3.5 卸载文件系统
fusermount -u <mount_point>若使用 systemd 挂载:
sudo systemctl stop google-drive-ocamlfuse.service sudo systemctl disable google-drive-ocamlfuse.service提示:CVAT 原生集成的 Google 系对象存储为Google Cloud Storage(而非 Google Drive)。若要在 CVAT 中使用 GCS 桶,请在 Cloud storages 页面选择 "Google Cloud Storage" Provider,使用服务账号 JSON 密钥文件(Key file)或匿名访问方式附加,详见 attach-cloud-storage.md;服务端实现见 GcsCloudStorageClient。Google Drive 的 FUSE 挂载更适合作为本地文件系统供单机使用。
四、挂载后如何在 CVAT 中使用数据
将云存储挂载为本地目录后,数据的使用方式与本地文件完全一致:
创建任务:在 CVAT 创建任务时,将数据源指向挂载目录(例如
/mnt/s3bucket/images/),CVAT 会按本地文件处理;数据集组织:推荐按照 attach-cloud-storage.md 末尾 "Prepare the dataset" 一节的方式组织数据,即准备图片目录并可选生成
manifest.jsonl清单文件;生成 manifest(可选但推荐):CVAT 通过清单文件加速数据预览与元数据解析,可使用仓库自带工具生成:
python <cvat repository>/utils/dataset_manifest/create.py --output-dir <your_folder> <your_folder>更多用法(视频、图片目录、通配符、
--force强制重建等)参见 dataset_manifest.md,工具源码位于 utils/dataset_manifest/。性能说明:FUSE 挂载本质上是网络文件系统,帧预览与视频解码会通过网络读取远端对象(CVAT 服务端在 cloud_provider.py 中以带缓存的流式文件对象读取远端数据,并通过 HTTP Range 请求按需拉取字节段,避免整文件下载)。对超大视频或海量图片,带宽与延迟会直接影响标注体验,建议结合网络条件评估。
五、常见问题速查
| 问题现象 | 可能原因 | 处理建议 |
|---|---|---|
| 挂载后其他进程无法读取 | 未启用user_allow_other或未加-o allow_other | 在/etc/fuse.conf取消注释user_allow_other,并检查挂载命令选项 |
| 挂载失败:权限拒绝 | 凭据文件权限过宽或归属错误 | S3 凭据文件需chmod 600;Azure 缓存目录需chown给挂载用户 |
| 开机未自动挂载 | fstab/systemd 配置或网络依赖问题 | 检查_netdev选项;systemd 方案确认After=network.target与Restart=always |
| 卸载失败:busy | 有进程正在使用挂载点 | 先停止 CVAT 相关进程再执行fusermount -u |
CVAT 附加内网 S3 报Failed to connect to proxy URL | Smokescreen 出站代理拦截私有 IP | 按 installation.md 设置SMOKESCREEN_OPTS=--allow-address=<ip> |
参考与延伸阅读
- 本文主体文档:mounting_cloud_storages.md
- CVAT 云存储页面说明:cloud-storages.md
- CVAT 附加云存储(UI 操作)指南:attach-cloud-storage.md
- 云存储客户端实现:cloud_provider.py(S3:L604-L855、Azure:L858-L1002、GCS:L1020-L1138、Credentials:L1215-L1305)
- 私有云存储端点放行(Smokescreen):installation.md、smokescreen.conf、docker-compose.yml
- 数据集 manifest 清单工具:dataset_manifest.md、utils/dataset_manifest/
【免费下载链接】cvatComputer Vision Annotation Tool (CVAT) is a leading platform for building high-quality visual datasets for vision AI. It offers open-source, cloud, and enterprise products, as well as labeling services, for image, video, and 3D annotation with AI-assisted labeling, quality assurance, team collaboration, analytics, and developer APIs.项目地址: https://gitcode.com/GitHub_Trending/cvat/cvat
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考