How to Run Zoo Models¶
Use this guide to run CoastSeg zoo models on imagery you already downloaded.
Note
Before you start:
- Download your imagery from Google Earth Engine first.
- The zoo workflow processes one region of interest (ROI) at a time.
- Install the zoo workflow first by following Install the Zoo Workflow.
Phase 1: Download a Model¶
Before you can run the zoo workflow, you need to download at least one model.
-
Activate your main CoastSeg environment.
1conda activate coastseg -
Open the notebook
SDS_zoo_classifier.ipynb. -
Use the download button in the notebook to download a model.
- You can also download a model with the script
download_zoo_model.py. If you want to use the script instead of the notebook, see How to Download Models.
- You can also download a model with the script
-
Confirm that the model folder was saved in
CoastSeg/models.
Phase 2: Activate the Zoo Environment¶
Choose one setup method.
Option 1: Pixi (Recommended)¶
1 2 3 | |
On the first run, pixi shell installs the environment and then activates it.
You will know the environment is active when you see (segmentation_workflow) in the terminal.
Option 2: Conda¶
1 2 3 | |
Phase 3: Run the Models¶
Before running the command below, make sure:
- The
(segmentation_workflow)environment is active - You are inside the
segmentation_workflowfolder
Command¶
1 2 3 4 5 6 7 | |
What the command means¶
-i,--input-dir: Folder containing the input images. These can bejpg,png, ortiffiles.-o,--output-dir: Folder where the model outputs will be saved.-m,--model: Folder containing the model files, including the.h5weights and.jsonconfig files.
Default behavior¶
--implementation BESTis used unless you choose something else- A GPU is used automatically if one is available
Example¶
1 2 3 4 | |
Real example¶
1 2 3 4 | |
This example runs the model global_segformer_RGB_4class_14036903 on the images in C:\CoastSeg\data\ID_rnv2_datetime01-16-26__03_50_41\jpg_files\preprocessed\RGB and saves the results to C:\CoastSeg\sessions\model_outputs_session.
Outputs¶
All results are written to <output_dir>.
For each input image, the workflow creates:
<image_stem>_predseg.png: A colorized segmentation mask<image_stem>_res.npz: A compressed NumPy file containing the predicted labels and metadata
It also creates these summary files for the full run:
model_settings.json: The settings used for the run, including implementation mode, model type, and GPU usagemodel_info.json: Information about the model, including the model directory, class names, and water-class indicessegmentation_summary.json: A summary of the run, including processed images, output files, skipped files, and failures
The output folder keeps the same relative folder structure as the input folder.
Phase 4: Extract Shorelines from the Segmentations¶
After the model finishes, you can extract shorelines from the segmentation outputs.
To do this, use the script 3_zoo_workflow_extract_shorelines.py in the main CoastSeg folder.
Or you can use the SDS_zoo_classifier.ipynb and use the workflow b option to extract shorelines from the folder of segmentations you just created.
- Exit or deactivate the
segmentation_workflowenvironment. -
Go back to the main CoastSeg folder.
1cd .. -
Activate your main CoastSeg environment.
Use one of these options:
1conda activate CoastSegor
1pixi shell -
Open
3_zoo_workflow_extract_shorelines.pyin a code editor such as VS Code.- Read the instructions in the script for a guide on how to use it.
- Update the script so it points to the folder containing your segmentation outputs.
- Run the script.