jazzmacedo commited on
Commit
bef29fa
1 Parent(s): f2204f5

chore: add model and update readme

Browse files
Files changed (3) hide show
  1. README.md +105 -1
  2. config.json +110 -0
  3. pytorch_model.bin +3 -0
README.md CHANGED
@@ -1,3 +1,107 @@
1
  ---
2
- license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: apache-2.0
3
+ tags:
4
+ - vision
5
+ - image-classification
6
+ - generated_from_trainer
7
+ datasets:
8
+ - imagefolder
9
+ model-index:
10
+ - name: vegetables-detector
11
+ results:
12
+ - task:
13
+ name: Image Classification
14
+ type: image-classification
15
+ dataset:
16
+ name: imagefolder
17
+ type: imagefolder
18
+ config: default
19
+ split: train
20
+ args: default
21
+ metrics:
22
+ - name: Accuracy
23
+ type: accuracy
24
+ value: 0.9721
25
+ language:
26
+ - en
27
+ pipeline_tag: image-classification
28
  ---
29
+
30
+ # Vegetables Detector
31
+
32
+ This model is a fine-tuned version of [microsoft/resnet-50](https://huggingface.co/microsoft/resnet-50).
33
+
34
+ It achieves the following results on the evaluation set:
35
+
36
+ - Loss: 0.0014
37
+ - Accuracy: 0.9721
38
+
39
+ ## Model description
40
+
41
+ This Model is a exploration test using the base model resnet-50 from microsoft.
42
+
43
+ ## Intended uses & limitations
44
+
45
+ This Model was trained with a very small dataset
46
+ [kritikseth/fruit-and-vegetable-image-recognition](https://www.kaggle.com/datasets/kritikseth/fruit-and-vegetable-image-recognition) and it was created to validate the resnet-50 fine-tuning capabilities
47
+
48
+ ### How to use
49
+
50
+ Here is how to use this model to classify an image:
51
+
52
+ ```python
53
+ import cv2
54
+ import torch
55
+ import torchvision.transforms as transforms
56
+ from transformers import AutoModelForImageClassification
57
+ from PIL import Image
58
+
59
+ # Load the saved model and tokenizer
60
+ model = AutoModelForImageClassification.from_pretrained("jazzmacedo/vegetables-detector")
61
+
62
+ # Get the list of labels from the model's configuration
63
+ labels = list(model.config.id2label.values())
64
+
65
+ # Define the preprocessing transformation
66
+ preprocess = transforms.Compose([
67
+ transforms.Resize((224, 224)),
68
+ transforms.ToTensor(),
69
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
70
+ ])
71
+
72
+ image_path = "path/to/your/image.jpg"
73
+ image = cv2.imread(image_path)
74
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
75
+ pil_image = Image.fromarray(image) # Convert NumPy array to PIL image
76
+ input_tensor = preprocess(pil_image).unsqueeze(0)
77
+
78
+ # Run the image through the model
79
+ outputs = model(input_tensor)
80
+
81
+ # Get the predicted label index
82
+ predicted_idx = torch.argmax(outputs.logits, dim=1).item()
83
+
84
+ # Get the predicted label text
85
+ predicted_label = labels[predicted_idx]
86
+
87
+ # Print the predicted label
88
+ print("Detected label:", predicted_label)
89
+ ```
90
+
91
+ ## Training and evaluation data
92
+
93
+ Dataset Source: https://www.kaggle.com/datasets/kritikseth/fruit-and-vegetable-image-recognition
94
+
95
+ ## Training procedure
96
+
97
+ ### Training hyperparameters
98
+
99
+ The following hyperparameters were used during training:
100
+
101
+ - learning_rate: 0.001
102
+ - train_batch_size: 32
103
+ - eval_batch_size: 32
104
+ - seed: 42
105
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
106
+ - lr_scheduler_type: linear
107
+ - num_epochs: 10
config.json ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "microsoft/resnet-50",
3
+ "architectures": [
4
+ "ResNetForImageClassification"
5
+ ],
6
+ "depths": [
7
+ 3,
8
+ 4,
9
+ 6,
10
+ 3
11
+ ],
12
+ "downsample_in_first_stage": false,
13
+ "embedding_size": 64,
14
+ "hidden_act": "relu",
15
+ "hidden_sizes": [
16
+ 256,
17
+ 512,
18
+ 1024,
19
+ 2048
20
+ ],
21
+ "id2label": {
22
+ "0": "apple",
23
+ "1": "banana",
24
+ "2": "beetroot",
25
+ "3": "bell pepper",
26
+ "4": "cabbage",
27
+ "5": "capsicum",
28
+ "6": "carrot",
29
+ "7": "cauliflower",
30
+ "8": "chilli pepper",
31
+ "9": "corn",
32
+ "10": "cucumber",
33
+ "11": "eggplant",
34
+ "12": "garlic",
35
+ "13": "ginger",
36
+ "14": "grapes",
37
+ "15": "jalepeno",
38
+ "16": "kiwi",
39
+ "17": "lemon",
40
+ "18": "lettuce",
41
+ "19": "mango",
42
+ "20": "onion",
43
+ "21": "orange",
44
+ "22": "paprika",
45
+ "23": "pear",
46
+ "24": "peas",
47
+ "25": "pineapple",
48
+ "26": "pomegranate",
49
+ "27": "potato",
50
+ "28": "raddish",
51
+ "29": "soy beans",
52
+ "30": "spinach",
53
+ "31": "sweetcorn",
54
+ "32": "sweetpotato",
55
+ "33": "tomato",
56
+ "34": "turnip",
57
+ "35": "watermelon"
58
+ },
59
+ "label2id": {
60
+ "apple": 0,
61
+ "banana": 1,
62
+ "beetroot": 2,
63
+ "bell pepper": 3,
64
+ "cabbage": 4,
65
+ "capsicum": 5,
66
+ "carrot": 6,
67
+ "cauliflower": 7,
68
+ "chilli pepper": 8,
69
+ "corn": 9,
70
+ "cucumber": 10,
71
+ "eggplant": 11,
72
+ "garlic": 12,
73
+ "ginger": 13,
74
+ "grapes": 14,
75
+ "jalepeno": 15,
76
+ "kiwi": 16,
77
+ "lemon": 17,
78
+ "lettuce": 18,
79
+ "mango": 19,
80
+ "onion": 20,
81
+ "orange": 21,
82
+ "paprika": 22,
83
+ "pear": 23,
84
+ "peas": 24,
85
+ "pineapple": 25,
86
+ "pomegranate": 26,
87
+ "potato": 27,
88
+ "raddish": 28,
89
+ "soy beans": 29,
90
+ "spinach": 30,
91
+ "sweetcorn": 31,
92
+ "sweetpotato": 32,
93
+ "tomato": 33,
94
+ "turnip": 34,
95
+ "watermelon": 35
96
+ },
97
+ "layer_type": "bottleneck",
98
+ "model_type": "resnet",
99
+ "num_channels": 3,
100
+ "out_features": null,
101
+ "stage_names": [
102
+ "stem",
103
+ "stage1",
104
+ "stage2",
105
+ "stage3",
106
+ "stage4"
107
+ ],
108
+ "torch_dtype": "float32",
109
+ "transformers_version": "4.26.1"
110
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cc4eeb24292742187b926b6d573f5b7b9fb76b12bd8efd8c92b615d9916989c3
3
+ size 94649165