class_docstr: SVM trainer that takes care of training (using k-fold cross validation),
  and evaluating the SVMs
class_docstr_tok: ["SVM","trainer","that","takes","care","of","training","(","using","k-fold","cross","validation",")",",","and","evaluating","the","SVMs"]
docstr: Test the trained SVM models on the test features and targets values.
  We use the cost per class that gives the maximum cross validation AP on
  the training and load the correspond trained SVM model for the cost value
  and the class.
  
  Log the test ap to stdout and also save the AP in a file.
docstr_tok: ["Test","the","trained","SVM","models","on","the","test","features","and","targets","values",".","We","use","the","cost","per","class","that","gives","the","maximum","cross","validation","AP","on","the","training","and","load","the","correspond","trained","SVM","model","for","the","cost","value","and","the","class",".","Log","the","test","ap","to","stdout","and","also","save","the","AP","in","a","file","."]
code: def test(self, features, targets):
      """
      Test the trained SVM models on the test features and targets values.
      We use the cost per class that gives the maximum cross validation AP on
      the training and load the correspond trained SVM model for the cost value
      and the class.
  
      Log the test ap to stdout and also save the AP in a file.
      """
      logging.info("Testing SVM")
      # normalize the features: N x 9216 (example shape)
      if self.normalize:
          # normalize the features: N x 9216 (example shape)
          features = self._normalize_features(features)
      num_classes = targets.shape[1]
      logging.info("Num test classes: {}".format(num_classes))
      # get the chosen cost that maximizes the cross-validation AP per class
      costs_list = self.get_best_cost_value()
  
      ap_matrix = np.zeros((num_classes, 1))
      for cls_num in range(num_classes):
          cost = costs_list[cls_num]
          logging.info(f"Testing model for cls: {cls_num} cost: {cost}")
          model_file, _ = self._get_svm_model_filename(cls_num, cost)
          model = load_file(model_file)
          prediction = model.decision_function(features)
          cls_labels = targets[:, cls_num]
          # meaning of labels in VOC/COCO original loaded target files:
          # label 0 = not present, set it to -1 as svm train target
          # label 1 = present. Make the svm train target labels as -1, 1.
          evaluate_data_inds = targets[:, cls_num] != -1
          eval_preds = prediction[evaluate_data_inds]
          eval_cls_labels = cls_labels[evaluate_data_inds]
          eval_cls_labels[np.where(eval_cls_labels == 0)] = -1
          P, R, score, ap = get_precision_recall(
              eval_cls_labels, eval_preds
          )
          ap_matrix[cls_num][0] = ap
      logging.info(f"Mean test AP: {np.mean(ap_matrix, axis=0)}")
      test_ap_filepath = f"{self.output_dir}/test_ap.npy"
      save_file(np.array(ap_matrix), test_ap_filepath)
      logging.info(f"saved test AP to file: {test_ap_filepath}")
  
imports: import logging
  import pickle
  import threading
  import numpy
  from iopath.common.file_io import g_pathmgr
  from sklearn.model_selection import cross_val_score
  from sklearn.svm import LinearSVC
  from vissl.utils.io import load_file, save_file
  from vissl.utils.svm_utils.evaluate import get_precision_recall
label_desc: Use image node_id 11 for calling the SVMTrainer obj's underlying member method code with example usage: obj.test(features, targets) without return types