Welcome to Signature-Classifier documentation!

Modules

class main.SignatureVerification(dataset_path: str, storage_path: str, verbose: bool = False)

A class used to verify signatures using HOG features and KNN classifier.

dataset_path

Path to the dataset containing real and forged signatures.

Type:

str

storage_path

Path to save models, parameters, and results.

Type:

str

verbose

If True, enables logging information (default is False).

Type:

bool, optional

best_params

Stores the best hyperparameters found during optimization.

Type:

dict

signatures

Dictionary containing the paths to real and forged signatures.

Type:

dict

log_info(message)

Logs an info message if verbose is True.

log_error(message)

Logs an error message if verbose is True.

_load_signatures()

Loads signatures from the dataset path.

_extract_hog_features(image_path, resize_shape, orientations, pixels_per_cell, cells_per_block)

Extracts HOG features from an image.

_prepare_data(resize_shape, orientations, pixels_per_cell, cells_per_block)

Prepares the dataset by extracting HOG features.

_objective(trial)

Objective function for hyperparameter optimization using Optuna.

optimize_hyperparameters(n_trials)

Optimizes hyperparameters using Optuna.

train_final_model(params_dict=None, save_plots=False)

Trains the final model with given or optimized hyperparameters.

evaluate_model(model, X_test, y_test, save_plots)

Evaluates the trained model and saves classification report and confusion matrix.

predict(image_path, top_n=5, return_forg_preds=True)

Predicts the class of a given signature image.

_forg_predict(features, class_name, params)

Predicts the similarity score for forgery detection.

_save_model(model)

Saves the trained model.

_load_model()

Loads the trained model.

_save_params(params)

Saves the hyperparameters.

_load_params()

Loads the hyperparameters.

evaluate_model(model: KNeighborsClassifier, X_test: ndarray, y_test: ndarray, save_plots: bool) None

Evaluates the trained model and saves classification report and confusion matrix.

Parameters: model (KNeighborsClassifier): Trained KNN model. X_test (np.ndarray): Test set features. y_test (np.ndarray): Test set labels. save_plots (bool): If True, saves the classification report and confusion matrix plots.

log_error(message: str)

Logs an error message if verbose is True.

Parameters: message (str): The message to be logged.

log_info(message: str)

Logs an info message if verbose is True.

Parameters: message (str): The message to be logged.

optimize_hyperparameters(n_trials: int) None

Optimizes hyperparameters using Optuna.

Parameters: n_trials (int): Number of trials for the optimization.

predict(image_path: str, top_n: int = 5, return_forg_preds: bool = True) List[Tuple[str, float] | Tuple[str, float, float]]

Predicts the class of a given signature image.

Parameters: image_path (str): Path to the signature image. top_n (int): Number of top predictions to return. return_forg_preds (bool): If True, returns similarity score for forgery detection.

Returns: List[Union[Tuple[str, float], Tuple[str, float, float]]]: List of top predictions with probabilities and optional forgery scores.

train_final_model(params_dict: Dict[str, int | float] | None = None, save_plots: bool = False) None

Trains the final model with given or optimized hyperparameters.

Parameters: params_dict (Optional[Dict[str, Union[int, float]]]): Dictionary containing custom hyperparameters. save_plots (bool): If True, saves the classification report and confusion matrix plots.