VISSL 项目安装指南:从零开始搭建自监督学习环境

VISSL 项目安装指南:从零开始搭建自监督学习环境

vissl VISSL is FAIR's library of extensible, modular and scalable components for SOTA Self-Supervised Learning with images. vissl 项目地址: https://gitcode.com/gh_mirrors/vi/vissl

前言

VISSL(Vision Library for State-of-the-art Self-Supervised Learning)是一个专注于自监督学习的计算机视觉库,由Facebook Research团队开发。本文将详细介绍VISSL的安装过程,包括系统要求、预构建二进制安装和源码编译安装两种方式,帮助开发者快速搭建自监督学习的研究环境。

系统要求

在开始安装VISSL之前,请确保您的系统满足以下基本要求:

  • 操作系统:Linux(推荐Ubuntu 18.04或更高版本)
  • Python版本:3.6.2 ≤ Python < 3.9
  • PyTorch:≥1.4版本(推荐1.6.0或1.9.1)
  • torchvision:与PyTorch版本匹配
  • CUDA:需与PyTorch版本兼容(如10.1、10.2、11.0等)
  • OpenCV:用于图像处理

特别说明:

  1. 如果计划使用FSDP(Fully Sharded Data Parallel)功能,建议选择PyTorch 1.6.0、1.7.1或1.8.1版本
  2. CUDA版本必须与PyTorch版本匹配,否则可能导致兼容性问题

预构建二进制安装

VISSL提供了conda和pip两种预构建的二进制安装方式,适合希望快速搭建环境的用户。

Conda安装方式

Conda安装提供了完整的依赖管理,推荐使用:

# 创建并激活conda环境
conda create -n vissl python=3.8
conda activate vissl

# 安装PyTorch和相关依赖
conda install -c pytorch pytorch=1.7.1 torchvision cudatoolkit=10.2

# 安装VISSL及其依赖
conda install -c vissl -c iopath -c conda-forge -c pytorch -c defaults apex vissl

注意事项:

  • 可根据需要调整Python、PyTorch和CUDA版本
  • VISSL为各种PyTorch、Python和CUDA组合提供了预构建的Apex包

Pip安装方式

Pip安装提供了更灵活的版本选择:

# 安装PyTorch和torchvision(示例使用PyTorch 1.5.1和CUDA 10.1)
pip install torch==1.5.1+cu101 torchvision==0.6.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html

# 安装OpenCV
pip install opencv-python

# 自动检测系统配置并安装匹配的Apex
import sys
import torch
version_str="".join([
    f"py3{sys.version_info.minor}_cu",
    torch.version.cuda.replace(".",""),
    f"_pyt{torch.__version__[0:5:2]}"
])
print(version_str)

# 安装预编译的Apex
pip install apex -f https://dl.fbaipublicfiles.com/vissl/packaging/apexwheels/{version_str}/download.html

# 安装VISSL
pip install vissl

源码编译安装

对于需要自定义修改或希望获得最新功能的用户,推荐从源码编译安装。

Pip环境源码安装

步骤1:创建虚拟环境

python3 -m venv ~/venv
source ~/venv/bin/activate

步骤2:安装PyTorch

pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 -f https://download.pytorch.org/whl/torch_stable.html

步骤3:安装Apex

pip install apex -f https://dl.fbaipublicfiles.com/vissl/packaging/apexwheels/py37_cu101_pyt171/download.html

步骤4:编译安装VISSL

# 克隆VISSL仓库(包含子模块)
git clone --recursive https://github.com/facebookresearch/vissl.git
cd vissl

# 安装依赖
pip install --progress-bar off -r requirements.txt
pip install opencv-python

# 更新Classy Vision到最新main分支
pip uninstall -y classy_vision
pip install classy-vision@https://github.com/facebookresearch/ClassyVision/tarball/main

# 更新fairscale到兼容版本
pip uninstall -y fairscale
pip install fairscale@https://github.com/facebookresearch/fairscale/tarball/df7db85cef7f9c30a5b821007754b96eb1f977b6

# 以开发模式安装VISSL
pip install -e .[dev]

# 验证安装
python -c 'import vissl, apex, cv2'

Conda环境源码安装

步骤1:创建Conda环境

conda create -n vissl_env python=3.7
conda activate vissl_env

步骤2:安装PyTorch

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

步骤3:安装Apex

conda install -c vissl apex

步骤4:编译安装VISSL

与Pip环境源码安装的步骤4相同。

安装验证

完成安装后,可通过以下命令验证关键组件是否正常:

import vissl
import tensorboard
import apex
import torch

print(f"VISSL版本: {vissl.__version__}")
print(f"PyTorch版本: {torch.__version__}")
print(f"CUDA可用: {torch.cuda.is_available()}")

常见问题解决

  1. CUDA版本不匹配

    • 确保PyTorch、CUDA和Apex版本兼容
    • 使用nvcc --version检查CUDA版本
    • 使用torch.version.cuda检查PyTorch编译时使用的CUDA版本
  2. Apex安装失败

    • 确认PyTorch、Python和CUDA版本组合是否正确
    • 尝试从源码编译Apex
  3. 依赖冲突

    • 建议使用虚拟环境隔离安装
    • 可尝试先卸载冲突包再重新安装

结语

本文详细介绍了VISSL的多种安装方式,开发者可根据自身需求选择最适合的安装方法。预构建二进制安装适合快速开始,源码编译安装则适合需要定制化开发的研究人员。安装完成后,您就可以开始探索VISSL提供的各种自监督学习算法和模型了。

建议初次接触VISSL的用户从预构建的conda安装开始,待熟悉环境后再考虑源码编译安装以获得更多灵活性。

vissl VISSL is FAIR's library of extensible, modular and scalable components for SOTA Self-Supervised Learning with images. vissl 项目地址: https://gitcode.com/gh_mirrors/vi/vissl

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

束娣妙Hanna

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值