Untitled

img_comp
mail@pastecode.io avatar
unknown
plain_text
25 days ago
1.4 kB
0
Indexable
Never
conv = ConvEmbedding()
rec_model = Triplet(conv)
model_state_dict = torch.load(config['path_to_recognition_weights'], map_location=torch.device('cpu'))['model_state_dict']
rec_model.load_state_dict(model_state_dict)
rec_model.eval()
-----

import matplotlib.pyplot as plt
import numpy as np

# images = np.random.rand(3, 128, 128)

fig, axs = plt.subplots(1, 3, figsize=(10, 10))
for i in range(3):
    batch_img = np.transpose(batch[0][i], (1, 2, 0))
    axs[i].imshow(batch_img, cmap='gray')
    axs[i].axis('off')
plt.show()

fig, axs = plt.subplots(1, 3, figsize=(10, 10))
for i in range(3):
    batch_img = np.transpose(batch[1][i], (1, 2, 0))
    axs[i].imshow(batch_img, cmap='gray')
    axs[i].axis('off')
plt.show()

fig, axs = plt.subplots(1, 3, figsize=(10, 10))
for i in range(3):
    batch_img = np.transpose(batch[2][i], (1, 2, 0))
    axs[i].imshow(batch_img, cmap='gray')
    axs[i].axis('off')
plt.show()


from sklearn.metrics.pairwise import euclidean_distances as L2, cosine_similarity as cs

anchor_resp = rec_model.encoder(batch[0][0].unsqueeze(0)) #.shape
pos_resp = rec_model.encoder(batch[0][1].unsqueeze(0)) #.shape
neg_resp = rec_model.encoder(batch[0][2].unsqueeze(0)) #.shape

print('ANCHOR / POS', L2(anchor_resp.detach().numpy(), pos_resp.detach().numpy())[0][0])
print('ANCHOR / NEG', L2(anchor_resp.detach().numpy(), neg_resp.detach().numpy())[0][0])