focal.hyperparameter_tuning module¶
Hyperparameter tuning module for the FOCAL application.
This module provides classes for hyperparameter optimization using Keras Tuner for both CNN and MLP models.
- class focal.hyperparameter_tuning.BuildHyperModel(image_shape: Tuple[int, int, int], param_shape: Tuple[int, ...], backbone: str | None = 'mobilenet')[source]¶
Bases:
HyperModelHyperModel for determining optimal hyperparameters for the combined CNN+MLP model.
This class builds a model architecture that combines image features from MobileNetV2 with numerical parameters for fiber cleave classification.
- class focal.hyperparameter_tuning.BuildMLPHyperModel(model_path: str)[source]¶
Bases:
HyperModelHyperModel for MLP-based tension prediction.
This class builds a model that uses features extracted from a pre- trained CNN to predict optimal tension values.
- class focal.hyperparameter_tuning.HyperParameterTuning(image_shape: Tuple[int, int, int], feature_shape: Tuple[int, ...], max_epochs: int = 20, objective: str = 'val_accuracy', directory: str = './tuner_logs', project_name: str = 'Cleave_Tuner', backbone: str | None = 'mobilenet', class_weights: str | None = None)[source]¶
Bases:
objectClass for tuning hyperparameters for the combined CNN+MLP model.
- get_best_hyperparameters() object[source]¶
Get best hyperparameters from hyperparameter search.
- Returns:
Best hyperparameters from hyperparameter search
- Return type:
keras_tuner.engine.hyperparameters.HyperParameters
- get_best_model() Model[source]¶
Get best model from hyperparameter search.
- Returns:
Best model from hyperparameter search
- Return type:
tf.keras.Model
- run_search(train_ds: DatasetV2, test_ds: DatasetV2, max_epochs: int) None[source]¶
Run hyperparameter search.
- Parameters:
train_ds – tf.data.Dataset - Training dataset
test_ds – tf.data.Dataset - Testing dataset
max_epochs – maximum number of training epochs
- save_best_model(pathname: str) None[source]¶
Save the best model from hyperparameter search.
- Parameters:
pathname – Path where to save the model
- tuner¶
self.tuner = Hyperband( hypermodel, objective=objective, max_epochs=max_epochs, directory=directory,
project_name=project_name )
- class focal.hyperparameter_tuning.ImageHyperparameterTuning(image_shape: Tuple[int, int, int], max_epochs: int = 20, objective: str = 'val_accuracy', directory: str = './tuner_logs', project_name: str = 'CNN_Image_Only', backbone: str | None = 'mobilenet', num_classes: int | None = 5, class_weights: str | None = None)[source]¶
Bases:
HyperParameterTuningHyperparameter tuning specifically for image-only models.
- tuner¶
self.tuner = Hyperband( hypermodel, objective=objective, max_epochs=max_epochs, directory=directory,
project_name=project_name )
- class focal.hyperparameter_tuning.ImageOnlyHyperModel(image_shape: Tuple[int, int, int], num_classes: int = 5, backbone: str | None = 'mobilenet', classification_type: str | None = 'binary')[source]¶
Bases:
HyperModelHyperModel for image-only classification (no numerical parameters).
- class focal.hyperparameter_tuning.MLPHyperparameterTuning(cnn_path: str, max_epochs: int = 20, objective: str = 'val_mae', directory: str = './tuner_logs', project_name: str = 'MLPTuner', class_weights=None)[source]¶
Bases:
HyperParameterTuningHyperparameter tuning specifically for MLP models.