code: def give_inat_datasets_finetune_1head(
      testset, cluster_label_path, opt
  ):
      """
      This function generates a training, testing and evaluation dataloader for Metric Learning on the Inaturalist 2018 dataset.
      For Metric Learning, training and test sets are provided by given json files. Will define a train and test split
      So no random shuffling of classes.
  
      Args:
          opt: argparse.Namespace, contains all traininig-specific parameters.
      Returns:
          dict of PyTorch datasets for training, testing and evaluation.
      """
      # Load cluster labels from hilander results.
      import pickle
  
      train_image_dict, val_image_dict, cluster_image_dict = {}, {}, {}
      with open(cluster_label_path, "rb") as clusterf:
          (
              path2idx,
              global_features,
              global_pred_labels,
              gt_labels,
              masks,
          ) = pickle.load(clusterf)
  
          for path, idx in path2idx.items():
              if global_pred_labels[idx] == -1:
                  continue
              else:
                  if (
                      "te/%d" % global_pred_labels[idx]
                      not in train_image_dict
                  ):
                      train_image_dict[
                          "te/%d" % global_pred_labels[idx]
                      ] = []
                  train_image_dict[
                      "te/%d" % global_pred_labels[idx]
                  ].append(path)
  
      with open(os.path.join(opt.source_path, testset)) as f:
          FileLines = f.readlines()
          FileLines = [x.strip() for x in FileLines]
  
          for entry in FileLines:
              info = entry.split("/")
              if "/".join([info[-3], info[-2]]) not in val_image_dict:
                  val_image_dict["/".join([info[-3], info[-2]])] = []
              val_image_dict["/".join([info[-3], info[-2]])].append(
                  os.path.join(opt.source_path, entry)
              )
  
      train_dataset = TrainDatasetsmoothap(train_image_dict, opt)
  
      val_dataset = BaseTripletDataset(
          val_image_dict, opt, is_validation=True
      )
  
      # train_dataset.conversion       = conversion
      # val_dataset.conversion         = conversion
      # eval_dataset.conversion        = conversion
  
      return {
          "training": train_dataset,
          "testing": val_dataset,
          "evaluation": val_dataset,
      }
  
imports: import pickle
  import warnings
  from numpy.core.arrayprint import IntegerFormat
  import copy
  import os
  import random
  import numpy
  import pandas
  import torch
  from PIL import Image
  from torch.utils.data import Dataset
  from torchvision import transforms
label_desc: Use image node_id 4 for calling a global function with example usage: give_inat_datasets_finetune_1head(testset, cluster_label_path, opt) and returns: dict