PhotorealismEnhancement
PhotorealismEnhancement copied to clipboard
Attribute error in sample_matches.py
Hello,
Thanks for the great work. Inside matching/feature_based/sample_matches.py
the images are loaded by calling get_by_path
method of the datasets.

However, the ImageDataset
class does not have such an attribute, so this ends up with an error.
Replacing that with the _load_img
method and applying ToTensor()
on its output solved the issue for me.
For your notice. Cheers!
from what i understood, they hardcoded the name GTA in their scripts
Hey, alongside replacing with the _load_img
and applying torch.from_numpy()
, I also needed to permute channels accordingly, and in the end make cpu detach in matching/feature_based/sample_matches.py
. Below is my code:
for x in range(min(25,src_id.shape[0])):
i = int(rd[x])
print(f'\tloading sample {i}...')
#img, _ = src_dataset.get_by_path(src_paths[int(src_id[i])])
img = torch.from_numpy(src_dataset._load_img(src_paths[int(src_id[i])])).permute(2,0,1)
print("img size", img.size())
r0,r1,c0,c1 = src_coords[int(src_id[i])]
a = img[:,r0:r1,c0:c1].unsqueeze(0)
#img, _ = dst_dataset.get_by_path(dst_paths[int(dst_id[int(src_id[i]), int(knn[i])])])
img = torch.from_numpy(dst_dataset._load_img(dst_paths[int(dst_id[int(src_id[i]), int(knn[i])])])).permute(2,0,1)
r0,r1,c0,c1 = dst_coords[int(dst_id[int(src_id[i]), int(knn[i])])]
b = img[:,r0:r1,c0:c1].unsqueeze(0)
crops.append(a)
crops.append(b)
pass
if len(crops) > 0:
grid = make_grid(torch.cat(crops, 0), nrow=2)
some_arr = (255.0*grid.permute(1,2,0).cpu().detach().numpy()).astype(np.uint8)
print("some_arr shp:", some_arr.shape)
imwrite(f'knn_{t}.jpg', some_arr)
pass
pass