| --- |
| license: apache-2.0 |
| tags: |
| - vision |
| - image-classification |
| - waste-classification |
| - vit |
| - pytorch |
| - fine-tuned |
| --- |
| |
| # Vision Transformer (ViT) para Clasificaci贸n de Residuos |
|
|
| ## Descripci贸n |
|
|
| Modelo Vision Transformer (ViT) afinado sobre el dataset de segregaci贸n de residuos para |
| clasificar im谩genes en 9 categor铆as. Desarrollado como parte de un proyecto de aprendizaje |
| autom谩tico en el Instituto Tecnol贸gico de Costa Rica (ITCR). |
|
|
| Basado en `google/vit-base-patch16-224-in21k` con ajuste fino mediante transfer learning. |
|
|
| ## Resultados de Entrenamiento |
|
|
| ### Configuraci贸n |
|
|
| - **Modelo base**: google/vit-base-patch16-224-in21k |
| - **脡pocas**: 3 |
| - **Tasa de aprendizaje**: 0.0002 |
| - **Tama帽o de lote**: 16 |
| - **Optimizador**: AdamW con warmup |
| - **Regularizaci贸n (weight decay)**: 0.01 |
|
|
| ### Datos |
|
|
| - **Entrenamiento**: 3044 im谩genes |
| - **Validaci贸n**: 762 im谩genes |
| - **Clases**: 9 |
|
|
| ### M茅tricas |
|
|
| - **P茅rdida de entrenamiento**: 1.6462 |
| - **Evaluaci贸n**: por 茅poca |
| - **Criterio de guardado**: mejor accuracy en validaci贸n |
|
|
| ## Metodolog铆a |
|
|
| El afinamiento se realiz贸 en las siguientes etapas: |
|
|
| 1. **Preprocesamiento**: normalizaci贸n con `ViTImageProcessor` (224脳224 px) |
| 2. **Transfer learning**: pesos preentrenados en ImageNet-21k |
| 3. **Afinamiento**: tasa de aprendizaje baja (2e-4) para preservar representaciones aprendidas |
| 4. **Regularizaci贸n**: weight decay (0.01) y warmup lineal (10% de pasos) |
| 5. **Parada anticipada**: monitoreo de accuracy en validaci贸n |
|
|
| ## Clases |
|
|
| | ID | Clase | |
| |----|---------------------| |
| | 0 | Cardboard | |
| | 1 | Food Organics | |
| | 2 | Glass | |
| | 3 | Metal | |
| | 4 | Miscellaneous Trash | |
| | 5 | Paper | |
| | 6 | Plastic | |
| | 7 | Textile Trash | |
| | 8 | Vegetation | |
|
|
| ## Uso |
|
|
| ```python |
| from transformers import ViTForImageClassification, ViTImageProcessor |
| from PIL import Image |
| |
| processor = ViTImageProcessor.from_pretrained("ddompe/vit-waste-classification") |
| model = ViTForImageClassification.from_pretrained("ddompe/vit-waste-classification") |
| |
| imagen = Image.open("residuo.jpg").convert("RGB") |
| entradas = processor(images=imagen, return_tensors="pt") |
| salidas = model(**entradas) |
| clase_pred = salidas.logits.argmax(-1).item() |
| print(model.config.id2label[clase_pred]) |
| ``` |
|
|