| layout | tutorial_hands_on | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| title | SAM3 – AI-based Semantic Segmentation of marine biodiversity Images and Videos | ||||||||||||||||
| questions |
|
||||||||||||||||
| objectives |
|
||||||||||||||||
| time_estimation | 20M | ||||||||||||||||
| key_points |
|
||||||||||||||||
| tags |
|
||||||||||||||||
| contributions |
|
||||||||||||||||
| lang | en | ||||||||||||||||
| translations |
|
||||||||||||||||
| subtopic | ecologymediaannotation |
This tutorial will guide you through using the {% tool SAM3 %} (Segment Anything Model 3) tool on Galaxy. SAM3 can automatically detect and segment objects in images or videos using text prompts, with no specific training required.
We will work through two concrete examples from the Moorev project:
- A photograph of a jellyfish (Pelagia noctiluca)
- A video of shrimps
In this tutorial, we will cover:
- TOC {:toc}
{: .agenda}
Quick introduction to how Galaxy works
Log in to Galaxy
- Open your preferred web browser
- Go to your Galaxy instance (please verify that the Galaxy instance you want to use propose SAM3 tool as Galaxy Europe is doing)
- Log in or create an account
This screenshot shows the Galaxy Ecology instance, available at usegalaxy.eu
The Galaxy home page is divided into 3 panels:
- Tools on the left
- The visualisation panel in the centre
- The history of analyses and files on the right
The first time you use Galaxy, there will be no files in your history panel. {: .details}
Before running SAM3 Galaxy tool, you need to import the following files into Galaxy:
- The jellyfish photo:
https://zenodo.org/records/19890809/files/Moorev-jellyfish.jpg - The shrimp video:
https://zenodo.org/records/19891364/files/2024-09-20-PorzBreign-shrimps.mp4
{% snippet faqs/galaxy/datasets_import_via_link.md %}
File format not recognised?
If you want to try with other files, make sure the file extension is correct before uploading, as Galaxy may not detect it automatically. In that case, two options:
- During upload, specify the format using the Type (set all) field
- From the history, click the {% icon galaxy-pencil %} pencil icon, go to the Datatype tab and search for your extension
{: .warning}
In this first section, we will run SAM3 Galaxy tool on the photo Moorev-jellyfish.jpg to detect and segment the jellyfish.
How to access the SAM3 tool?
Type SAM3 in the tool search bar at the top left, then click on the tool in the results.
{: .tip}
Segment the jellyfish in the photo
{% tool SAM3 Semantic Segmentation %} with these parameters:
- {% icon param-file %} "Model data":
Segment Anything Model 3 (SAM 3)(default)- {% icon param-select %} "Input type":
One or more images(default)- {% icon param-file %} "Input images":
Moorev-jellyfish.jpg- {% icon param-select %} "Output formats":
COCO- {% icon param-text %} "Text prompt":
jellyfish- {% icon version%} "Confidence threshold":
0.5- {% icon version %} "Video frame stride":
5(default)- {% icon param-toggle %} "Show bounding boxes on annotated output":
Yes(default)- {% icon param-toggle %} "Normalize outputs?":
No(default)How to write a good prompt?
The text prompt should describe the object to segment in English, using simple and precise terms. To detect multiple classes at once, separate them with commas:
jellyfish, shrimp, fishAvoid overly vague descriptions like
animalif you are specifically looking for a jellyfish. You can also use more descriptive prompt likesmall blue fish, but results may vary depending on the objects you want to detect. {: .tip}Click Run Tool
Processing time
Processing may take a few minutes depending on the image size and the resources available on the server. Wait until the outputs appear in green in the history.
{: .comment}
Once processing is complete, the following outputs appear in your history:
- COCO Annotation: the
annotations.jsonfile containing the segmentation masks- Annotated Outputs: the collection of annotated images with overlaid masks
Viewing the annotated result
You should see the jellyfish outlined with a coloured mask and a bounding box.
Display the image in the history
Click on Annotated Outputs in the history panel:
{: style="width:50%; display:block; margin:auto;"}
Then use the {% icon galaxy-eye %} icon to display the image in the central panel:
{: style="width:50%; display:block; margin:auto;"}
Or click {% icon galaxy-save %} to download the file directly. {: .tip}
Exploring the COCO file
- Look at the content of your COCO Annotation file in your history
- Use {% icon galaxy-eye %} to view the JSON, or {% icon galaxy-save %} to download it
The file contains the
images,annotations, andcategoriesfields. Each annotation includes:
segmentation: the polygon coordinates of the maskbbox: the bounding box[x, y, width, height]category_id: the identifier of the detected class (1=jellyfish)Export to YOLO format (optional)
If you need to train a YOLO model with your annotations, you can export results in YOLO format in addition to COCO. In the {% icon param-select %} "Output formats" parameter, select
COCOand/orYOLO segmentation masksand/orYOLO bounding boxes.YOLO segmentation format
Each line in a YOLO segmentation label file follows this format:
<class_id> <x1> <y1> <x2> <y2> ... <xn> <yn>Coordinates are normalised between 0 and 1 relative to the image dimensions. Example for a jellyfish (class 0):
0 0.423 0.312 0.456 0.298 ...{: .details}
{: .details}
{: .hands_on}
In this second section, we will execute SAM3 tool to the video 2024-09-20-PorzBreign-shrimps.mp4. SAM3 model analyses the video frame by frame, tracking the shrimps over time.
Segment the shrimps in the video
{% tool SAM3 Semantic Segmentation %} with these parameters:
- {% icon param-file %} "Model data":
Segment Anything Model 3 (SAM 3)(default)- {% icon param-select %} "Input type":
One video- {% icon param-file %} "Input video file":
2024-09-20-PorzBreign-shrimps.mp4- {% icon param-select %} "Video quality":
"2000k" = video bitrate 2000 kbps (480p~720p)- {% icon param-select %} "COCO output mode":
Annotate the video — one COCO entry per frame, referencing the video file(default)- {% icon param-text %} "Text prompt":
shrimp- {% icon version %} "Confidence threshold":
0.25(default)- {% icon version %} "Video frame stride":
5(default)- {% icon param-toggle %} "Show bounding boxes on annotated output":
Yes(default)- {% icon param-toggle %} "Normalize outputs?":
No(default)Understanding the video parameters
{% icon version %} "Video frame stride": determines how often frames are analysed. A stride of
5means one frame in every five is processed.
- Low stride (1–3): more precise analysis, but longer processing time
- High stride (10–30): faster processing, useful for long videos where objects move slowly
{% icon param-select %} "Video quality": controls the quality of the annotated output video, with no impact on processing speed or annotations.
{% icon param-select %} "COCO output mode": controls how COCO annotations are generated.
Annotate the video: one COCO entry per frame, referencing the video file (default)Annotate extracted frames: saves frames as JPGs with one COCO entry per image — useful for pre-processing, for example with the {% tool AnyLabeling Interactive %} tool as shown in the Moorev tutorial{: .tip}
Click Execute
Video processing time
Video processing takes significantly longer than processing a single image. For a video of a few minutes, expect between 5 and 20 minutes depending on the server and the stride chosen.
{: .comment}
The following outputs appear in your history:
- COCO Annotation: the JSON file with annotations for each processed frame
- Annotated Outputs: the annotated video with segmentation masks overlaid frame by frame
Viewing the annotated video
- Click on Annotated Outputs in the history panel
- Click {% icon galaxy-eye %}
- Click {% icon galaxy-visualise %}
- Select Media Player
Display the video in Galaxy
{: style="width:75%; display:block; margin:auto;"}
Video not loading?
The video may not load in Galaxy for several reasons:
- The file is too large for your internet connection
In that case, use {% icon galaxy-save %} to download the video and play it locally with your usual media player.
{: .warning}{: .tip}
You will see the shrimps tracked with a coloured segmentation mask throughout the video.
Downloading the annotated video
- Click the Annotated Outputs collection
- Use {% icon galaxy-save %} to download the
.mp4videoLimitations of SAM3 and pre-processing
SAM3 tool is a first attempt to propose prompt-based Galaxy tool. As it is using SAM3 model, you can have highly heterogenous results in term of quality depending on the objects you are searching to segment, notably if such kind of object can be on data used to train the SAM3 model. Adjusting the confidence threshold can help, but it does not solve everything. Pre-processing your images or videos is often necessary to improve results.
To learn more, check out the dedicated tutorial: Tuto Moorev{: .comment}
{: .hands_on}
You now know how to use SAM3 Galaxy tool to:
- Segment objects in an image using a simple text prompt
- Segment objects in a video frame by frame with temporal tracking
- Export results in COCO format (for annotation and evaluation tools) or YOLO format (for model training)







