segment-anything安装教程

一. segment-anything安装教程

官网安装说明:https://github.com/facebookresearch/segment-anything

  1. anaconda下新建一个环境

    conda create -n sam python=3.8
    

    在这里插入图片描述

  2. 激活新建的环境

    conda activate sam
    

在这里插入图片描述

  1. 更换conda镜像源

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
    conda config --set show_channel_urls yes
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
    

    在这里插入图片描述

  2. 安装pytorch

    conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3
    

    在这里插入图片描述

  3. 克隆官方代码

    git clone [email protected]:facebookresearch/segment-anything.git
    

    在这里插入图片描述

  4. 进入下载好的文件夹,打开cmd,激活安装好的环境,运行以下代码

    pip install -e . -i https://mirrors.aliyun.com/pypi/simple/
    

    在这里插入图片描述
    在这里插入图片描述

  5. 安装所需python库

    pip install opencv-python pycocotools matplotlib onnxruntime onnx flake8 isort black mypy -i https://mirrors.aliyun.com/pypi/simple/
    

    在这里插入图片描述

  6. 从官网下载模型,并复制到源代码下
    在这里插入图片描述
    在这里插入图片描述

  7. 运行以下代码
    1.png为放置在源代码下的图像

    python scripts/amg.py --checkpoint sam_vit_b_01ec64.pth --model-type vit_b --input 1.jpg --output result
    

    在这里插入图片描述

    生成的图像掩码在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_30150579/article/details/134742854