bacpipe.embedding_evaluation.visualization package
Submodules
bacpipe.embedding_evaluation.visualization.dashboard module
- class bacpipe.embedding_evaluation.visualization.dashboard.DashBoard(model_names, audio_dir, main_results_dir, default_label_keys, evaluation_task, dim_reduction_model, dim_reduc_parent_dir, **kwargs)[source]
Bases:
DashBoardHelper- build_layout()[source]
Builds the layout for the dashboard with two models and a single model page. The layout consists of a single model page, a two-models comparison page, and a page showing all models. Each page contains sidebars with model-specific information and content areas for visualizations.
- bacpipe.embedding_evaluation.visualization.dashboard.visualize_using_dashboard(models, dashboard_port=5006, dashboard_address='localhost', dashboard_websocket_origin=False, **kwargs)[source]
Create and serve the dashboard for visualization. To colorcode embeddings by other labels than the default ones, create an annotations file with timestamps. An example file can be found in ‘bacpipe/tests/test_data/annotations.csv’. Multiple dashboards can be opened, the port will simply increment.
- Parameters:
models (list) – embedding models
kwargs (dict) – Dictionary with parameters for dashboard creation
bacpipe.embedding_evaluation.visualization.dashboard_utils module
- class bacpipe.embedding_evaluation.visualization.dashboard_utils.DashBoardHelper[source]
Bases:
object- handle_selection(event, widget_idx=None)[source]
Triggered when the user uses the Lasso or Box select tool.
- init_interactive_embed_plot(widget_idx)[source]
Initialize interactive embedding plot with dummy figure
- save_embedding_plot(event, widget_idx, plot_func, **kwargs)[source]
Save the current embedding plot
bacpipe.embedding_evaluation.visualization.tooltips module
bacpipe.embedding_evaluation.visualization.visualize module
- bacpipe.embedding_evaluation.visualization.visualize.clustering_overview(path_func, label_by, no_noise, model_list, label_column, **kwargs)[source]
Create overview plots for clustering metrics.
- Parameters:
path_func (function) – function to return the paths when model name is given
label_by (str) – key of default_labels dict
no_noise (bool) – whether to plot the metrics with or without noise
model_list (list) – list of models
label_column (str) – label as defined in the annotations.csv file
kwargs (dict) – additional arguments for plotting
- Returns:
figure handle
- Return type:
plt.plot object
- bacpipe.embedding_evaluation.visualization.visualize.generate_bar_plot(metrics, fig, ax, x_label='Metric value', no_legend=False, **kwargs)[source]
- bacpipe.embedding_evaluation.visualization.visualize.iterate_through_subtasks(plot_func, plot_path, task_name, model_list, metrics)[source]
For classification multiple subtasks exist (linear and knn). Iterate over each of the subtasks and call the plotting functions to create the visualizations.
- Parameters:
plot_func (function) – returns model specific paths when model name is passed
plot_path (pathlib.Path object) – path to store overview plots
task_name (str) – name of task
model_list (list) – list of models
metrics (dict) – performance dictionary
- bacpipe.embedding_evaluation.visualization.visualize.plot_clusterings(path_func, model_name, label_by, no_noise, fig=None, ax=None, **kwargs)[source]
Plot the clustering metrics for a given model and label type.
- Parameters:
path_func (function) – function to return the paths when model name is given
model_name (str) – name of model
label_by (str) – key of default_labels dict
no_noise (bool) – whether to plot the metrics with or without noise
fig (plt.plot object, optional) – figure handle, by default None
ax (plt.plot object, optional) – axes handle, by default None
- Returns:
figure handle
- Return type:
plt.plot object
- bacpipe.embedding_evaluation.visualization.visualize.plot_overview_metrics(plot_path, task_name, model_list, metrics, path_func=None, return_fig=False, sort_string='kmeans-audio_file_name')[source]
Visualization of task performance by model accross all classes. Resulting plot is stored in the plot path.
- Parameters:
plot_path (pathlib.Path object) – path to store overview plots
task_name (str) – name of task
model_list (list) – list of models
metrics (dict) – performance dictionary
sort_string (str) – string to sort the metrics by, defaults to “kmeans-audio_file_name”
- bacpipe.embedding_evaluation.visualization.visualize.visualise_results_across_models(plot_path, task_name, model_list)[source]
Create visualizations to compare models by specified tasks.
- Parameters:
path_func (function) – return the paths when given a model name
plot_path (pathlib.Path object) – path to overview plots
task_name (str) – name of task
model_list (list) – list of models
bacpipe.embedding_evaluation.visualization.visualize_embeddings module
- class bacpipe.embedding_evaluation.visualization.visualize_embeddings.EmbedAndLabelLoader(dim_reduction_model, dashboard=False, **kwargs)[source]
Bases:
object
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.collect_dim_reduced_embeds(model_name, dim_reduced_embed_path, dim_reduction_model, **kwargs)[source]
Return the dimensionality reduced embeddings of a model.
- Parameters:
model_name (str) – name of model
dim_reduced_embed_path (pathlib.Path object) – path to dim reduced embeddings
dim_reduction_model (str) – name of feature extraction model
- Returns:
dimensionality reduced embeddings
- Return type:
dict
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.darken_hex_color_bitwise(hex_color)[source]
Darkens a hex color using the bitwise operation: (color & 0xfefefe) >> 1.
- Parameters:
hex_color (str): The hex color string (e.g., ‘#1f77b4’).
- Returns:
str: The darkened hex color.
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.data_split_by_labels(embeds_dict, labels)[source]
Split data by labels for scatterplots.
- Parameters:
embeds_dict (dict) – embeddings by model
labels (list) – list of labels
- Returns:
x and y data corresponding to labels
- Return type:
dict
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.get_labels_for_plot(model_name=None, **kwargs)[source]
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.init_embed_figure(fig, axes, bool_3d=False, **kwargs)[source]
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.plot_comparison(plot_path, models, dim_reduction_model, bool_spherical=False, dashboard=False, loader=None, evaluation_task=[], **kwargs)[source]
Create big overview visualization of all embeddings spaces. Labels are chosen from ground_truth and if that does not exist, default lables are used.
- Parameters:
plot_path (pathlib.Path object) – path to store overview plots
models (list) – list of models
dim_reduction_model (str) – name of dimensionality reduction model
bool_spherical (bool, optional) – if True 3d embeddings will be plotted, by default False
dashboard (bool, optional) – if dashboard called this function or not
loader (EmbedAndLabelLoader object) – object containing embeds and labels by model for quicker loading
evaluation_task (list, optional) – list of tasks to evaluate, by default []
- Returns:
figure handle
- Return type:
plt object
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.plot_embedding_points(axes, embeds, split_data, labels, c_label_dict, remove_noise=False, **kwargs)[source]
Plot embeddings in scatter plot.
- Parameters:
axes (plt object) – axes handle
embeds (dict) – embeddings
split_data (dict) – data split by label
labels (list) – labels of the data
c_label_dict (dict) – linking labels to ints for coloring
remove_noise (bool, optional) – remove noise or not, defaults to False
- Returns:
axes points
- Return type:
plt object
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.plot_embeddings(loader, model_name, label_by, paths=None, dim_reduction_model=None, axes=False, fig=False, dashboard=False, dashboard_idx=None, **kwargs)[source]
Generate figures and axes to plot points corresponding to embeddings. This function can also be called and given figure and axes handeles. In that case the existing handles will be used to add the points and configure the axes and labels.
- Parameters:
loader (EmbedAndLabelLoader object) – contains the labels and embeddings by model, for quicker loading
model_name (str) – name of model
label_by (str, optional) – key of default_labels dict, by default “audio_file_name”
paths (SimpleNamespace object, optional) – object with path attributes, defaults to None
dim_reduction_model (str) – name of dim reduced model
axes (plt object, optional) – axes handle, by default False
fig (plt object, optional) – figure handle, by default False
dashboard (bool, optional) – whether the calls comes from the dashboard, by deafult False
dashboard_idx (int, optional) – index of dashboard plot, relevant for legend placement
- Returns:
plt object – axes handles is axes handles were given
dict – color dictionary for legend
list – plt point objects for legend of colorbar
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.plot_embeddings_px(embeds, labels, c_label_dict, label_by='label', **kwargs)[source]
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.reorder_embeddings_by_clustering_performance(plot_path, axes, models, order_metric='ground_truth-kmeans')[source]
Reorder the embedding overview plot by clustering performance.
- Parameters:
plot_path (pathlib.Path object) – path to store plots and results comparing all models
axes (plt.axes object) – handle for figures axes
models (list) – list of models
order_metric (str) – key corresponding to a metric in the clustering_results.json file. Defaults to “ARI(kmeans)”
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.set_colorbar_or_legend(fig, axes, points, c_label_dict, label_by, **kwargs)[source]
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.set_figsize_for_comparison(rows, cols)[source]
- bacpipe.embedding_evaluation.visualization.visualize_embeddings.set_legend(handles, labels, fig, axes, bool_plot_centroids=False, dashboard=False, **kwargs)[source]
Create the legend for embeddings visualization plots.
- Parameters:
handles (list) – list of legend handles
labels (list) – list of labels for legend
fig (plt.fig object) – figure handle
axes (plt.axes object) – axes handle
bool_plot_centroids (bool, optional) – if True centroids of each class will be plotted, by default True
dashboard (bool) – if dashboard called this function or not
- Returns:
plt.fig object – figure handle
plt.axes object – axes handle
bacpipe.embedding_evaluation.visualization.visualize_predictions module
- class bacpipe.embedding_evaluation.visualization.visualize_predictions.PredictionsLoader(vis_loader, path_func, models, panel_selection, progress_bar, loading_pane, thresh=0.5)[source]
Bases:
object
- bacpipe.embedding_evaluation.visualization.visualize_predictions.load_results(path_func, task, model_list)[source]
Load the task results into a dict and return them. For classification multiple subtasks exist, so do them seperately.
- Parameters:
path_func (function) – returns model specific tasks when model is given
task (str) – name of task
model_list (list) – list of models
- Returns:
performance for different tasks and models
- Return type:
dict
- bacpipe.embedding_evaluation.visualization.visualize_predictions.plot_classification_heatmap(event, predictions_loader, model, accumulate_by, threshold, species=None, **kwargs)[source]
- bacpipe.embedding_evaluation.visualization.visualize_predictions.plot_classification_results(task_name, paths=None, metrics=None, return_fig=False, path_func=None, model_name=None)[source]
Save model specific classification results in the model specific plot path, displayed as horizontal bars.
- Parameters:
task_name (str) – name of task
paths (SimpleNamespace object) – path to store plots
metrics (dict) – classification performance
return_fig (bool) – if True the figure will be returned, by default False
path_func (function) – function to return the paths when model name is given
model_name (str) – name of model, by default None
- Returns:
figure handle
- Return type:
plt object
- bacpipe.embedding_evaluation.visualization.visualize_predictions.plot_per_class_metrics(plot_path, task_name, model_list, metrics)[source]
Visualization of per class results. Resulting figure is stored in plot path. Models are sorted by the value of the first entry.
- Parameters:
plot_path (pathlib.Path object) – path to store plot in
task_name (str) – name of task
model_list (list) – list of models
metrics (dict) – performance dictionary