class_docstr: Train the SVM for the low-shot image classification tasks. Currently,
  datasets like VOC07 and Places205 are supported.
  
  The trained inherits from the SVMTrainer class and takes care of
  training SVM, evaluating, and aggregate the metrics.
class_docstr_tok: ["Train","the","SVM","for","the","low-shot","image","classification","tasks",".","Currently",",","datasets","like","VOC07","and","Places205","are","supported",".","The","trained","inherits","from","the","SVMTrainer","class","and","takes","care","of","training","SVM",",","evaluating",",","and","aggregate","the","metrics","."]
docstr: Test the SVM for the input test features and targets for the given:
      low-shot k-value, sample number
  
  We compute the meanAP across all classes for a given cost value.
  We get the output matrix of shape (1, #costs) for the given sample_num and
  k-value and save the matrix. We use this information to aggregate
  later.
docstr_tok: ["Test","the","SVM","for","the","input","test","features","and","targets","for","the","given",":","low-shot","k-value",",","sample","number","We","compute","the","meanAP","across","all","classes","for","a","given","cost","value",".","We","get","the","output","matrix","of","shape","(","1",",","#","costs",")","for","the","given","sample_num","and","k-value","and","save","the","matrix",".","We","use","this","information","to","aggregate","later","."]
code: def test(self, features, targets, sample_num, low_shot_kvalue):
      """
      Test the SVM for the input test features and targets for the given:
          low-shot k-value, sample number
  
      We compute the meanAP across all classes for a given cost value.
      We get the output matrix of shape (1, #costs) for the given sample_num and
      k-value and save the matrix. We use this information to aggregate
      later.
      """
      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)
  
      sample_ap_matrix = np.zeros((1, len(self.costs_list)))
      suffix = f"sample{sample_num}_k{low_shot_kvalue}"
      for cost_idx in range(len(self.costs_list)):
          cost = self.costs_list[cost_idx]
          local_cost_ap = np.zeros((self.num_classes, 1))
          for cls_num in self.cls_list:
              logging.info(
                  f"Test sample/k_value/cost/cls: "
                  f"{sample_num}/{low_shot_kvalue}/{cost}/{cls_num}"
              )
              model_file = self._get_svm_low_shot_model_filename(
                  cls_num, cost, suffix
              )
              model = load_file(model_file)
              prediction = model.decision_function(features)
              eval_preds, eval_cls_labels = self._get_cls_feats_labels(
                  cls_num, prediction, targets
              )
              P, R, score, ap = get_precision_recall(
                  eval_cls_labels, eval_preds
              )
              local_cost_ap[cls_num][0] = ap
          mean_cost_ap = np.mean(local_cost_ap, axis=0)
          sample_ap_matrix[0][cost_idx] = mean_cost_ap
      out_k_sample_file = f"{self.output_dir}/test_ap_sample{sample_num}_k{low_shot_kvalue}.npy"
      save_data = sample_ap_matrix.reshape((1, -1))
      save_file(save_data, out_k_sample_file)
      logging.info(
          f"Saved sample test k_idx AP: {out_k_sample_file} {save_data.shape}"
      )
  
file_path: vissl/vissl/utils/svm_utils/svm_low_shot_trainer.py
imports: import logging
  import pickle
  import numpy
  from iopath.common.file_io import g_pathmgr
  from sklearn.svm import LinearSVC
  from vissl.utils.io import load_file, save_file
  from vissl.utils.svm_utils.evaluate import get_precision_recall
  from vissl.utils.svm_utils.svm_trainer import SVMTrainer
label_desc: Use image node_id 6 for calling the SVMLowShotTrainer obj's underlying member method code with example usage: obj.test(features, targets, sample_num, low_shot_kvalue) without return types