Image Segmentation
ONNX
sam2
computer-vision
carpet-analysis
defect-detection
unet
image-classification
Instructions to use yosedie/carpet-analysis-api with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sam2
How to use yosedie/carpet-analysis-api with sam2:
# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained("yosedie/carpet-analysis-api") 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("yosedie/carpet-analysis-api") 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
π§Ά Carpet Analysis System - Deep Learning Models
A collection of pre-trained deep learning models optimized for real-time carpet quality inspection, style classification, material detection, and surface segmentation.
Optimized with ONNX Runtime for low latency and efficient deployment on both CPU and GPU backends.
π Live Demo & API Endpoint
These models power the active production backend deployed on Hugging Face Spaces:
- Live Space: yosedie/carpet-analysis-api
- Interactive Swagger UI: https://yosedie-carpet-analysis-api.hf.space/docs
π¦ Model Portfolio
| Model File | Architecture | Task / Objective | Input Resolution | Format |
|---|---|---|---|---|
unet_model.onnx |
U-Net | Carpet surface segmentation & defect coverage ratio calculation | 512x512 | ONNX |
cnn_a_model.onnx |
Custom CNN | Carpet Style Classification (Asia, Malaysia, Mie, Persia, Polos, Sejadah) | 224x224 | ONNX |
cnn_b_model.onnx |
Custom CNN | Fiber Material Identification (Polypropylene, Nylon, Polyester) | 224x224 | ONNX |
sam2_hiera_base_plus.pt |
SAM 2 (Hiera Base+) | Zero-shot promptable segmentation for fine-grained boundary extraction | Multi-scale | PyTorch / SAM 2 |
β‘ Quickstart: Python & ONNX Runtime
import onnxruntime as ort
import numpy as np
from PIL import Image
# 1. Initialize U-Net Inference Session
session = ort.InferenceSession("unet_model.onnx", providers=["CPUExecutionProvider"])
# 2. Preprocess Input Image
image = Image.open("sample_carpet.jpg").convert("RGB").resize((512, 512))
img_data = np.array(image, dtype=np.float32) / 255.0
img_data = np.transpose(img_data, (2, 0, 1))
img_data = np.expand_dims(img_data, axis=0)
# 3. Execute Model Prediction
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name
prediction = session.run([output_name], {input_name: img_data})[0]
# 4. Generate Binary Mask
segmentation_mask = (prediction[0, 0] > 0.5).astype(np.uint8) * 255
print("Inference successful. Mask dimension:", segmentation_mask.shape)
π€ Author
- Developer: yosedie
- GitHub: https://github.com/yosedie