bacpipe.embedding_evaluation.visualization.visualize_embeddings
Functions
|
Return the dimensionality reduced embeddings of a model. |
|
Darkens a hex color using the bitwise operation: (color & 0xfefefe) >> 1. |
|
Split data by labels for scatterplots. |
|
|
|
|
|
Create big overview visualization of all embeddings spaces. |
|
Plot embeddings in scatter plot. |
|
Generate figures and axes to plot points corresponding to embeddings. |
|
|
Reorder the embedding overview plot by clustering performance. |
|
|
|
|
|
|
|
|
Create the legend for embeddings visualization plots. |
Classes
|
|
|
The top level container for all the plot elements. |
|
PurePath subclass that can make system calls. |
- 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