Skip to content

Add image classification models#653

Open
Creylay wants to merge 12 commits into
developfrom
feat/add-image-classification-models
Open

Add image classification models#653
Creylay wants to merge 12 commits into
developfrom
feat/add-image-classification-models

Conversation

@Creylay
Copy link
Copy Markdown
Collaborator

@Creylay Creylay commented May 28, 2026

Summary

Adds four new torchvision-based image classification models to DashAI and introduces a shared base class that consolidates all training logic. The MLP image classifier is also upgraded with new configurable hyperparameters. A defensive logging improvement in BaseModel avoids silent failures when a metric returns a non-finite score (e.g., only one class present in a split).


Type of Change

  • Backend change
  • Frontend change
  • CI / Workflow change
  • Build / Packaging change
  • Bug fix
  • Documentation

Changes (by file)

  • DashAI/back/models/base_torchvision_image_classifier.py: New shared base class (TorchvisionImageClassifier) for torchvision-backed models. Implements the full train/predict/save/load lifecycle, data augmentation pipeline, and a shared schema (TorchvisionImageClassifierSchema) with parameters: epochs, learning_rate, batch_size, image_size, dropout_rate, weight_decay.
  • DashAI/back/models/cnn_image_classifier.py: New CNNImageClassifier — a lightweight custom CNN with two conv blocks and a configurable number of filters.
  • DashAI/back/models/lenet5_image_classifier.py: New LeNet5ImageClassifier — LeNet-5 architecture (LeCun et al., 1998), adapted for multi-class output.
  • DashAI/back/models/resnet18_image_classifier.py: New ResNet18ImageClassifier — ResNet-18 backbone with optional ImageNet pre-trained weights; final FC layer replaced to match target classes.
  • DashAI/back/models/resnet50_image_classifier.py: New ResNet50ImageClassifier — ResNet-50 backbone with optional ImageNet pre-trained weights; final FC layer replaced.
  • DashAI/back/models/efficientnet_b0_image_classifier.py: New EfficientNetB0ImageClassifier — EfficientNet-B0 backbone with optional ImageNet
  • DashAI/back/models/mlp_image_classifier.py: Added batch_size, image_size, dropout_rate, and weight_decay parameters; wired them through training, prediction, save, and load paths.
  • DashAI/back/models/base_model.py: Added warning log when a metric returns a non-finite value (e.g., NaN, inf) during evaluation; the metric is skipped instead of crashing or silently producing bad results.
  • DashAI/back/tasks/image_classification_task.py: Shortened the DESCRIPTION field to a concise single sentence.
  • DashAI/back/initial_components.py: Registered CNNImageClassifier, LeNet5ImageClassifier, ResNet18ImageClassifier, ResNet50ImageClassifier, and EfficientNetB0ImageClassifier. Removed VGG16ImageClassifier (also deleted its file).

Notes

  • All new models subclass TorchvisionImageClassifier and only need to implement _build_backbone and _classifier_head, keeping each model file minimal.
  • Pre-trained weights are downloaded from torchvision on first use when pretrained=True (the default).

Creylay added 8 commits May 25, 2026 16:36
…t rate, and weight decay in MLPImageClassifier
… ResNet-50, VGG-16

- Implement EfficientNet-B0 image classifier with support for pretrained weights.
- Implement LeNet-5 image classifier with configurable dropout and training parameters.
- Implement ResNet-18 image classifier with skip connections and pretrained weights.
- Implement ResNet-50 image classifier using bottleneck blocks and pretrained weights.
- Implement VGG-16 image classifier with 3x3 convolutions and pretrained weights.
- Add documentation for image classification models, including descriptions, architectures, and usage recommendations.
Copy link
Copy Markdown
Collaborator

@Irozuku Irozuku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing lazy imports for heavy dependencies such as torch. These imports should be moved inside the methods where they are actually used to avoid unnecessary startup overhead and memory consumption when the functionality is not needed.

It is also missing live metrics reporting for classification models. A call to calculate_metrics(...) should be added in each model so metrics are computed and reported consistently during training and evaluation.

Copy link
Copy Markdown
Collaborator

@Irozuku Irozuku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All models are missing a device parameter to explicitly select the execution device.

@cristian-tamblay
Copy link
Copy Markdown
Member

cristian-tamblay commented May 28, 2026

Also missing de language (and i think this show we are also missing pt language on models)

@cristian-tamblay cristian-tamblay added the conflict This PR has merge conflicts label May 28, 2026
Creylay added 4 commits May 28, 2026 17:49
…nction

- Replaced individual dataset classes with a common `_make_image_dataset` function across multiple classifiers (Torchvision, CNN, LeNet5, MLP).
- Updated model definitions to utilize the new dataset function.
- Simplified model architecture definitions by introducing `_build_*_model` functions for CNN, LeNet5, and MLP.
- Removed redundant imports and organized code for better readability.
- Enhanced training loops to include evaluation metrics for both training and validation datasets.
@Creylay Creylay removed the conflict This PR has merge conflicts label May 28, 2026
@Creylay Creylay requested a review from Irozuku May 28, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants