The Reciclaje AI model is publicly available on HuggingFace, making it easy to access, download, and integrate into your projects. This page provides guidance on accessing the model and using it in your applications.
Use the HuggingFace Hub Python library for programmatic access:
pip install huggingface-hub
Then download the model in your Python code:
from huggingface_hub import hf_hub_download# Download the model filemodel_path = hf_hub_download( repo_id="AprendeIngenia/recyclingAI", filename="best.pt", cache_dir="./models")print(f"Model downloaded to: {model_path}")
Once downloaded, use the model with Ultralytics YOLO:
from ultralytics import YOLOimport cv2# Load the modelmodel = YOLO('path/to/best.pt')# Class namesclsName = ['Metal', 'Glass', 'Plastic', 'Carton', 'Medical']# Run inference on an imageimage = cv2.imread('waste_image.jpg')results = model(image, stream=True, verbose=False)# Process resultsfor res in results: boxes = res.boxes for box in boxes: # Get class and confidence cls = int(box.cls[0]) conf = float(box.conf[0]) print(f"Detected: {clsName[cls]} with {conf*100:.1f}% confidence")
from ultralytics import YOLO# Load model on GPUmodel = YOLO('best.pt')model.to('cuda') # Move model to GPU# Verify GPU usageimport torchprint(f"Using GPU: {torch.cuda.is_available()}")
images = ['img1.jpg', 'img2.jpg', 'img3.jpg']# Batch inferenceresults = model(images, stream=True)for result in results: # Process each result result.save() # Save annotated image