validation package

Submodules

validation.embeddings module

class validation.embeddings.Embeddings(model, transform)[source]

Bases: object

Parameters:
  • model (Module)

  • transform (Compose)

image_to_embedding(image_path, model, transform, img_type='L')[source]

Transform an image to an embedding using the given model.

Parameters:
  • image_path (str | Path) – The path to the image file.

  • model (Module) – The neural network model used for embedding.

  • transform (Compose) – The image transformation pipeline.

  • img_type (str) – The image type (default: “L”).

Returns:

The embedding tensor.

Return type:

Tensor

get_images_embeddings(image_paths, diagnosis)[source]

Get embeddings for list of images.

Parameters:
  • image_paths (list[str | Path]) – List of image paths.

  • diagnosis (str) – Diagnosis for the images.

Returns:

Dictionary containing image embeddings.

Return type:

dict[str, torch.Tensor]

get_images_embeddings_from_dataset(dataset_df)[source]

Get embeddings for list of images.

Parameters:

dataset_df (pd.DataFrame) – DataFrame containing image paths and diagnoses.

Returns:

Dictionary containing embeddings for each image.

Return type:

dict[str, torch.Tensor]

save_embeddings(embeddings, save_path)[source]

Save embeddings to file.

Parameters:
  • embeddings (dict[str, torch.Tensor]) – A dictionary containing embeddings as values and their corresponding keys.

  • save_path (str or Path) – The path where the embeddings will be saved.

Returns:

None

Return type:

None

load_embeddings(embeddings_path)[source]

Load embeddings from file.

Parameters:

embeddings_path (str | Path) – The path to the embeddings file.

Returns:

A dictionary mapping strings to torch.Tensor objects representing the embeddings.

Return type:

dict[str, torch.Tensor]

create_umap_plot(embeddings, save_path)[source]

Create UMAP plot, save it to file.

Parameters:
  • embeddings (dict[str, torch.Tensor]) – A dictionary containing embeddings as values.

  • save_path (str or Path) – The path to save the UMAP plot.

Return type:

None

create_violin_plot(embeddings_dataframe, save_path)[source]

Create violin plot, save it to file.

Parameters:
  • embeddings_dataframe (pd.DataFrame) – DataFrame containing embeddings data.

  • save_path (str or Path) – Path to save the violin plot.

Returns:

None

Return type:

None

calculate_embeddings_distances(embedings1, embedings2)[source]

Create pandas dataframe from embeddings.

Parameters:
  • embedings1 (dict[str, torch.Tensor]) – A dictionary containing embeddings for the first set of images.

  • embedings2 (dict[str, torch.Tensor]) – A dictionary containing embeddings for the second set of images.

Returns:

A pandas DataFrame containing the calculated distances between embeddings.

Return type:

pd.DataFrame

calculate_cosine_similarity(emb1, emb2)[source]

Calculate cosine distance between two embeddings.

Parameters:
  • emb1 (torch.Tensor) – The first embedding.

  • emb2 (torch.Tensor) – The second embedding.

Returns:

The cosine similarity between the two embeddings.

Return type:

float

validation.fid module

Module contents

class validation.Embeddings(model, transform)[source]

Bases: object

Parameters:
  • model (Module)

  • transform (Compose)

image_to_embedding(image_path, model, transform, img_type='L')[source]

Transform an image to an embedding using the given model.

Parameters:
  • image_path (str | Path) – The path to the image file.

  • model (Module) – The neural network model used for embedding.

  • transform (Compose) – The image transformation pipeline.

  • img_type (str) – The image type (default: “L”).

Returns:

The embedding tensor.

Return type:

Tensor

get_images_embeddings(image_paths, diagnosis)[source]

Get embeddings for list of images.

Parameters:
  • image_paths (list[str | Path]) – List of image paths.

  • diagnosis (str) – Diagnosis for the images.

Returns:

Dictionary containing image embeddings.

Return type:

dict[str, torch.Tensor]

get_images_embeddings_from_dataset(dataset_df)[source]

Get embeddings for list of images.

Parameters:

dataset_df (pd.DataFrame) – DataFrame containing image paths and diagnoses.

Returns:

Dictionary containing embeddings for each image.

Return type:

dict[str, torch.Tensor]

save_embeddings(embeddings, save_path)[source]

Save embeddings to file.

Parameters:
  • embeddings (dict[str, torch.Tensor]) – A dictionary containing embeddings as values and their corresponding keys.

  • save_path (str or Path) – The path where the embeddings will be saved.

Returns:

None

Return type:

None

load_embeddings(embeddings_path)[source]

Load embeddings from file.

Parameters:

embeddings_path (str | Path) – The path to the embeddings file.

Returns:

A dictionary mapping strings to torch.Tensor objects representing the embeddings.

Return type:

dict[str, torch.Tensor]

create_umap_plot(embeddings, save_path)[source]

Create UMAP plot, save it to file.

Parameters:
  • embeddings (dict[str, torch.Tensor]) – A dictionary containing embeddings as values.

  • save_path (str or Path) – The path to save the UMAP plot.

Return type:

None

create_violin_plot(embeddings_dataframe, save_path)[source]

Create violin plot, save it to file.

Parameters:
  • embeddings_dataframe (pd.DataFrame) – DataFrame containing embeddings data.

  • save_path (str or Path) – Path to save the violin plot.

Returns:

None

Return type:

None

calculate_embeddings_distances(embedings1, embedings2)[source]

Create pandas dataframe from embeddings.

Parameters:
  • embedings1 (dict[str, torch.Tensor]) – A dictionary containing embeddings for the first set of images.

  • embedings2 (dict[str, torch.Tensor]) – A dictionary containing embeddings for the second set of images.

Returns:

A pandas DataFrame containing the calculated distances between embeddings.

Return type:

pd.DataFrame

calculate_cosine_similarity(emb1, emb2)[source]

Calculate cosine distance between two embeddings.

Parameters:
  • emb1 (torch.Tensor) – The first embedding.

  • emb2 (torch.Tensor) – The second embedding.

Returns:

The cosine similarity between the two embeddings.

Return type:

float