当前位置:   article > 正文

【Segment Anything】CV的大模型Segment Anything也来了,强人工智能的时代究竟还有多远?_segmentanything训练模型

segmentanything训练模型

Segment Anything

在这里插入图片描述

1. 论文

论文链接:https://arxiv.org/pdf/2304.02643.pdf
在这里插入图片描述
论文解读后续更新……

2. 官方文档

官方文档:https://ai.facebook.com/blog/segment-anything-foundation-model-image-segmentation/

项目地址:https://github.com/facebookresearch/segment-anything

3. 测试网站

demo地址:https://segment-anything.com/demo

我自己上传了一张图片,结果还是挺好的(我上传的图片比较简单)。
在这里插入图片描述
在这里插入图片描述

4. 本地测试

4.1 下载预训练权重

https://github.com/facebookresearch/segment-anything#model-checkpoints

4.2 新建get_masks.py

新建get_masks.py内容如下:

from segment_anything import build_sam, SamPredictor
import numpy as np
import cv2
image = cv2.imread('/home/scholar/ldw/segment-anything/images/01.jpg')
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
predictor = SamPredictor(build_sam(checkpoint="/data_1/ldw_checkpoints/segment-anything/sam_vit_l_0b3195.pth"))
predictor.set_image(image)
input_point = np.array([[500, 375]])
input_label = np.array([1])

masks, _, _ = predictor.predict(    point_coords=input_point,
    point_labels=input_label,
    multimask_output=True,)
print('Done')

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

由于自己的3090显存有限,无法使用build_sam_vit_hpth,所以选用了build_sam_vit_l.pth

修改segment_anything/build_sam.py

build_sam = build_sam_vit_l
sam_model_registry = {
    "default": build_sam_vit_l,
    "vit_h": build_sam,
    "vit_l": build_sam_vit_l,
    "vit_b": build_sam_vit_b,
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

4.4 测试

# origin
python scripts/amg.py --checkpoint <path/to/sam/checkpoint> --input <image_or_folder> --output <output_directory>

# mine
python scripts/amg.py --checkpoint '/data_1/ldw_checkpoints/segment-anything/sam_vit_l_0b3195.pth' --input '/home/scholar/ldw/segment-anything/images/01.jpg' --output 'output'
  • 1
  • 2
  • 3
  • 4
  • 5

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/990395
推荐阅读
相关标签
  

闽ICP备14008679号