rlogh commited on
Commit
90250a1
·
verified ·
1 Parent(s): 864ec31

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +134 -0
  2. config.json +33 -0
  3. pytorch_model.bin +3 -0
  4. training_results.json +98 -0
README.md ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - image-classification
5
+ - cheese
6
+ - texture
7
+ - computer-vision
8
+ - pytorch
9
+ - transfer-learning
10
+ - automl
11
+ datasets:
12
+ - aslan-ng/cheese-image
13
+ metrics:
14
+ - accuracy
15
+ model-index:
16
+ - name: Cheese Texture Classifier (AutoML)
17
+ results:
18
+ - task:
19
+ type: image-classification
20
+ name: Cheese Texture Classification
21
+ dataset:
22
+ type: aslan-ng/cheese-image
23
+ name: Cheese Image Dataset
24
+ metrics:
25
+ - type: accuracy
26
+ value: 80.00
27
+ name: Test Accuracy
28
+ ---
29
+
30
+ # Cheese Texture Classifier (AutoML)
31
+
32
+ This model performs 4-class texture classification on cheese images using AutoML-optimized transfer learning.
33
+
34
+ ## Model Description
35
+
36
+ - **Architecture**: Transfer Learning with resnet34
37
+ - **Task**: 4-class texture classification (Low, Medium-Low, Medium-High, High texture)
38
+ - **Input**: 224x224 RGB images
39
+ - **Output**: 4-class probability distribution
40
+
41
+ ## Training Details
42
+
43
+ - **Dataset**: [aslan-ng/cheese-image](https://huggingface.co/datasets/aslan-ng/cheese-image)
44
+ - **AutoML Method**: Optuna with 20 trials
45
+ - **Transfer Learning**: Pre-trained resnet34 backbone
46
+ - **Early Stopping**: Yes (patience=10)
47
+ - **Max Epochs**: 50
48
+
49
+ ## Performance
50
+
51
+ - **Test Accuracy**: 80.00%
52
+ - **Validation Accuracy**: 50.00%
53
+ - **Test Loss**: 1.6345
54
+
55
+ ## Best Hyperparameters (AutoML Optimized)
56
+
57
+ ```json
58
+ {
59
+ "model_name": "resnet34",
60
+ "dropout_rate": 0.4682019316470914,
61
+ "learning_rate": 0.00027817005315620047,
62
+ "weight_decay": 1.4677013775851028e-05,
63
+ "batch_size": 2
64
+ }
65
+ ```
66
+
67
+ ## Usage
68
+
69
+ ```python
70
+ import torch
71
+ import torch.nn as nn
72
+ from PIL import Image
73
+ import torchvision.transforms as transforms
74
+ import torchvision.models as models
75
+
76
+ # Load model (define TransferLearningModel class first)
77
+ model = TransferLearningModel(num_classes=4, dropout_rate=0.4682019316470914, model_name='resnet34')
78
+ model.load_state_dict(torch.load('pytorch_model.bin'))
79
+ model.eval()
80
+
81
+ # Preprocess image
82
+ transform = transforms.Compose([
83
+ transforms.Resize((224, 224)),
84
+ transforms.ToTensor(),
85
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
86
+ ])
87
+
88
+ # Load and preprocess image
89
+ image = Image.open('cheese_image.jpg').convert('RGB')
90
+ input_tensor = transform(image).unsqueeze(0)
91
+
92
+ # Make prediction
93
+ with torch.no_grad():
94
+ output = model(input_tensor)
95
+ probabilities = torch.softmax(output, dim=1)
96
+ predicted_class = torch.argmax(probabilities, dim=1).item()
97
+
98
+ class_names = ["Low Texture", "Medium-Low Texture", "Medium-High Texture", "High Texture"]
99
+ print(f"Predicted class: {class_names[predicted_class]}")
100
+ ```
101
+
102
+ ## Class Definitions
103
+
104
+ - **Class 0 (Low Texture)**: Texture values <= 0.425
105
+ - **Class 1 (Medium-Low Texture)**: Texture values 0.425 < x <= 0.600
106
+ - **Class 2 (Medium-High Texture)**: Texture values 0.600 < x <= 0.775
107
+ - **Class 3 (High Texture)**: Texture values > 0.775
108
+
109
+ ## AutoML Features
110
+
111
+ - **Hyperparameter Optimization**: Optuna with 20 trials
112
+ - **Architecture Search**: ResNet18 vs ResNet34
113
+ - **Transfer Learning**: Pre-trained ImageNet weights
114
+ - **Early Stopping**: Prevents overfitting
115
+ - **Fixed Budget**: 20 trials, 10-minute timeout
116
+
117
+ ## Limitations
118
+
119
+ - Trained on a very small dataset (30 images)
120
+ - Texture classification may not generalize to all cheese types
121
+ - Performance may vary with different lighting conditions or image quality
122
+
123
+ ## Citation
124
+
125
+ If you use this model, please cite the original dataset:
126
+
127
+ ```bibtex
128
+ @dataset{aslan-ng/cheese-image,
129
+ title={Cheese Image Dataset},
130
+ author={Aslan Noorghasemi},
131
+ year={2024},
132
+ url={https://huggingface.co/datasets/aslan-ng/cheese-image}
133
+ }
134
+ ```
config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "TransferLearning_resnet34",
3
+ "num_classes": 4,
4
+ "dropout_rate": 0.4682019316470914,
5
+ "model_name": "resnet34",
6
+ "input_size": [
7
+ 3,
8
+ 224,
9
+ 224
10
+ ],
11
+ "class_names": [
12
+ "Low Texture",
13
+ "Medium-Low Texture",
14
+ "Medium-High Texture",
15
+ "High Texture"
16
+ ],
17
+ "texture_bins": [
18
+ 0.42500000447034836,
19
+ 0.6000000238418579,
20
+ 0.7750000059604645
21
+ ],
22
+ "best_hyperparameters": {
23
+ "model_name": "resnet34",
24
+ "dropout_rate": 0.4682019316470914,
25
+ "learning_rate": 0.00027817005315620047,
26
+ "weight_decay": 1.4677013775851028e-05,
27
+ "batch_size": 2
28
+ },
29
+ "test_accuracy": 80.0,
30
+ "validation_accuracy": 50.0,
31
+ "automl_trials": 20,
32
+ "transfer_learning": true
33
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aca27010e82c90189abfd95cc6a2d119e094d7eda90f9e9b65d7c1bd4524d30c
3
+ size 85810707
training_results.json ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "final_results": {
3
+ "train_losses": [
4
+ 1.4447196613658557,
5
+ 1.401605719869787,
6
+ 1.4588848569176414,
7
+ 1.13447397405451,
8
+ 1.3122313943776218,
9
+ 1.3370132012800737,
10
+ 1.1401585746895184,
11
+ 1.2844787619330666,
12
+ 1.0529416718266227,
13
+ 0.8777340379628268,
14
+ 1.2054237046025016,
15
+ 1.2429353242570704,
16
+ 0.8026705953207883,
17
+ 0.8380333388393576,
18
+ 1.1218866407871246,
19
+ 1.189048544927077,
20
+ 0.9291147156195207,
21
+ 0.8265700577334925
22
+ ],
23
+ "val_losses": [
24
+ 1.4239388704299927,
25
+ 1.577258288860321,
26
+ 1.6651681661605835,
27
+ 1.69488525390625,
28
+ 1.5533403158187866,
29
+ 1.7702475786209106,
30
+ 1.6792759895324707,
31
+ 1.6965703964233398,
32
+ 1.922376573085785,
33
+ 2.0783464908599854,
34
+ 2.049513578414917,
35
+ 1.886182188987732,
36
+ 2.1077781915664673,
37
+ 2.1828709840774536,
38
+ 2.3769230246543884,
39
+ 2.173452138900757,
40
+ 2.080229640007019,
41
+ 2.1112526655197144
42
+ ],
43
+ "train_accs": [
44
+ 23.80952380952381,
45
+ 47.61904761904762,
46
+ 28.571428571428573,
47
+ 42.857142857142854,
48
+ 23.80952380952381,
49
+ 38.095238095238095,
50
+ 47.61904761904762,
51
+ 42.857142857142854,
52
+ 61.904761904761905,
53
+ 61.904761904761905,
54
+ 47.61904761904762,
55
+ 42.857142857142854,
56
+ 66.66666666666667,
57
+ 71.42857142857143,
58
+ 38.095238095238095,
59
+ 47.61904761904762,
60
+ 71.42857142857143,
61
+ 71.42857142857143
62
+ ],
63
+ "val_accs": [
64
+ 25.0,
65
+ 25.0,
66
+ 25.0,
67
+ 25.0,
68
+ 25.0,
69
+ 25.0,
70
+ 25.0,
71
+ 50.0,
72
+ 50.0,
73
+ 50.0,
74
+ 25.0,
75
+ 50.0,
76
+ 50.0,
77
+ 50.0,
78
+ 50.0,
79
+ 50.0,
80
+ 50.0,
81
+ 50.0
82
+ ],
83
+ "best_val_acc": 50.0,
84
+ "test_acc": 80.0,
85
+ "test_loss": 1.6345435877641041
86
+ },
87
+ "test_accuracy": 80.0,
88
+ "test_loss": 1.6345435877641041,
89
+ "best_hyperparameters": {
90
+ "model_name": "resnet34",
91
+ "dropout_rate": 0.4682019316470914,
92
+ "learning_rate": 0.00027817005315620047,
93
+ "weight_decay": 1.4677013775851028e-05,
94
+ "batch_size": 2
95
+ },
96
+ "automl_trials": 20,
97
+ "transfer_learning": true
98
+ }