File size: 2,781 Bytes
f2204f5 a84824c bef29fa a84824c bef29fa a84824c bef29fa a84824c f2204f5 bef29fa 177b95e bef29fa 52b4e33 bef29fa 177b95e bef29fa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
---
language:
- en
license: apache-2.0
tags:
- vision
- image-classification
- generated_from_trainer
datasets:
- imagefolder
pipeline_tag: image-classification
base_model: microsoft/resnet-50
model-index:
- name: fruits-and-vegetables-detector-36
results:
- task:
type: image-classification
name: Image Classification
dataset:
name: imagefolder
type: imagefolder
config: default
split: train
args: default
metrics:
- type: accuracy
value: 0.9721
name: Accuracy
---
# fruits-and-vegetables-detector-36
This model is a fine-tuned version of [microsoft/resnet-50](https://huggingface.co/microsoft/resnet-50).
It achieves the following results on the evaluation set:
- Loss: 0.0014
- Accuracy: 0.9721
## Model description
This Model is a exploration test using the base model resnet-50 from microsoft.
## Intended uses & limitations
This Model was trained with a very small dataset
[kritikseth/fruit-and-vegetable-image-recognition](https://www.kaggle.com/datasets/kritikseth/fruit-and-vegetable-image-recognition) that contains only 36 labels
### How to use
Here is how to use this model to classify an image:
```python
import cv2
import torch
import torchvision.transforms as transforms
from transformers import AutoModelForImageClassification
from PIL import Image
# Load the saved model and tokenizer
model = AutoModelForImageClassification.from_pretrained("jazzmacedo/fruits-and-vegetables-detector-36")
# Get the list of labels from the model's configuration
labels = list(model.config.id2label.values())
# Define the preprocessing transformation
preprocess = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
image_path = "path/to/your/image.jpg"
image = cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
pil_image = Image.fromarray(image) # Convert NumPy array to PIL image
input_tensor = preprocess(pil_image).unsqueeze(0)
# Run the image through the model
outputs = model(input_tensor)
# Get the predicted label index
predicted_idx = torch.argmax(outputs.logits, dim=1).item()
# Get the predicted label text
predicted_label = labels[predicted_idx]
# Print the predicted label
print("Detected label:", predicted_label)
```
## Training and evaluation data
Dataset Source: https://www.kaggle.com/datasets/kritikseth/fruit-and-vegetable-image-recognition
## Training procedure
### Training hyperparameters
The following hyperparameters were used during training:
- learning_rate: 0.001
- train_batch_size: 32
- eval_batch_size: 32
- seed: 42
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: linear
- num_epochs: 10
|