segment anything环境配置与使用测试

硬件:RTX3070 i9-11900H 内存16G

目录

一、环境配置

二、使用测试--predictor_example.ipynb

1.jupyter notebook准备操作

2.Object masks from prompts with SAM与Environment Set-up

3.Set-up

4.Example image

5.Selecting objects with SAM

6.Specifying a specific object with additional points

7.Specifying a specific object with a box

 8.Combining points and boxes

 9.Batched prompt inputs

10.End-to-end batched inference

三、使用测试--automatic_mask_generator_example.ipynb

1.Environment Set-up

2.Set-up

3.Example image

4.Automatic mask generation

 5.Automatic mask generation options


一、环境配置

首先从官方github上下载并解压在一个目录下,官方github网址:

GitHub - facebookresearch/segment-anythinghttps://github.com/facebookresearch/segment-anything下面进行环境配置:

1.conda创建虚拟环境,注意python版本大于等于3.8(官方要求python>=3.8)。

conda create -n segment python=3.8 -y

2.激活刚刚创建的虚拟环境,安装pytorch,注意官方要求pytorch>=1.7torchvision>=0.8。

conda activate segment
pip install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio==0.10.1+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

3.本文在pycharm IDE中进行调试,在解压目录下打开pycharm并配置上刚刚配置好的环境,进行后续的环境配置。

pycharm调用conda虚拟环境

进入 pycharm终端terminal进行后续安装

pip install -e .

官方没有给出安装库的详细版本,按照官方给的指令进行执行 

pip install opencv-python pycocotools matplotlib onnxruntime onnx

至此,环境配置完成,后续问题通过程序的报错去补全环境缺失的库或者调整库的版本。

二、使用测试--predictor_example.ipynb

1.jupyter notebook准备操作

官方给的是jupyter notebook的测试流程,首先启动终端进入虚拟环境

conda activate segment

进入官方编写的jupyter notebook的目录下,通过cd的方式,xxx根据实际目录调整

cd xxx:\xxx\segment-anything-main\segment-anything-main\notebooks

注:网上有很多方式去在jupyter notebook调用虚拟环境,我认为最好是在虚拟环境中安装库,如果安装错了可以直接删除虚拟环境,留有容错率且保持conda base环境的简洁,尽量不要在conda base环境中安装多余的库,conda base环境只作为创建虚拟环境的base环境。

在虚拟环境中安装ipykernel,如果不安装,jupyter notebook无法识别到刚刚创建的虚拟环境,即使终端已经启动了虚拟环境。

pip install ipykernel

 将刚刚创建的虚拟环境写入jupyter notebook

模板:

python -m ipykernel install --user --name 虚拟环境名 --display-name "显示名"

实际操作:

python -m ipykernel install --user --name segment --display-name "segment"

 启动jupyter notebook,启动后该终端不要关闭

jupyter notebook

在此图可以发现segment虚拟环境,说明jupyter notebook识别环境配置成功,但是需要配置虚拟环境。

 图中右侧可以看到虚拟环境名。

官方jupyter notebook给的比较详细,首先是predictor_example

接下来按照标题去看官方给的例子

2.Object masks from prompts with SAM与Environment Set-up

关于谷歌colab上运行的操作,由于是本机运行不需要这些操作。

3.Set-up

调用库并定义掩膜、点、矩形框的绘图函数。

4.Example image

为实例图片,通过Opencv读取并展示出来

5.Selecting objects with SAM

为检测测试,分为多个步骤

(1)下载训练好的网络模型,放在项目的model文件夹下,并修改程序中的路径

GitHub - facebookresearch/segment-anything: The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值