Skip to content

Instantly share code, notes, and snippets.

@sachadee
Created May 7, 2022 09:34
Show Gist options
  • Save sachadee/6e71c946dcc4c97948068df05f8c81c2 to your computer and use it in GitHub Desktop.
Save sachadee/6e71c946dcc4c97948068df05f8c81c2 to your computer and use it in GitHub Desktop.
final
with torch.no_grad():
for idx, (image, _) in enumerate(
tqdm(loader, desc="Create embeddings matrix", total=len(loader)),
):
embeddings = np.empty([1,512])
embeddings[int(0) :] = F.normalize(backbone(image.to(device))).cpu()
image = image[0].permute(1,2,0)
imgarr = image.cpu().detach().numpy()
print(imgarr.dtype)
opencvImage = cv2.cvtColor(imgarr, cv2.COLOR_RGB2BGR)
opencvImage = cv2.normalize(opencvImage, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
print(opencvImage.dtype)
cv2.imshow('test',opencvImage)
cv2.waitKey(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment