예제 #1
0
    def read_labels(self):
        depth_label = cv2.imread(self.depth_gt[0], cv2.IMREAD_GRAYSCALE)

        # leggi file di testo

        with open(self.obstacles_gt[0], 'r') as f:
            obstacles = f.readlines()
        obstacles = [x.strip() for x in obstacles]

        obstacles_label = np.zeros(shape=(5, 8, 10))

        for obs in obstacles:
            parsed_str_obs = obs.split(" ")
            parsed_obs = np.zeros(shape=9)
            i = 0
            for n in parsed_str_obs:
                if i < 2:
                    parsed_obs[i] = int(n)
                elif i == 8:
                    parsed_obs[i] = Classes.str_to_class_enum(n)
                else:
                    parsed_obs[i] = float(n)
                i += 1

            obstacles_label[int(parsed_obs[1]),
                            int(parsed_obs[0]),
                            0] = 1.0 if parsed_obs[8] == 3 else 0.0  # class 3
            obstacles_label[int(parsed_obs[1]),
                            int(parsed_obs[0]),
                            1] = 1.0 if parsed_obs[8] == 4 else 0.0  # class 4
            obstacles_label[int(parsed_obs[1]),
                            int(parsed_obs[0]),
                            2] = 1.0 if parsed_obs[8] == 1 else 0.0  # class 1
            obstacles_label[int(parsed_obs[1]),
                            int(parsed_obs[0]),
                            3] = 1.0 if parsed_obs[8] == 2 else 0.0  # class 2
            obstacles_label[int(parsed_obs[1]),
                            int(parsed_obs[0]), 4] = parsed_obs[2]  # x
            obstacles_label[int(parsed_obs[1]),
                            int(parsed_obs[0]), 5] = parsed_obs[3]  # y
            obstacles_label[int(parsed_obs[1]),
                            int(parsed_obs[0]), 6] = parsed_obs[4]  # w
            obstacles_label[int(parsed_obs[1]),
                            int(parsed_obs[0]), 7] = parsed_obs[5]  # h
            obstacles_label[int(parsed_obs[1]),
                            int(parsed_obs[0]), 8] = parsed_obs[6] * 0.1  # m
            obstacles_label[int(parsed_obs[1]),
                            int(parsed_obs[0]), 9] = parsed_obs[7] * 0.1  # v
        labels = {
            "depth": np.expand_dims(depth_label, 2),
            "obstacles": np.reshape(obstacles_label, (40, 10))
        }

        return labels
예제 #2
0
def labels_from_file_multiclass_4(obstacles_gt):
    with open(obstacles_gt, 'r') as f:
        obstacles = f.readlines()
    obstacles = [x.strip() for x in obstacles]

    obstacles_label = np.zeros(shape=(5, 8, 10))

    for obs_ in obstacles:
        parsed_str_obs = obs_.split(" ")
        parsed_obs = np.zeros(shape=9)
        i_ = 0
        for n in parsed_str_obs:
            if i_ < 2:
                parsed_obs[i_] = int(n)
            elif i_ == 8:
                parsed_obs[i_] = Classes.str_to_class_enum(n)
            else:
                parsed_obs[i_] = float(n)
            i_ += 1

        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]),
                        0] = 1.0 if parsed_obs[8] == 3 else 0.0  # class 3
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]),
                        1] = 1.0 if parsed_obs[8] == 4 else 0.0  # class 4
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]),
                        2] = 1.0 if parsed_obs[8] == 1 else 0.0  # class 1
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]),
                        3] = 1.0 if parsed_obs[8] == 2 else 0.0  # class 2
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 4] = parsed_obs[2]  # x
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 5] = parsed_obs[3]  # y
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 6] = parsed_obs[4]  # w
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 7] = parsed_obs[5]  # h
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 8] = parsed_obs[6] * 0.1  # m
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 9] = parsed_obs[7] * 0.1  # v
    labels = np.reshape(obstacles_label, (40, 10))

    return labels
예제 #3
0
def labels_from_file_multiclass_2(obstacles_gt):
    with open(obstacles_gt, 'r') as f:
        obstacles = f.readlines()
    obstacles = [x.strip() for x in obstacles]

    obstacles_label = np.zeros(shape=(5, 8, 8))

    for obs_ in obstacles:
        parsed_str_obs = obs_.split(" ")
        parsed_obs = np.zeros(shape=9)
        i_ = 0
        for n in parsed_str_obs:
            if i_ < 2:
                parsed_obs[i_] = int(n)
            elif i_ == 8:
                if n == 'robot_team' or n == 'robot_opponent':
                    n = 'robot'
                elif n == 'goal':
                    n = 'nothing'
                parsed_obs[i_] = Classes.str_to_class_enum(n)
            else:
                parsed_obs[i_] = float(n)
            i_ += 1

        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]),
                        0] = 1.0 if parsed_obs[8] == 0 else 0.0  # class 0
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]),
                        1] = 1.0 if parsed_obs[8] == 1 else 0.0  # class 1
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 2] = parsed_obs[2]  # x
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 3] = parsed_obs[3]  # y
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 4] = parsed_obs[4]  # w
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 5] = parsed_obs[5]  # h
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 6] = parsed_obs[6] * 0.1  # m
        obstacles_label[int(parsed_obs[1]),
                        int(parsed_obs[0]), 7] = parsed_obs[7] * 0.1  # v
    labels = np.reshape(obstacles_label, (40, 8))

    return labels
예제 #4
0
def read_labels_gt_viewer_multiclass(obstacles_gt, number_classes):
    with open(obstacles_gt, 'r') as f:
        obstacles = f.readlines()
    obstacles = [x.strip() for x in obstacles]

    labels = []

    for obs in obstacles:
        parsed_str_obs = obs.split(" ")
        parsed_obs = np.zeros(shape=9)
        i = 0
        for n in parsed_str_obs:
            if i < 2:
                parsed_obs[i] = int(n)
            elif i == 8:
                if (number_classes == 2 or number_classes
                        == 3) and (n == 'robot_team' or n == 'robot_opponent'):
                    n = 'robot'
                elif number_classes == 2 and n == 'goal':
                    n = 'nothing'

                parsed_obs[i] = Classes.str_to_class_enum(n)
            else:
                parsed_obs[i] = float(n)
            i += 1

        x = int(parsed_obs[0] * 32 + parsed_obs[2] * 32)
        y = int(parsed_obs[1] * 32 + parsed_obs[3] * 32)
        w = int(parsed_obs[4] * 256)
        h = int(parsed_obs[5] * 160)

        object = [[x - w / 2, y - h / 2, w, h], [parsed_obs[6], parsed_obs[7]],
                  parsed_obs[8]]

        # Object with last value equal to -1 is a dispensable object
        if object[-1] != -1:
            labels.append(object)

    return labels
예제 #5
0
def read_labels_gt_viewer_multiclass_2(obstacles_gt):
    with open(obstacles_gt, 'r') as f:
        obstacles = f.readlines()
    obstacles = [x.strip() for x in obstacles]

    labels = []

    for obs in obstacles:
        parsed_str_obs = obs.split(" ")
        parsed_obs = np.zeros(shape=9)
        i = 0
        for n in parsed_str_obs:
            if i < 2:
                parsed_obs[i] = int(n)
            elif i == 8:
                if n == 'robot_team' or n == 'robot_opponent':
                    n = 'robot'

                parsed_obs[i] = Classes.str_to_class_enum(n)
            else:
                parsed_obs[i] = float(n)
            i += 1

        if parsed_obs[8] == 2:
            continue

        x = int(parsed_obs[0] * 32 + parsed_obs[2] * 32)
        y = int(parsed_obs[1] * 32 + parsed_obs[3] * 32)
        w = int(parsed_obs[4] * 256)
        h = int(parsed_obs[5] * 160)

        object = [[x - w / 2, y - h / 2, w, h], [parsed_obs[6], parsed_obs[7]],
                  parsed_obs[8]]
        labels.append(object)

    return labels
예제 #6
0
            depth_gt = gt.copy()
            #evaluate only on valid predictions (some methods like Cadena's may return zero or negative values)
            depth_gt[np.nonzero(pred_depth_ <= 0)] = 0.0
        else:
            depth_gt = None
        #Corrected depth
        if results[2] is not None:
            corr_depth = results[2][0, :, :, 0].copy()
            corr_depth[np.nonzero(depth_gt <= 0)] = 0.0
            results[2] = corr_depth

        #Get obstacles from GT segmentation and depth
        #gt_obs = EvaluationUtils.get_obstacles_from_seg_and_depth(gt, seg, segm_thr=-1)
        if model_name == 'odl':
            for ob in obs:
                ob[2] = Classes.generate_class(ob[2])

            gt_obs = EvaluationUtils.get_obstacles_from_list_multiclass(obs)
        else:
            gt_obs = EvaluationUtils.get_obstacles_from_list(obs)

        if confMatrix:
            obs_labels = []
            if number_classes == 2:
                obs_labels = labels_from_file_multiclass_2(obs_path)
            elif number_classes == 3:
                obs_labels = labels_from_file_multiclass_3(obs_path)
            elif number_classes == 4:
                obs_labels = labels_from_file_multiclass_4(obs_path)

            conf_list_pred = []