7-11 MobileSAM Development

Learning Objectives

SAM (Segment Anything Model) is a powerful image segmentation model developed by Meta AI that supports segmentation based on various prompts such as text and coordinate points.

However, due to its large model size, it is challenging to run smoothly on the Jetson Orin platform. Therefore, a lightweight version called MobileSAM is used to achieve similar segmentation capabilities while balancing performance and efficiency.

Initial environment setup

sudo apt update && sudo apt install vim

pip3 install ultralytics 
pip3 install numpy==1.26.4 

Run MobileSAM

1. Create an empty folder and download test images

mkdir -p MobileSAM && cd MobileSAM

wget https://github.com/ultralytics/ultralytics/blob/main/ultralytics/assets/zidane.jpg?raw=true -O zidane.jpg

2. Create a test Python file

touch demo.py && vim demo.py

3. Paste the following code

from ultralytics import SAM

# Load the model
model = SAM("mobile_sam.pt")

# Predict a segment based on a single point prompt
model.predict("zidane.jpg", points=[900, 370], labels=[1], save=Ture)

4. Run and verify the results

// The results will be automatically saved to runs/segment/predict
python3 demo.py

 

 

Copyright © 2026 YUAN High-Tech Development Co., Ltd.
All rights reserved.