Untitled

 avatar
unknown
python
a year ago
2.3 kB
7
Indexable
preds_test = []
target_test = []

for true_boxes, true_names, pred_boxes, pred_names, confs in zip(
    bbox_info['true_bboxes'],
    bbox_info['true_bboxes_names'],
    bbox_info['pred_bboxes'],
    bbox_info['pred_bboxes_names'],
    bbox_info['pred_confs']
): # IMAGE ITER
  is_1d_true = np.shape(true_names) != (1,)
  is_1d_pred = np.shape(np.squeeze(pred_names)) != ()
  # print('eyeyeyeyey')

  true_boxes = np.squeeze(np.array(true_boxes))
  true_names = np.squeeze(np.array(true_names)) if is_1d_true else np.array(true_names)
  pred_boxes = np.squeeze(np.array(pred_boxes))
  pred_names = np.squeeze(np.array(pred_names))

  if pred_boxes.ndim == 1:
    pred_boxes = np.array([pred_boxes])
  elif pred_boxes.ndim == 0:
    print('coño de la madre')
    continue

  if true_boxes.ndim == 1:
    true_boxes = np.array([true_boxes])

  if np.shape(pred_names) == ():
    pred_names = np.array([pred_names])
    # print('nDIM 0')

  t_true_names, t_pred_names = class_name_converse(true_names, pred_names)

  for t_kitti_class in np.unique(t_true_names):
    if t_kitti_class == 'DontCare':
      # print('dontcare')
      continue
    # kitti_args = np.nonzero(true_boxes[true_names == kitti_class])
    kitti_boxes = true_boxes[t_true_names == t_kitti_class]
    yolo_boxes =  pred_boxes[t_pred_names == t_kitti_class]
    # print('care')
    class_pairs = get_matches(kitti_boxes, yolo_boxes, confs)

    # Initialize variables for new dict of tensors.
    boxes_pred = np.array([])
    boxes_true = np.array([])
    # scores = np.array(confs)
    labels_pred = np.array([])
    labels_true = np.array([])
    scores = np.array([])


    for pair in class_pairs:
      true_box = np.array(pair[0])
      pred_box = np.array(pair[1])

      boxes_pred = np.append(boxes_pred, pred_box, axis=0)
      boxes_true = np.append(boxes_true, true_box, axis=0)
      scores = np.append(scores, np.abs(intersection_over_union(true_box, pred_box)[0]))
      labels_pred = np.append(labels_pred, int(class_to_id[t_kitti_class]))
      labels_true = np.append(labels_true, int(class_to_id[t_kitti_class]))

  preds_test.append(dict(
      boxes=boxes_pred.reshape(-1, 4),
      scores=scores,
      labels=labels_pred.astype(int)
  ))

  target_test.append(dict(
      boxes=boxes_true.reshape(-1, 4),
      labels=labels_true.astype(int)
  ))


Editor is loading...
Leave a Comment