def make_ground_truth(self, labels: List[Label3D]): """ return shape: 252*252*4, 252*252*4*3, 252*252*4*3, 252*252*4, 252*252*4, 252*252*4*4 """ # filter labels by classes (cars, pedestrians and Trams) # Label has 4 properties (Classification (0th index of labels file), # centroid coordinates, dimensions, yaw) labels = list( filter(lambda x: x.classification in self.classes, labels)) if len(labels) == 0: pX, pY = int(self.Xn / self.downscaling_factor), int( self.Yn / self.downscaling_factor) a = int(self.anchor_dims.shape[0]) return np.zeros((pX, pY, a), dtype='float32'), np.zeros((pX, pY, a, self.nb_dims), dtype='float32'), \ np.zeros((pX, pY, a, self.nb_dims), dtype='float32'), np.zeros((pX, pY, a), dtype='float32'), \ np.zeros((pX, pY, a, self.nb_classes), dtype='float64') # For each label file, generate these properties except for the Don't care class target_positions = np.array([label.centroid for label in labels], dtype=np.float32) target_dimension = np.array([label.dimension for label in labels], dtype=np.float32) target_yaw = np.array([label.yaw for label in labels], dtype=np.float32) target_class = np.array( [self.classes[label.classification] for label in labels], dtype=np.int32) assert np.all(target_yaw >= -np.pi) & np.all(target_yaw <= np.pi) assert len(target_positions) == len(target_dimension) == len( target_yaw) == len(target_class) target, pos, neg = createPillarsTarget( target_positions, target_dimension, target_yaw, target_class, self.anchor_dims, self.anchor_z, self.anchor_yaw, self.positive_iou_threshold, self.negative_iou_threshold, self.nb_classes, self.downscaling_factor, self.x_step, self.y_step, self.x_min, self.x_max, self.y_min, self.y_max, self.z_min, self.z_max, False) self.pos_cnt += pos self.neg_cnt += neg # return a merged target view for all objects in the ground truth and get categorical labels sel = select_best_anchors(target) # class_label = np.array(sel[...,9],dtype='uint8').tolist() # print(class_label) # one_hot_encode = to_categorical(sel[..., 9], num_classes=self.nb_classes) one_hot_encode = tf.keras.utils.to_categorical( sel[..., 9], num_classes=self.nb_classes, dtype='float64') # 252*252*4, 252*252*4*3, 252*252*4*3 252*252*4 252*252*4, 252*252*4*4 return sel[..., 0], sel[..., 1:4], sel[..., 4:7], sel[..., 7], sel[..., 8], one_hot_encode
def make_ground_truth(self, labels: List[Label3D]): # filter by class labels = list(filter(lambda x: x.classification in self.classes, labels)) if len(labels) == 0: return target_positions = np.array([label.centroid for label in labels], dtype=np.float32) target_dimension = np.array([label.dimension for label in labels], dtype=np.float32) target_yaw = np.array([label.yaw for label in labels], dtype=np.float32) target_class = np.array([self.classes[label.classification] for label in labels], dtype=np.int32) assert np.all(target_yaw >= -np.pi) & np.all(target_yaw <= np.pi) assert len(target_positions) == len(target_dimension) == len(target_yaw) == len(target_class) target = createPillarsTarget(target_positions, target_dimension, target_yaw, target_class, self.anchor_dims, self.anchor_z, self.anchor_yaw, self.positive_iou_threshold, self.negative_iou_threshold, self.nb_classes, self.downscaling_factor, self.x_step, self.y_step, self.x_min, self.x_max, self.y_min, self.y_max, self.z_min, self.z_max, False) best_anchors = target[..., 0:1].argmax(0) selection = select(target, best_anchors) # one hot encoding of class clf = selection[..., 9] clf[clf == -1] = 0 ohe = np.eye(self.nb_classes)[np.array(clf, dtype=np.int32).reshape(-1)] ohe = ohe.reshape(list(clf.shape) + [self.nb_classes]) return selection[..., 0], selection[..., 1:4], selection[..., 4:7], selection[..., 7], selection[..., 8], ohe
def test_pillar_target_creation(): dims = np.array([[3.7, 1.6, 1.4], [3.7, 1.6, 1.4], [0.8, 0.6, 1.7]], dtype=np.float32) posn = np.array([[50, 10, 0], [20, 0, 0], [30, 5, 0]], dtype=np.float32) yaws = np.array([0, 0, 90], dtype=np.float32) target = createPillarsTarget(posn, dims, yaws, np.array([1, 1, 2], dtype=np.int32), dims[[0, 2]], np.array([0, 0], dtype=np.float32), np.array([0, 90], dtype=np.float32), 0.5, 0.4, 10, 2, 0.1, 0.1, 0, 80, -40, 40, -3, 1, True) assert target.shape == (3, 400, 400, 2, 10) assert (target[..., 0] == 1).sum() == 83 selected = target[..., 0:1].argmax(axis=0) target = select(target, selected) assert (target.shape == (400, 400, 2, 10))