This function loads a fine-tuned Torch model, extracts embeddings from a set of test images, performs dimensionality reduction using UMAP, and creates scatter plots to visualize the embeddings.

extract_embeddings(test_input, model_path, target_class, unsupervised = "TRUE")

Arguments

test_input

A character string specifying the path to the directory containing the test images.

model_path

A character string specifying the path to the pre-trained PyTorch model file.

target_class

A character string specifying the class of interest for cluster analysis.

unsupervised

Logical, indicates whether to assign 'target_class' to a cluster and calculate NMI and corresponding confusion matrix

Value

A list containing the following components:

EmbeddingsCombined

A combined scatter plot of embeddings, showing class and cluster colors.

NMI

Normalized Mutual Information (NMI) score between clustering results and ground truth labels.

ConfusionMatrix

A confusion matrix showing classification performance metrics.

Note

Requires a model trained using 'train_CNN_multi' or 'train_CNN_binary', and a directory of spectrogram images created using 'spectrogram_images'.

Examples

{
  #' Set model directory
  trained_models_dir <- system.file("extdata", "trainedresnetmulti/", package = "gibbonNetR")

  #' Specify model path
  ModelPath <- list.files(trained_models_dir, full.names = TRUE)

  # Specify model path
  ImageFile <- system.file("extdata", "multiclass/test/", package = "gibbonNetR")

  # Function to extract and plot embeddings
  result <- extract_embeddings(
    test_input = ImageFile,
    model_path = ModelPath,
    target_class = "female.gibbon",
    unsupervised = "TRUE"
  )

  print(result$EmbeddingsCombined)
}
#> Unupervised clustering for female.gibbon