Instructions to use Inseop97/mp-segmentation-models with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ultralytics
How to use Inseop97/mp-segmentation-models with ultralytics:
from huggingface_hub import hf_hub_download from ultralytics import YOLO # pick the weights file from this repo's "Files and versions" tab weights = hf_hub_download("Inseop97/mp-segmentation-models", "<weights>.pt") model = YOLO(weights) source = 'http://images.cocodataset.org/val2017/000000039769.jpg' model.predict(source=source, save=True) - sam2
How to use Inseop97/mp-segmentation-models with sam2:
# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained("Inseop97/mp-segmentation-models") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): predictor.set_image(<your_image>) masks, _, _ = predictor.predict(<input_prompts>)# Use SAM2 with videos import torch from sam2.sam2_video_predictor import SAM2VideoPredictor predictor = SAM2VideoPredictor.from_pretrained("Inseop97/mp-segmentation-models") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): state = predictor.init_state(<your_video>) # add new prompts and instantly get the output on the same frame frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>) # propagate the prompts to get masklets throughout the video for frame_idx, object_ids, masks in predictor.propagate_in_video(state): ... - Notebooks
- Google Colab
- Kaggle
# Use SAM2 with images
import torch
from sam2.sam2_image_predictor import SAM2ImagePredictor
predictor = SAM2ImagePredictor.from_pretrained("Inseop97/mp-segmentation-models")
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
predictor.set_image(<your_image>)
masks, _, _ = predictor.predict(<input_prompts>)# Use SAM2 with videos
import torch
from sam2.sam2_video_predictor import SAM2VideoPredictor
predictor = SAM2VideoPredictor.from_pretrained("Inseop97/mp-segmentation-models")
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
state = predictor.init_state(<your_video>)
# add new prompts and instantly get the output on the same frame
frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>)
# propagate the prompts to get masklets throughout the video
for frame_idx, object_ids, masks in predictor.propagate_in_video(state):
...Microplastic segmentation models
This access-controlled repository stores the YOLO checkpoints used by the microplastic microscopy pipeline in https://github.com/Inseop97/mp-segmentation.
Deployment checkpoint
yolo11n_detector/model_deployment.pt
The deployment detector was trained on all curated detection data after model selection. It localizes particles as a single class. During inference, each box is passed to SAM2 as a prompt; circularity, aspect ratio, and normalized width are then extracted from the mask and classified with the Logistic Regression model distributed in the GitHub repository.
Deployment-training metrics are diagnostic and must not be reported as generalization performance.
Manuscript checkpoints
paper_checkpoints/
βββ yolo11n_seg/fold0..fold4/
βββ yolo11n_detector_sam/fold0..fold4/
Each fold directory contains best.pt and eval_summary.json. These held-out
fold checkpoints reproduce the manuscript comparison between the YOLO11n-seg
baseline and the YOLO11n detector β box-prompted SAM2 pipeline.
Download the deployment checkpoint:
python scripts/download_models.py
Download all manuscript checkpoints:
python scripts/download_models.py --paper-checkpoints
Authenticate first with hf auth login using an account that has access.
Intended use and limitations
These checkpoints are intended for microscopy images prepared consistently with the study protocol. Performance can degrade for very small, blurred, overlapping, or strongly out-of-distribution particles. The morphology-based PS, PP, and PET output does not replace chemical polymer identification.
- Downloads last month
- -
# Gated model: Login with a HF token with gated access permission hf auth login