MLPImageClassifier
MLP-based image classifier.
A feed-forward neural network that flattens image pixels and passes them through configurable hidden layers with ReLU activation for classification.
Parameters
- epochs : integer, default=
10 - The number of epochs to train the model. An epoch is a full iteration over the training data.
- learning_rate : number, default=
0.001 - Learning rate for the Adam optimizer.
- hidden_dims : array, default=
[128, 64] - The hidden layers and their dimensions. Specify the number of units of each layer separated by commas.
Methods
load(cls, filename: str)
MLPImageClassifierLoad a model checkpoint from disk.
Parameters
- filename : str
- Path to the checkpoint file.
Returns
- MLPImageClassifier
- Instance with loaded weights.
predict(self, x)
MLPImageClassifierMake predictions on the input dataset.
Parameters
- x : DashAIDataset
- Input dataset containing images.
Returns
- list of lists
- List of predicted probabilities for each class for each image.
prepare_output(self, dataset, is_fit=False)
MLPImageClassifierEncode string labels to integer indices matching the model's class order.
save(self, filename: str) -> None
MLPImageClassifierSave the model checkpoint to disk.
Parameters
- filename : str
- Path where the checkpoint will be saved.
train(self, x_train, y_train, x_validation=None, y_validation=None)
MLPImageClassifierTrain the MLP on the provided image dataset.
Parameters
- x_train : DashAIDataset
- Input dataset containing images.
- y_train : DashAIDataset
- Target dataset containing labels.
- x_validation : DashAIDataset, optional
- Validation input features (unused). Defaults to None.
- y_validation : DashAIDataset, optional
- Validation target labels (unused). Defaults to None.
Returns
- MLPImageClassifier
- The trained model instance.
calculate_metrics(self, split: DashAI.back.core.enums.metrics.SplitEnum = <SplitEnum.VALIDATION: 'validation'>, level: DashAI.back.core.enums.metrics.LevelEnum = <LevelEnum.LAST: 'last'>, log_index: int = None, x_data: 'DashAIDataset' = None, y_data: 'DashAIDataset' = None)
BaseModelCalculate and save metrics for a given data split and level.
Parameters
- split : SplitEnum
- The data split to evaluate (TRAIN, VALIDATION, or TEST). Defaults to SplitEnum.VALIDATION.
- level : LevelEnum
- The metric granularity level (LAST, TRIAL, STEP, or BATCH). Defaults to LevelEnum.LAST.
- log_index : int, optional
- Explicit step index for the metric entry. If None, the next step index is computed automatically. Defaults to None.
- x_data : DashAIDataset, optional
- Input features. If None, the dataset stored in the model for the given split is used. Defaults to None.
- y_data : DashAIDataset, optional
- Target labels. If None, the labels stored in the model for the given split are used. Defaults to None.
get_metadata(cls) -> Dict[str, Any]
BaseModelGet metadata values for the current model.
Returns
- Dict[str, Any]
- Dictionary containing UI metadata such as the model icon used in the DashAI frontend.
get_schema(cls) -> dict
ConfigObjectGenerates the component related Json Schema.
Returns
- dict
- Dictionary representing the Json Schema of the component.
prepare_dataset(self, dataset: 'DashAIDataset', is_fit: bool = False) -> 'DashAIDataset'
BaseModelHook for model-specific preprocessing of input features.
Parameters
- dataset : DashAIDataset
- The input dataset to preprocess.
- is_fit : bool
- Whether the call is part of a fitting phase. Defaults to False.
Returns
- DashAIDataset
- The preprocessed dataset ready to be fed into the model.
validate_and_transform(self, raw_data: dict) -> dict
ConfigObjectIt takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.
Parameters
- raw_data : dict
- A dictionary with the data provided by the user to initialize the model.
Returns
- dict
- A validated dictionary with the necessary objects.