File size: 4,999 Bytes
90250a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb6dc89
 
 
 
90250a1
 
 
 
 
 
 
 
 
 
fb6dc89
 
90250a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75de3fd
 
 
 
 
 
 
 
 
 
90250a1
 
fb6dc89
 
 
 
 
 
 
 
 
 
 
90250a1
fb6dc89
90250a1
 
 
 
 
 
 
 
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
license: mit
tags:
- image-classification
- cheese
- texture
- computer-vision
- pytorch
- transfer-learning
- automl
datasets:
- aslan-ng/cheese-image
metrics:
- accuracy
model-index:
- name: Cheese Texture Classifier (AutoML)
  results:
  - task:
      type: image-classification
      name: Cheese Texture Classification
    dataset:
      type: aslan-ng/cheese-image
      name: Cheese Image Dataset
    metrics:
    - type: accuracy
      value: 80.00
      name: Test Accuracy
---

# Cheese Texture Classifier (AutoML)

**Model Creator**: Rumi Loghmani (@rlogh)  
**Original Dataset**: aslan-ng/cheese-image (by Aslan Noorghasemi)

This model performs 4-class texture classification on cheese images using AutoML-optimized transfer learning. The model was developed by Rumi Loghmani using the cheese image dataset created by Aslan Noorghasemi.

## Model Description

- **Architecture**: Transfer Learning with resnet34
- **Task**: 4-class texture classification (Low, Medium-Low, Medium-High, High texture)
- **Input**: 224x224 RGB images
- **Output**: 4-class probability distribution

## Training Details

- **Model Developer**: Rumi Loghmani (@rlogh)
- **Dataset**: [aslan-ng/cheese-image](https://huggingface.co/datasets/aslan-ng/cheese-image) (by Aslan Noorghasemi)
- **AutoML Method**: Optuna with 20 trials
- **Transfer Learning**: Pre-trained resnet34 backbone
- **Early Stopping**: Yes (patience=10)
- **Max Epochs**: 50

## Performance

- **Test Accuracy**: 80.00%
- **Validation Accuracy**: 50.00%
- **Test Loss**: 1.6345

## Best Hyperparameters (AutoML Optimized)

```json
{
  "model_name": "resnet34",
  "dropout_rate": 0.4682019316470914,
  "learning_rate": 0.00027817005315620047,
  "weight_decay": 1.4677013775851028e-05,
  "batch_size": 2
}
```

## Usage

```python
import torch
import torch.nn as nn
from PIL import Image
import torchvision.transforms as transforms
import torchvision.models as models

# Load model (define TransferLearningModel class first)
model = TransferLearningModel(num_classes=4, dropout_rate=0.4682019316470914, model_name='resnet34')
model.load_state_dict(torch.load('pytorch_model.bin'))
model.eval()

# Preprocess image
transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

# Load and preprocess image
image = Image.open('cheese_image.jpg').convert('RGB')
input_tensor = transform(image).unsqueeze(0)

# Make prediction
with torch.no_grad():
    output = model(input_tensor)
    probabilities = torch.softmax(output, dim=1)
    predicted_class = torch.argmax(probabilities, dim=1).item()

class_names = ["Low Texture", "Medium-Low Texture", "Medium-High Texture", "High Texture"]
print(f"Predicted class: {class_names[predicted_class]}")
```

## Class Definitions

- **Class 0 (Low Texture)**: Texture values <= 0.425
- **Class 1 (Medium-Low Texture)**: Texture values 0.425 < x <= 0.600
- **Class 2 (Medium-High Texture)**: Texture values 0.600 < x <= 0.775
- **Class 3 (High Texture)**: Texture values > 0.775

## AutoML Features

- **Hyperparameter Optimization**: Optuna with 20 trials
- **Architecture Search**: ResNet18 vs ResNet34
- **Transfer Learning**: Pre-trained ImageNet weights
- **Early Stopping**: Prevents overfitting
- **Fixed Budget**: 20 trials, 10-minute timeout

## Limitations

- Trained on a very small dataset (30 images)
- Texture classification may not generalize to all cheese types
- Performance may vary with different lighting conditions or image quality

## AI Usage 
This notebook was developed with the assistance of AI as a coding co-pilot. AI tools were used to:

- **Suggest code snippets**: AI provided suggestions for implementing various parts of the code, such as the dataset class, model architecture, training loops, and data preprocessing steps.
- **Debug and refactor code**: AI helped identify potential errors and suggest ways to refactor code for improved readability and efficiency.
- **Generate documentation**: AI assisted in generating explanations for code sections and creating the model card for Hugging Face.
- **Explore potential issues**: AI provided insights into potential challenges, such as handling small batch sizes and implementing early stopping, and suggested strategies to address them.

The AI served as a valuable partner throughout the development process, accelerating coding and improving code quality.

## Citation

If you use this model, please cite both the model and the original dataset:

**Model Citation:**
```bibtex
@model{rlogh/cheese-texture-classifier-automl,
  title={Cheese Texture Classifier (AutoML)},
  author={Rumi Loghmani},
  year={2024},
  url={https://huggingface.co/rlogh/cheese-texture-classifier-automl}
}
```

**Dataset Citation:**
```bibtex
@dataset{aslan-ng/cheese-image,
  title={Cheese Image Dataset},
  author={Aslan Noorghasemi},
  year={2024},
  url={https://huggingface.co/datasets/aslan-ng/cheese-image}
}
```