--- 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} } ```