Update README.md
Browse files
README.md
CHANGED
@@ -1,33 +1,76 @@
|
|
1 |
---
|
2 |
tags:
|
3 |
- image-classification
|
4 |
-
-
|
|
|
|
|
5 |
datasets:
|
6 |
- Iris314/Food_tomatoes_dataset
|
7 |
-
license: mit
|
8 |
---
|
9 |
|
10 |
-
#
|
11 |
|
12 |
-
This
|
13 |
|
14 |
-
##
|
15 |
|
16 |
-
The model was
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
The best hyperparameters found by Keras Tuner were:
|
23 |
```
|
24 |
import tensorflow as tf
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
```
|
|
|
1 |
---
|
2 |
tags:
|
3 |
- image-classification
|
4 |
+
- tensorflow
|
5 |
+
- keras-tuner
|
6 |
+
- computer-vision
|
7 |
datasets:
|
8 |
- Iris314/Food_tomatoes_dataset
|
|
|
9 |
---
|
10 |
|
11 |
+
# Tomato Binary Classification Model
|
12 |
|
13 |
+
This model is a convolutional neural network trained to classify images of tomatoes into two categories (presumably ripe and unripe, based on the dataset name and binary classification setup).
|
14 |
|
15 |
+
## Model Architecture
|
16 |
|
17 |
+
The model architecture was determined using Keras Tuner's Hyperband algorithm. Based on the previous tuning results, the best hyperparameters found were:
|
18 |
+
- `conv_blocks`: 2
|
19 |
+
- `filters_0`: 32
|
20 |
+
- `dense_units`: 64
|
21 |
+
- `dropout`: 0.1
|
22 |
+
- `lr`: 0.001
|
23 |
+
- `filters_1`: 16
|
24 |
|
25 |
+
The model consists of:
|
26 |
+
- Data augmentation layers (RandomFlip, RandomRotation, RandomZoom) applied during training.
|
27 |
+
- Two convolutional blocks:
|
28 |
+
- The first block has 32 filters, a 3x3 kernel, ReLU activation, and MaxPooling.
|
29 |
+
- The second block has 16 filters, a 3x3 kernel, ReLU activation, and MaxPooling.
|
30 |
+
- A Flatten layer.
|
31 |
+
- A dense layer with 64 units and ReLU activation.
|
32 |
+
- A Dropout layer with a rate of 0.1.
|
33 |
+
- An output layer with a single unit and a sigmoid activation function for binary classification.
|
34 |
|
35 |
+
## Training
|
36 |
+
|
37 |
+
- **Dataset:** Iris314/Food_tomatoes_dataset. The `augmented` split was used for training, and the `original` split was used for validation.
|
38 |
+
- **Input Resolution:** Images are resized to 128x128 pixels.
|
39 |
+
- **Preprocessing:** Images are converted to RGB and pixel values are scaled to the range [0, 1].
|
40 |
+
- **Optimizer:** Adam with a learning rate of 0.001 (based on the best hyperparameters).
|
41 |
+
- **Loss Function:** Binary Crossentropy.
|
42 |
+
- **Metrics:** Accuracy was used as the evaluation metric.
|
43 |
+
- **Early Stopping:** Training was stopped early if the validation loss did not improve for 3 consecutive epochs. The model was trained for a maximum of 15 epochs.
|
44 |
+
|
45 |
+
## Performance
|
46 |
+
|
47 |
+
Based on the evaluation on the validation set, the model achieved the following performance:
|
48 |
+
|
49 |
+
- **Accuracy:** 1.00
|
50 |
+
- **Loss:** 0.0079
|
51 |
+
|
52 |
+
**Classification Report:**
|
53 |
|
|
|
54 |
```
|
55 |
import tensorflow as tf
|
56 |
+
from PIL import Image
|
57 |
+
import numpy as np
|
58 |
+
|
59 |
+
#Load the model
|
60 |
+
model = tf.keras.models.load_model('best_tomato_model.keras')
|
61 |
+
|
62 |
+
#Load and preprocess an image
|
63 |
+
img_path = 'path/to/your/image.jpg' # Replace with your image path
|
64 |
+
img = Image.open(img_path).convert('RGB').resize((128, 128))
|
65 |
+
img_array = np.array(img) / 255.0
|
66 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
67 |
+
|
68 |
+
#Make a prediction
|
69 |
+
prediction = model.predict(img_array)
|
70 |
+
|
71 |
+
#Interpret the prediction
|
72 |
+
predicted_class = int(prediction > 0.5)
|
73 |
+
|
74 |
+
print(f"Prediction: {prediction[0][0]:.4f}")
|
75 |
+
print(f"Predicted class: {predicted_class}")
|
76 |
```
|