Exemplo n.º 1
0
def FAN_model(resource, model):
    preds = fan_labeler(resource)

    # create structure for AI Labeler result
    frames_name = []
    frames_kpts = []
    types = ('*.jpg', '*.png')
    files_grabbed = []
    for files in types:
        files_grabbed.extend(glob.glob(os.path.join(resource, files)))
    im_list = sorted(files_grabbed)
    for i in range(len(preds)):
        sp_kpts = []
        frames_name.append(im_list[i])
        arr = np.empty([2, 68])
        for j in range(len(preds[0])):
            arr[0, j] = preds[i][j][0]
            arr[1, j] = preds[i][j][1]

        sp_kpts.append(arr)
        frames_kpts.append(sp_kpts)

    predictions = {}
    predictions['all_keyps'] = [[], frames_kpts]
    predictions['all_boxes'] = [[] for i in range(len(frames_kpts))]

    helpers.savepkl(predictions, resource, model)
Exemplo n.º 2
0
    def update_flags(self):
        global result
        for num in range(num_poses):
            result['all_keyps'][1][self.idx][num] = np.append(
                result['all_keyps'][1][self.idx][num],
                np.ones((1, num_kpts)),
                axis=0)
            result['all_boxes'][self.idx].append(bbox)
        for i in range(len(fixed)):
            pose = int(fix[i] / num_kpts)
            joint = fix[i] % num_kpts
            # print(result['all_keyps'][1][self.idx][pose][0][joint])
            result['all_keyps'][1][self.idx][pose][0][joint] = fixed[i][0]
            result['all_keyps'][1][self.idx][pose][1][joint] = fixed[i][1]
            result['all_keyps'][1][self.idx][pose][-1][joint] = fixed[i][2]

        self.idx = self.idx + 1
        if self.idx < len(self.frames_kpts):
            self.show_flags()
        else:
            messagebox.showinfo(
                "Information",
                "All frames are revised and keypoints are saved!")
            helpers.savepkl(result, self.resource, "gt")
            plt.close()
Exemplo n.º 3
0
def detectron2_model(resource, model):
    preds = inference(resource)
    # create structure for AI Labeler result
    frames_name = []
    frames_kpts = []
    types = ('*.jpg', '*.png')
    files_grabbed = []
    for files in types:
        files_grabbed.extend(glob.glob(os.path.join(resource, files)))
    im_list = sorted(files_grabbed)
    for i in range(len(preds)):
        sp_kpts = []
        frames_name.append(im_list[i])
        arr = np.empty([2, 17])
        filename = os.path.basename(im_list[i])
        print(filename)
        print(len(preds[filename]['keypoints']))
        if len(preds[filename]['keypoints']) == 0:
            os.remove(os.path.join(resource, filename))
            continue

        for j in range(len(preds[filename]['keypoints'][0])):
            arr[0, j] = preds[filename]['keypoints'][0][j][0]
            arr[1, j] = preds[filename]['keypoints'][0][j][1]

        sp_kpts.append(arr)
        frames_kpts.append(sp_kpts)

    predictions = {}
    predictions['all_keyps'] = [[], frames_kpts]
    predictions['all_boxes'] = [[] for i in range(len(frames_kpts))]

    helpers.savepkl(predictions, resource, model)
    def update_figure(self):
        global flag
        list_flag = []
        list = [1] * num_kpts * num_poses
        for i in range(len(vis_idx)):
            list[vis_idx[i]] = flag[i]
        for pose in range(num_poses):
            list_flag.append(list[pose * num_kpts:(pose + 1) * num_kpts])
        dict_flags[str(self.idx)] = list_flag
        print(dict_flags)

        self.idx = self.idx + 1
        if self.idx < len(self.frames_kpts):
            self.show_figure()
        else:
            messagebox.showinfo(
                "Information", "All frames are reviewed and flags are saved!")
            helpers.savepkl(dict_flags, self.resource, "flag")
            plt.close()
def hourglass_model(resource, model):
    preds = hg_labeler(resource)

    # create structure for AI Labeler result
    frames_name = []
    frames_kpts = []
    im_list = sorted(glob.glob(os.path.join(resource, "*.jpg")))
    for i in range(len(preds)):
        sp_kpts = []
        frames_name.append(im_list[i])
        arr = np.empty([2, 16])
        for j in range(len(preds[0])):
            arr[0, j] = preds[i][j][0]
            arr[1, j] = preds[i][j][1]

        sp_kpts.append(arr)
        frames_kpts.append(sp_kpts)

    predictions = {}
    predictions['all_keyps'] = [[], frames_kpts]
    predictions['all_boxes'] = [[] for i in range(len(frames_kpts))]

    helpers.savepkl(predictions, resource, model)