class_docstr: Method from Chen et al., 2018 performing poisoning detection based on activations clustering.
  
  | Paper link: https://arxiv.org/abs/1811.03728
  
  | Please keep in mind the limitations of defences. For more information on the limitations of this
      defence, see https://arxiv.org/abs/1905.13409 . For details on how to evaluate classifier security
      in general, see https://arxiv.org/abs/1902.06705
docstr: This function creates the sprite/mosaic visualization for clusters. When save=True,
  it also stores a sprite (mosaic) per cluster in art.config.ART_DATA_PATH.
  
  :param x_raw: Images used to train the classifier (before pre-processing).
  :param save: Boolean specifying if image should be saved.
  :param folder: Directory where the sprites will be saved inside art.config.ART_DATA_PATH folder.
  :param kwargs: a dictionary of cluster-analysis-specific parameters.
  :return: Array with sprite images sprites_by_class, where sprites_by_class[i][j] contains the
                            sprite of class i cluster j.
docstr_tok: ["This","function","creates","the","sprite\/mosaic","visualization","for","clusters",".","When","save=True",",","it","also","stores","a","sprite","(","mosaic",")","per","cluster","in","art.config.ART_DATA_PATH",".",":","param","x_raw",":","Images","used","to","train","the","classifier","(","before","pre-processing",")",".",":","param","save",":","Boolean","specifying","if","image","should","be","saved",".",":","param","folder",":","Directory","where","the","sprites","will","be","saved","inside","art.config.ART_DATA_PATH","folder",".",":","param","kwargs",":","a","dictionary","of","cluster-analysis-specific","parameters",".",":","return",":","Array","with","sprite","images","sprites_by_class",",","where","sprites_by_class","[","i","]","[","j","]","contains","the","sprite","of","class","i","cluster","j","."]
code: def visualize_clusters(
      self,
      x_raw: np.ndarray,
      save: bool = True,
      folder: str = ".",
      **kwargs,
  ) -> List[List[np.ndarray]]:
      """
      This function creates the sprite/mosaic visualization for clusters. When save=True,
      it also stores a sprite (mosaic) per cluster in art.config.ART_DATA_PATH.
  
      :param x_raw: Images used to train the classifier (before pre-processing).
      :param save: Boolean specifying if image should be saved.
      :param folder: Directory where the sprites will be saved inside art.config.ART_DATA_PATH folder.
      :param kwargs: a dictionary of cluster-analysis-specific parameters.
      :return: Array with sprite images sprites_by_class, where sprites_by_class[i][j] contains the
                                sprite of class i cluster j.
      """
      self.set_params(**kwargs)
  
      if not self.clusters_by_class:
          self.cluster_activations()
  
      x_raw_by_class = self._segment_by_class(x_raw, self.y_train)
      x_raw_by_cluster: List[List[np.ndarray]] = [  # type: ignore
          [[] for _ in range(self.nb_clusters)] for _ in range(self.classifier.nb_classes)  # type: ignore
      ]
  
      # Get all data in x_raw in the right cluster
      for n_class, cluster in enumerate(self.clusters_by_class):
          for j, assigned_cluster in enumerate(cluster):
              x_raw_by_cluster[n_class][assigned_cluster].append(
                  x_raw_by_class[n_class][j]
              )
  
      # Now create sprites:
      sprites_by_class: List[List[np.ndarray]] = [  # type: ignore
          [[] for _ in range(self.nb_clusters)] for _ in range(self.classifier.nb_classes)  # type: ignore
      ]
      for i, class_i in enumerate(x_raw_by_cluster):
          for j, images_cluster in enumerate(class_i):
              title = (
                  "Class_"
                  + str(i)
                  + "_cluster_"
                  + str(j)
                  + "_clusterSize_"
                  + str(len(images_cluster))
              )
              f_name = title + ".png"
              f_name = os.path.join(folder, f_name)
              sprite = create_sprite(np.array(images_cluster))
              if save:
                  save_image(sprite, f_name)
              sprites_by_class[i][j] = sprite
  
      return sprites_by_class
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import os
  import pickle
  import time
  from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING
  import numpy
  from sklearn.cluster import KMeans, MiniBatchKMeans
  from art import config
  from art.data_generators import DataGenerator
  from art.defences.detector.poison.clustering_analyzer import ClusteringAnalyzer
  from art.defences.detector.poison.ground_truth_evaluator import GroundTruthEvaluator
  from art.defences.detector.poison.poison_filtering_defence import PoisonFilteringDefence
  from art.utils import segment_by_class
  from art.visualization import create_sprite, save_image, plot_3d
label_desc: Use image node_id 12 for calling the ActivationDefence obj's underlying member method code with example usage: obj.visualize_clusters(x_raw, save, folder) and returns: sprites_by_class