Semantic-SAM安装教程
安装简介
1 进入终端后,先安装github给的配置命令原封不动的进行下载配置
2 测试完成后,根据问题进行修改
1 下载安装
# 进入Semantic-SAM 的github地址
https://github.com/UX-Decoder/Semantic-SAM
# 根据给定安装步骤,依次安装
pip3 install torch==1.13.1 torchvision==0.14.1 --extra-index-url https://download.pytorch.org/whl/cu113
python -m pip install 'git+https://github.com/MaureenZOU/detectron2-xyz.git'
pip install git+https://github.com/cocodataset/panopticapi.git
git clone https://github.com/UX-Decoder/Semantic-SAM
cd Semantic-SAM
python -m pip install -r requirements.txt
export DATASET=/pth/to/dataset # path to your coco data
2 安装测试
使用下述代码对安装的模型进行测试,其中的ckpt,model_type,point位置都需要自己修改
from semantic_sam import prepare_image, plot_multi_results, build_semantic_sam, SemanticSAMPredictor
original_image, input_image = prepare_image(image_pth='examples/dog.jpg') # change the image path to your image
mask_generator = SemanticSAMPredictor(build_semantic_sam(model_type='<model_type>', ckpt='</your/ckpt/path>')) # model_type: 'L' / 'T', depends on your checkpint
iou_sort_masks, area_sort_masks = mask_generator.predict_masks(original_image, input_image, point='<your prompts>') # input point [[w, h]] relative location, i.e, [[0.5, 0.5]] is the center of the image
plot_multi_results(iou_sort_masks, area_sort_masks, original_image, save_path='../vis/') # results and original images will be saved at save_path
3 报错修改
通常运行后会出现以下报错
Please compile MultiScaleDeformableAttention CUDA op with the following commands:
‘cd mask2former/modeling/pixel decoder/ops‘
‘sh make.sh’
这个报错是由于deformable-DETR-main模型集成错误,所以需要重新对该模型进行编译
3.1 下载Deformable-DETR
https://github.com/fundamentalvision/Deformable-DETR
在github上下载Deformable-DETR模型
3.2 编译Deformable-DETR
# 下载项目后,进入下述目录进行编译
cd ./models/ops
sh ./make.sh
3.3 编译环境
建议编译环境在cuda11,cudnn8,gcc11环境,其他环境可能会编译不通过
添加链接描述