コード例 #1
0
def main():
    # Parse arguments (options)
    opts = parse_opts()

    # Read labels
    # label_file = opts.datasets_dir + '/' + opts.datasets + '/splits/pkummd.json'
    label_file = opts.datasets_dir + '/' + opts.datasets + '/splits/pkummd_cross_subject_background.json'
    class_file = opts.datasets_dir + '/' + opts.datasets + '/splits/classInd.txt'
    labels = video_utils.VideoLabels(label_file, class_file, opts.datasets)
    txt_labels = read_txt_labels(class_file)

    assert _FUSION_METHOD == "exponential_smoothing", "Fusion method NotImplemented"

    use_siminet = (opts.sim_method == "siminet" or opts.corr_at_transition
                   or opts.corr_per_window)
    if use_siminet:
        assert opts.siminet_path != '', "Siminet model path cannot be empty"
        siminet.load_siminet_model(opts.n_classes, opts.siminet_path)

    # _VIDEOS_LST = labels.labels_key
    for video in _VIDEOS_LST:
        ret = get_predicted_actions(opts=opts, video=video, labels=labels)
        if ret is not None:
            local_predicted_actions, remote_predicted_actions, fusion_predicted_actions, true_actions = ret
            predictions = list(
                zip(local_predicted_actions, remote_predicted_actions,
                    fusion_predicted_actions))
            assert len(predictions) == len(true_actions)

            video_file = opts.datasets_dir + "/" + opts.datasets + f"/videos/{video}.{_VIDEO_EXTENSION}"
            window_size = opts.window_size

            try:
                visualizer = Visualizer(video_file,
                                        window_size,
                                        predictions,
                                        true_actions,
                                        txt_labels,
                                        target_fps=_TARGET_FPS,
                                        use_qt=_USE_QT)
                visualizer.display()
            except Visualizer.VideoError as e:
                print(f"Cannot open video file: {e.filename}")