def gpu_fft_run_times_with_img_copy(): image_pth = Path(os.path.dirname( os.path.realpath(__file__))) / Path("../simulation/screenshot.png") screenshot = SimulPLIF(img_path=image_pth, num_repeats=1) img_height, img_width = screenshot[0].squeeze(0).numpy().shape train_dataloader = torch.utils.data.DataLoader(screenshot, batch_size=1, pin_memory=PIN_MEMORY) with open("gpu_fftconv_with_img_copy_run_times.csv", "w", newline="") as csvfile: writer = csv.writer(csvfile) writer.writerow(["n_bin", "max_sigma", "time"]) for i in range(REPEATS): 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 = DifferenceOfGaussiansFFT( img_height=img_height, img_width=img_width, 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() torch.cuda.synchronize(DEVICE) START = time.monotonic() img_tensor = next(iter(train_dataloader)) img_tensor = img_tensor.to(DEVICE, non_blocking=PIN_MEMORY) torch.cuda.synchronize(DEVICE) mask, local_maxima = model(img_tensor) m, l = next(zip(mask, local_maxima)) blobs = model.make_blobs(m, l) torch.cuda.synchronize(DEVICE) END = time.monotonic() res = [n_bin, max_sigma, END - START] writer.writerow(res) print(res)
def gpu_accuracy(): test_img_dir = Path(os.path.dirname( os.path.realpath(__file__))) / Path("../simulation/test_data/") screenshot = PLIF(plif_dir=test_img_dir, ext="png", include_paths=True) img_height, img_width = screenshot[0][0].squeeze(0).numpy().shape train_dataloader = DataLoader(screenshot, batch_size=1, pin_memory=PIN_MEMORY, shuffle=False) with torch.no_grad(): model = DifferenceOfGaussiansFFT( img_height=img_height, img_width=img_width, min_sigma=min_sigma, max_sigma=mx_sigma, overlap=0.5, threshold=0.1, prune=False, sigma_bins=max_bin, ).to(DEVICE, non_blocking=PIN_MEMORY) for p in model.parameters(): p.requires_grad = False model.eval() for img_tensor, image_pth in train_dataloader: img_tensor = img_tensor.to(DEVICE, non_blocking=PIN_MEMORY) mask, local_maxima = model(img_tensor) m, l = next(zip(mask, local_maxima)) blobs = model.make_blobs(m, l) # make_circles_fig(screenshot[0][0].numpy(), blobs).show() # break image_pth = list(image_pth)[0] fn = str( Path(os.path.dirname(os.path.realpath(__file__))) / f"accuracy_results/gpu/{os.path.basename(image_pth)}.res") np.savetxt(fn, blobs) print(fn)