求手机视频网站,wordpress category 404,本地网站建设多少钱,云开发是什么今年4月份#xff0c;Meta公布了它图形分割模型Segment-Anything#xff0c;简称SAM。当时就想着这个东西用在遥感影像分割上应该效果不错#xff0c;奈何自己能力有限#xff0c;没有办法上手实践。偶然间看到有介绍SAM-Geo工具包的文章#xff0c;决定研究一番#xff…今年4月份Meta公布了它图形分割模型Segment-Anything简称SAM。当时就想着这个东西用在遥感影像分割上应该效果不错奈何自己能力有限没有办法上手实践。偶然间看到有介绍SAM-Geo工具包的文章决定研究一番现在的做的这些工作可能只是狗尾续貂权当是记一下工作笔记了。
1. 简介
SAM-Geo是一个用于地理空间数据的Python 包可在 PyPI 和 conda-forge 上使用。作者吴秋生是美国田纳西大学地理系老师根据他在Bilibili主页上的介绍研究方向主要包括地理信息科学和遥感个人主页地址https://wetlands.io。 SAM-Geo工具包主要用于简化SAM模型在地理空间数据上的应用其想法来源于segment-anything-eo【github地址】。为方便后续学习将相应的地址都放在这里SAM-Geo的Github地址是https://github.com/opengeos/segment-geospatial文档地址https://samgeo.gishub.org。
2.安装
根据官网可以使用PyPI、Conda、GitHub、Docker方式安装
最简单的当然是使用pip安装了
pip install segment-geospatialConda推荐新建环境
conda create -n geo python
conda activate geo
conda install -c conda-forge mamba
mamba install -c conda-forge segment-geospatial安装依赖
mamba install -c conda-forge groundingdino-py segment-anything-fastGithub
pip install githttps://github.com/opengeos/segment-geospatialDocker
docker run -it -p 8888:8888 giswqs/segment-geospatial:latest为了是GPU生效需要运行下面的命令
docker run --rm -it --gpusall nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark如果报错nvidia-container-cli: initialization error: load library failed: libnvidia-ml.so.1: cannot open shared object file: no such file or directory: unknown.在上面的命令前面加上sudo运行。 等GPU容器运行正常后再运行docker run命令将SAM-Geom运行起来。
3.入门案例
官网的案例地址在https://samgeo.gishub.org/workshops/purdue/我这边简单记录下自己的操作过程水平有限您可以移步官网查看更详细的介绍。 这边采用的conda虚拟环境利用之前搭建的pytorch环境可以参考PyTorch安装记录及Anaconda环境配置 下列代码运行在Jupyter Notebook中
安装依赖
pip install segment-geospatial groundingdino-py leafmap localtileserver导入依赖
import leafmap
from samgeo import SamGeo
from samgeo.text_sam import LangSAM创建交互式地图
m leafmap.Map(center[40.427495, -86.913638], zoom18, height700)
m.add_basemap(SATELLITE)
m地图操作平移或缩放到所需位置然后用绘图工具在地图上创建多边形或矩形。
if m.user_roi_bounds() is not None:bbox m.user_roi_bounds()
else:bbox [-86.9167, 40.4262, -86.9105, 40.4289]image image.tif
leafmap.map_tiles_to_geotiff(outputimage, bboxbbox, zoom18, sourceSatellite, overwriteTrue)如果要使用自己的图像可以将image的地址设置为本地图片的地址。
将图片展示在地图上
m.layers[-1].visible False # turn off the basemap
m.add_raster(image, layer_nameImage)
m初始化模型
sam SamGeo( model_typevit_h, checkpointsam_vit_h_4b8939.pth, automaticFalse, sam_kwargsNone,
)sam.set_image(image)自动分类
sam.generate(image, outputmasks.tif, foregroundTrue, uniqueTrue)
sam.show_masks(cmapbinary_r)展示分类
sam.show_anns(axisoff, alpha1, outputannotations.tif)