Exemple #1
0
def main():
    print(DATA_DIR)
    plif_dataset = PLIF(plif_dir=DATA_DIR)
    plif_dataloader = torch.utils.data.DataLoader(plif_dataset,
                                                  batch_size=1,
                                                  pin_memory=PIN_MEMORY,
                                                  num_workers=1)

    img_height, img_width = plif_dataset[0].squeeze(0).numpy().shape

    with torch.no_grad():
        model = DifferenceOfGaussiansStandardConv(
            min_sigma=1,
            max_sigma=10,
            overlap=0.9,
            threshold=0.012,
            prune=False,
            sigma_bins=20,
        ).to(DEVICE, non_blocking=PIN_MEMORY)
        for p in model.parameters():
            p.requires_grad = False
        model.eval()
        start = time.monotonic()
        for i, blobs in enumerate(torch_dog(plif_dataloader, model)):
            print(time.monotonic() - start)
            start = time.monotonic()
Exemple #2
0
def main(data_dir_path):
    plif_dataset = PLIF(plif_dir=Path(data_dir_path))
    plif_dataloader = torch.utils.data.DataLoader(plif_dataset,
                                                  batch_size=1,
                                                  pin_memory=PIN_MEMORY,
                                                  num_workers=1)

    img_height, img_width = plif_dataset[0].squeeze(0).numpy().shape
    with torch.no_grad():
        model = DifferenceOfGaussiansStandardConv(
            min_sigma=1,
            max_sigma=10,
            overlap=0.9,
            threshold=0.012,
            prune=False,
            sigma_bins=20,
        ).to(DEVICE, non_blocking=PIN_MEMORY)
        for p in model.parameters():
            p.requires_grad = False
        model.eval()

        for i, img_tensor in enumerate(plif_dataloader):
            img_tensor = img_tensor.to(DEVICE, non_blocking=PIN_MEMORY)
            mask, local_maxima = model(img_tensor.unsqueeze(0))
            blobs = model.make_blobs(mask, local_maxima)
            make_circles_fig(plif_dataset[0], blobs).show()
            break
Exemple #3
0
def gpu_standard_run_times(fn):
    image_pth = Path(os.path.dirname(os.path.realpath(__file__))) / Path(
        "../simulation/screenshot.png"
    )
    screenshot = SimulPLIF(img_path=image_pth, num_repeats=1000000)
    train_dataloader = torch.utils.data.DataLoader(
        screenshot, batch_size=1, pin_memory=PIN_MEMORY
    )

    with open(f"{fn}.csv", "w", newline="") as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(["n_bin", "max_sigma", "time"])

        for max_sigma in range(min_sigma + 1, mx_sigma + 1):
            for n_bin in range(min_bin, max_bin + 1):
                with torch.no_grad():
                    model = DifferenceOfGaussiansStandardConv(
                        min_sigma=min_sigma,
                        max_sigma=max_sigma,
                        overlap=0.9,
                        threshold=0.012,
                        prune=False,
                        sigma_bins=n_bin,
                    ).to(DEVICE, non_blocking=PIN_MEMORY)
                    for p in model.parameters():
                        p.requires_grad = False
                    model.eval()

                    for i in range(REPEATS):

                        img_tensor = next(iter(train_dataloader))
                        img_tensor = img_tensor.to(DEVICE, non_blocking=PIN_MEMORY)
                        torch.cuda.synchronize(DEVICE)

                        START = time.monotonic()

                        mask, local_maxima = model(img_tensor.unsqueeze(0))
                        blobs = model.make_blobs(mask, local_maxima)
                        torch.cuda.synchronize(DEVICE)

                        END = time.monotonic()

                        res = [n_bin, max_sigma, END - START]
                        writer.writerow(res)
                        print(res)
                    del model
Exemple #4
0
def test_simul():
    image_pth = Path(os.path.dirname(
        os.path.realpath(__file__))) / Path("../simulation/screenshot.png")
    screenshot = SimulPLIF(img_path=image_pth, num_repeats=1000000)
    with torch.no_grad():
        model = DifferenceOfGaussiansStandardConv(
            min_sigma=1,
            max_sigma=10,
            overlap=0.9,
            # threshold=0.012,
            threshold=0.112,
            prune=False,
            sigma_bins=20,
        ).to(DEVICE, non_blocking=PIN_MEMORY)
        for p in model.parameters():
            p.requires_grad = False
        model.eval()
        img_tensor = screenshot[0]
        img_tensor = img_tensor.to(DEVICE, non_blocking=PIN_MEMORY)
        mask, local_maxima = model(img_tensor.unsqueeze(0).unsqueeze(0))
        blobs = model.make_blobs(mask, local_maxima)
        make_circles_fig(screenshot[0], blobs).show()