def test_vis_graph():
    from tensorboardX import SummaryWriter
    # 可视化网络结构
    dataset = UCSDPed1(path=Config.video_folder)  # 所以 Config也要写对
    model = LSAUCSD(input_shape=dataset.shape,
                    code_length=64,
                    cpd_channels=100).to(device).eval()
    model_input = torch.rand([1380, 1, 8, 32, 32]).to(device)
    with SummaryWriter(log_dir="./summary/graphs/LSAUCSD") as writer:
        writer.add_graph(model, input_to_model=model_input)
def test_get_c_init():
    import os, time
    from datasets import UCSDPed2_TRAIN

    dataset = UCSDPed2_TRAIN(path="data/UCSD_Anomaly_Dataset.v1p2")  # 需重写
    net = LSAUCSD(input_shape=dataset.shape, code_length=64,
                  cpd_channels=100).to(device).eval()
    # 偷个懒,暂时直接使用作者预训练模型,后面再改成 AE预训练
    checkpoint = "checkpoints/ucsd_ped2.pkl"
    if os.path.exists(checkpoint):
        print("{} load !".format(checkpoint))
        net.load_w(checkpoint)
    # 只保留 Encoder部分
    # net = "" # 不需要,因为直接输出 z (latent vector) 就 OK 了
    #
    batch_size = 2
    c = init_center_c(dataset, net, batch_size)
    # Use torch.save(tensor, 'file.pt') and torch.load('file.pt')
    torch.save(c, "c_init_ped2.pt")
    cl = torch.load("c_init_ped2.pt")
    print("c1.shape: ", cl.shape)
def test_ucsdped2():
    # type: () -> None
    """
    Performs video anomaly detection tests on UCSD Ped2.
    """

    # Build dataset and model
    dataset = UCSDPed2(path=Config.video_folder)
    model = LSAUCSD(input_shape=dataset.shape,
                    code_length=64,
                    cpd_channels=100).to(device).eval()

    # Set up result helper and perform test
    helper = VideoAnomalyDetectionResultHelper(dataset,
                                               model,
                                               checkpoint=Config.model_ckpt,
                                               output_file=Config.output_file)
    helper.test_video_anomaly_detection()
Esempio n. 4
0
def test_ucsdped2():
    # type: () -> None
    """
    Performs video anomaly detection tests on UCSD Ped2.
    """

    # Build dataset and model
    dataset = UCSDPed2(path='data/UCSD_Anomaly_Dataset.v1p2')
    model = LSAUCSD(input_shape=dataset.shape,
                    code_length=64,
                    cpd_channels=100).cuda().eval()

    # Set up result helper and perform test
    helper = VideoAnomalyDetectionResultHelper(
        dataset,
        model,
        checkpoint='checkpoints/ucsd_ped2.pkl',
        output_file='ucsd_ped2.txt')
    helper.test_video_anomaly_detection()