[{"data":1,"prerenderedAt":329},["ShallowReactive",2],{"content-query-5suE6u0CRP":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"category":13,"body":14,"_type":323,"_id":324,"_source":325,"_file":326,"_stem":327,"_extension":328},"/technology-blogs/zh/3501","zh",false,"","FastSAM-MindSpore：加速图像分割的革命性技术","作者：梁启航 昇思开发者、湖北工业大学硕士研究生，研究方向为深度学习和机器视觉","2024-11-26","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/11/29/81e99c8adbb34460a1f354f827010a6f.png","technology-blogs","开发者分享",{"type":15,"children":16,"toc":320},"root",[17,25,30,35,43,48,57,72,77,87,94,108,113,121,128,136,144,149,157,164,172,179,187,192,205,210,215,233,241,254,259,266,273,281,286,293,300,308,313],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"fastsam-mindspore加速图像分割的革命性技术",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":24,"value":9},{"type":18,"tag":26,"props":31,"children":32},{},[33],{"type":24,"value":34},"在计算机视觉领域，图像分割技术一直是研究的热点。随着技术的发展，分割任意模型（SAM）在图像分割、图像描述和图像编辑等任务中发挥了重要作用。然而，SAM的高计算成本限制了其在实际场景中的应用。为了解决这一问题，中科院自动化所提出了FastSAM模型，通过将分割一切任务重新划分为全实例分割和提示指导选择两个子任务，用带实例分割分支的常规 CNN 检测器以高出50倍的运行速度实现了与SAM方法相当的性能，是首个实时分割⼀切的基础模型。本文将探讨FastSAM-MindSpore技术，即FastSAM在昇思MindSpore AI框架下的实现，以及其应用。",{"type":18,"tag":26,"props":36,"children":37},{},[38],{"type":18,"tag":39,"props":40,"children":42},"img",{"alt":7,"src":41},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/11/29/90cec684275f4fa986ce95994e28aa9a.png",[],{"type":18,"tag":26,"props":44,"children":45},{},[46],{"type":24,"value":47},"FastSAM的网络架构可分为两个阶段：全实例分割和提示引导选择。在全实例分割阶段，FastSAM使用卷积神经网络来对图像中的所有对象或区域进行划分。在提示引导选择阶段，它采用包括点提示、框提示和文本提示的各种提示来选出关注对象。与基于Transformer的方法不同，FastSAM融合了与视觉分割任务紧密相关的先验知识，例如局部连接和对象分配策略。这使得它以更低地参数量和计算量下更快地收敛。",{"type":18,"tag":26,"props":49,"children":50},{},[51],{"type":18,"tag":52,"props":53,"children":54},"strong",{},[55],{"type":24,"value":56},"基于昇思MindSpore实践",{"type":18,"tag":26,"props":58,"children":59},{},[60,65,67],{"type":18,"tag":52,"props":61,"children":62},{},[63],{"type":24,"value":64},"0****1",{"type":24,"value":66}," ",{"type":18,"tag":52,"props":68,"children":69},{},[70],{"type":24,"value":71},"无提示生成",{"type":18,"tag":26,"props":73,"children":74},{},[75],{"type":24,"value":76},"你可以使用以下代码生成所有的掩码和可视化结果。",{"type":18,"tag":78,"props":79,"children":81},"pre",{"code":80},"\nfrom mindyolo.models import create_model\nfrom Inference import segment\nfrom prompt import FastSAMPrompt\n\nnetwork = create_model(\n        model_name=args.network.model_name,\n        model_cfg=args.network,\n        num_classes=args.data.nc,\n        sync_bn=False,\n        checkpoint_path=args.weight,\n        )\n        \nresult_dict = segment(\n        network=network,\n        img=image,\n        conf_thres=args.conf_thres,\n        iou_thres=args.iou_thres,\n        conf_free=args.conf_free,\n        nms_time_limit=args.nms_time_limit,\n        img_size=args.img_size,\n        stride=max(max(args.network.stride), 32),\n        num_class=args.data.nc,\n        is_coco_dataset=is_coco_dataset,\n        )\nprompt_process = FastSAMPrompt(image, result_dict,)\n\n# everything prompt\nann = prompt_process.everything_prompt()\n\nprompt_process.plot(annotations=ann,output_path='./output/dog.jpg',)\n",[82],{"type":18,"tag":83,"props":84,"children":85},"code",{"__ignoreMap":7},[86],{"type":24,"value":80},{"type":18,"tag":26,"props":88,"children":89},{},[90],{"type":18,"tag":39,"props":91,"children":93},{"alt":7,"src":92},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/11/29/fbea33bb63b64742b1ea0610fbbebc81.png",[],{"type":18,"tag":26,"props":95,"children":96},{},[97,102,103],{"type":18,"tag":52,"props":98,"children":99},{},[100],{"type":24,"value":101},"0****2",{"type":24,"value":66},{"type":18,"tag":52,"props":104,"children":105},{},[106],{"type":24,"value":107},"点提示生成",{"type":18,"tag":26,"props":109,"children":110},{},[111],{"type":24,"value":112},"通过给出点的位置，和点的类别,1是前景，0是背景。",{"type":18,"tag":78,"props":114,"children":116},{"code":115},"\n# Box prompt (xywh)\npython Inference.py --weight ./weights/FastSAM.pt --image_path ./images/dogs.jpg  --box_prompt \"[[570,200,230,400]]\"\n",[117],{"type":18,"tag":83,"props":118,"children":119},{"__ignoreMap":7},[120],{"type":24,"value":115},{"type":18,"tag":26,"props":122,"children":123},{},[124],{"type":18,"tag":39,"props":125,"children":127},{"alt":7,"src":126},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/11/29/38a1e81d867a4c05b33fde6d52c28f49.png",[],{"type":18,"tag":26,"props":129,"children":130},{},[131],{"type":18,"tag":52,"props":132,"children":133},{},[134],{"type":24,"value":135},"0****3",{"type":18,"tag":26,"props":137,"children":138},{},[139],{"type":18,"tag":52,"props":140,"children":141},{},[142],{"type":24,"value":143},"框提示生成",{"type":18,"tag":26,"props":145,"children":146},{},[147],{"type":24,"value":148},"通过给出框的位置。",{"type":18,"tag":78,"props":150,"children":152},{"code":151},"\n# Everything mode\npython Inference.py --weight ./weights/FastSAM.pt --image_path ./images/dogs.jpg\n",[153],{"type":18,"tag":83,"props":154,"children":155},{"__ignoreMap":7},[156],{"type":24,"value":151},{"type":18,"tag":26,"props":158,"children":159},{},[160],{"type":18,"tag":39,"props":161,"children":163},{"alt":7,"src":162},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/11/29/ec480d83bb064d2ebb68fc929892e0a2.png",[],{"type":18,"tag":26,"props":165,"children":166},{},[167],{"type":18,"tag":52,"props":168,"children":169},{},[170],{"type":24,"value":171},"FastSAM-MindSpore的关键特性",{"type":18,"tag":26,"props":173,"children":174},{},[175],{"type":18,"tag":52,"props":176,"children":177},{},[178],{"type":24,"value":64},{"type":18,"tag":26,"props":180,"children":181},{},[182],{"type":18,"tag":52,"props":183,"children":184},{},[185],{"type":24,"value":186},"高效的分割解决方案",{"type":18,"tag":26,"props":188,"children":189},{},[190],{"type":24,"value":191},"FastSAM-MindSpore通过将任务转换为实例分割任务，并仅使用SAM作者发布的SA-1B数据集的1/50数据直接训练现有的实例分割方法，实现了与SAM相当的性能。这种方法不仅减少了数据需求，也降低了训练成本。",{"type":18,"tag":26,"props":193,"children":194},{},[195,199,200],{"type":18,"tag":52,"props":196,"children":197},{},[198],{"type":24,"value":101},{"type":24,"value":66},{"type":18,"tag":52,"props":201,"children":202},{},[203],{"type":24,"value":204},"快速部署",{"type":18,"tag":26,"props":206,"children":207},{},[208],{"type":24,"value":209},"FastSAM-MindSpore支持快速部署到边缘设备，使得模型能够快速应用于实际场景中，如列车部件状态检测、矿石颗粒自动分割和器官、组织、细胞分割等。",{"type":18,"tag":26,"props":211,"children":212},{},[213],{"type":24,"value":214},"在昇思大模型平台AI实验室中，你可以快速体验FastSAM-MindSpore的分割效果。你可以上传一张自定义的图片，点击分割按钮，就可以得到一个满意的分割结果。",{"type":18,"tag":216,"props":217,"children":218},"ul",{},[219],{"type":18,"tag":220,"props":221,"children":222},"li",{},[223,225],{"type":24,"value":224},"项目链接：",{"type":18,"tag":226,"props":227,"children":231},"a",{"href":228,"rel":229},"https://xihe.mindspore.cn/projects/Psychedelico/FastSAM-mindspore",[230],"nofollow",[232],{"type":24,"value":228},{"type":18,"tag":26,"props":234,"children":235},{},[236],{"type":18,"tag":52,"props":237,"children":238},{},[239],{"type":24,"value":240},"基于FastSAM-MindSpore实现的应用",{"type":18,"tag":26,"props":242,"children":243},{},[244,248,249],{"type":18,"tag":52,"props":245,"children":246},{},[247],{"type":24,"value":64},{"type":24,"value":66},{"type":18,"tag":52,"props":250,"children":251},{},[252],{"type":24,"value":253},"全列车部件状态检测",{"type":18,"tag":26,"props":255,"children":256},{},[257],{"type":24,"value":258},"通过全景分割，FastSAM-MindSpore能够将列车车体、轮对、制动系统、电气系统等不同部件分割为独立区域，自动分析其状态。同时，对关键部件（如车门、车窗、天线等）进行完整性检测，发现缺失或异常情况。",{"type":18,"tag":26,"props":260,"children":261},{},[262],{"type":18,"tag":39,"props":263,"children":265},{"alt":7,"src":264},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/11/29/2b8bb8dc59f3490a9da944a15dd4ec21.png",[],{"type":18,"tag":26,"props":267,"children":268},{},[269],{"type":18,"tag":52,"props":270,"children":271},{},[272],{"type":24,"value":101},{"type":18,"tag":26,"props":274,"children":275},{},[276],{"type":18,"tag":52,"props":277,"children":278},{},[279],{"type":24,"value":280},"矿石颗粒自动分割",{"type":18,"tag":26,"props":282,"children":283},{},[284],{"type":24,"value":285},"FastSAM-MindSpore的全景分割能力可以将图像中的矿石颗粒逐一分离，包括不同形状、大小、颜色的颗粒。无需人工逐一标注矿石颗粒，大幅提高分析效率。无需额外训练，能够不考虑矿石的其他特征而单独分割出不同种类的矿石，实现粒度检测的自动化。",{"type":18,"tag":26,"props":287,"children":288},{},[289],{"type":18,"tag":39,"props":290,"children":292},{"alt":7,"src":291},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/11/29/2a9cfda337b34ea2b66215caba2a27b0.png",[],{"type":18,"tag":26,"props":294,"children":295},{},[296],{"type":18,"tag":52,"props":297,"children":298},{},[299],{"type":24,"value":135},{"type":18,"tag":26,"props":301,"children":302},{},[303],{"type":18,"tag":52,"props":304,"children":305},{},[306],{"type":24,"value":307},"器官、组织、细胞分割",{"type":18,"tag":26,"props":309,"children":310},{},[311],{"type":24,"value":312},"在显微镜拍摄的图像中，FastSAM-MindSpore能够自动将每个细胞分离出来，明确地定义每个细胞的边界。对组织切片或培养皿中的细胞进行自动化分析，提高了分割效率和精度，有效降低了人工误差。",{"type":18,"tag":26,"props":314,"children":315},{},[316],{"type":18,"tag":39,"props":317,"children":319},{"alt":7,"src":318},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2024/11/29/34981304cf084f0bae6b5348886ba834.png",[],{"title":7,"searchDepth":321,"depth":321,"links":322},4,[],"markdown","content:technology-blogs:zh:3501.md","content","technology-blogs/zh/3501.md","technology-blogs/zh/3501","md",1776506130328]