Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute error in sample_matches.py #26

Open
acerdur opened this issue Apr 8, 2022 · 2 comments
Open

Attribute error in sample_matches.py #26

acerdur opened this issue Apr 8, 2022 · 2 comments

Comments

@acerdur
Copy link

acerdur commented Apr 8, 2022

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.

Screen Shot 2022-04-08 at 19 23 12

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!

@ZouaghiHoussem
Copy link

from what i understood, they hardcoded the name GTA in their scripts

@czero69
Copy link

czero69 commented Nov 20, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants