Hi,
I was tried to adopt fast.ai to metric learning, but failed so far. There is PyTorch code for doing this (https://github.com/DagnyT/hardnet) , but conversion is not obvious to me.
Could you please help me with following case?
Data: there are image patches, which are stored in quite custom format, but there is already torch.vision dataset class for it.
But what is important, is that sampling procedure is required to output two patches of the same class:
def __getitem__(self, index):
a, p = self.data[t[0]], self.data[t[1]]
img_a = transform_img(a)
img_p = transform_img(p)
return (img_a, img_p)
Note, that img_a and img_p are images of the same class and they are aligned.
Training. During training, image patches go through model to get descriptors and then distance matrix âall_a to all_pâ is calculated. The loss function is operation on the distance matrix itself and does not require labels.
pbar = tqdm(enumerate(train_loader))
for batch_idx, data in pbar:
data_a, data_p = data
out_a = model(data_a)
out_p = model(data_p)
loss = loss_HardNet(out_a, out_p, margin=1.0)
note that loss is not just MSE so that out_a should be equal to out_p, it does compare every descriptor to each other.
So my question is how to adopt DataBunch class and ConvLearner to accept such inputs and losses? Or, may be it would be easier for me to just cut out one_cycle_policy and use it in plain PyTorch?