class_docstr: Find duplicates using CNN and/or generate CNN encodings given a single image or a directory of images.
  
  The module can be used for 2 purposes: Encoding generation and duplicate detection.
  - Encodings generation:
  To propagate an image through a Convolutional Neural Network architecture and generate encodings. The generated
  encodings can be used at a later time for deduplication. Using the method 'encode_image', the CNN encodings for a
  single image can be obtained while the 'encode_images' method can be used to get encodings for all images in a
  directory.
  
  - Duplicate detection:
  Find duplicates either using the encoding mapping generated previously using 'encode_images' or using a Path to the
  directory that contains the images that need to be deduplicated. 'find_duplicates' and 'find_duplicates_to_remove'
  methods are provided to accomplish these tasks.
class_docstr_tok: ["Find","duplicates","using","CNN","and\/or","generate","CNN","encodings","given","a","single","image","or","a","directory","of","images",".","The","module","can","be","used","for","2","purposes",":","Encoding","generation","and","duplicate","detection",".","-","Encodings","generation",":","To","propagate","an","image","through","a","Convolutional","Neural","Network","architecture","and","generate","encodings",".","The","generated","encodings","can","be","used","at","a","later","time","for","deduplication",".","Using","the","method","'encode_image","'",",","the","CNN","encodings","for","a","single","image","can","be","obtained","while","the","'encode_images","'","method","can","be","used","to","get","encodings","for","all","images","in","a","directory",".","-","Duplicate","detection",":","Find","duplicates","either","using","the","encoding","mapping","generated","previously","using","'encode_images","'","or","using","a","Path","to","the","directory","that","contains","the","images","that","need","to","be","deduplicated",".","'find_duplicates","'","and","'find_duplicates_to_remove'","methods","are","provided","to","accomplish","these","tasks","."]
docstr: Initialize a pytorch MobileNet model v3 that is sliced at the last convolutional layer.
  Set the batch size for pytorch dataloader to be 64 samples.
  
  Args:
      verbose: Display progress bar if True else disable it. Default value is True.
      model_config: A CustomModel that can be used to initialize a custom PyTorch model along with the corresponding transform.
docstr_tok: ["Initialize","a","pytorch","MobileNet","model","v3","that","is","sliced","at","the","last","convolutional","layer",".","Set","the","batch","size","for","pytorch","dataloader","to","be","64","samples",".","Args",":","verbose",":","Display","progress","bar","if","True","else","disable","it",".","Default","value","is","True",".","model_config",":","A","CustomModel","that","can","be","used","to","initialize","a","custom","PyTorch","model","along","with","the","corresponding","transform","."]
code: def __init__(
      self,
      verbose: bool = True,
      model_config: CustomModel = CustomModel(
          model=MobilenetV3(),
          transform=MobilenetV3.transform,
          name=MobilenetV3.name,
      ),
  ) -> None:
      """
      Initialize a pytorch MobileNet model v3 that is sliced at the last convolutional layer.
      Set the batch size for pytorch dataloader to be 64 samples.
  
      Args:
          verbose: Display progress bar if True else disable it. Default value is True.
          model_config: A CustomModel that can be used to initialize a custom PyTorch model along with the corresponding transform.
      """
      self.model_config = model_config
      self._validate_model_config()
  
      self.logger = return_logger(
          __name__
      )  # The logger needs to be bound to the class, otherwise stderr also gets
      # directed to stdout (Don't know why that is the case)
  
      self.batch_size = 64
      self.device = torch.device(
          "cuda" if torch.cuda.is_available() else "cpu"
      )
      self.logger.info(f"Device set to {self.device} ..")
  
      self.model = self.model_config.model
      self.model.to(self.device)
  
      self.transform = self.model_config.transform
      self.logger.info(
          f"Initialized: {self.model_config.name} for feature extraction .."
      )
      self.verbose = 1 if verbose is True else 0
  
imports: from pathlib import Path, PurePath
  import sys
  from typing import Dict, List, Optional, Union
  import warnings
  from multiprocessing import cpu_count
  import numpy
  from PIL import Image
  import torch
  from imagededup.handlers.search.retrieval import get_cosine_similarity
  from imagededup.utils.data_generator import img_dataloader
  from imagededup.utils.models import CustomModel, MobilenetV3, DEFAULT_MODEL_NAME
  from imagededup.utils.general_utils import generate_relative_names, get_files_to_remove, save_json
  from imagededup.utils.image_utils import expand_image_array_cnn, load_image, preprocess_image
  from imagededup.utils.logger import return_logger
label_desc: Use image node_id 1 to create a new CNN object  with example: obj = CNN(verbose, model_config)