byungjae89 / SPADE-pytorch

PyTorch implementation of "Sub-Image Anomaly Detection with Deep Pyramid Correspondences"
Apache License 2.0
235 stars 43 forks source link

Confusion about the meaning of parameter 100 #12

Open TimZhang001 opened 2 years ago

TimZhang001 commented 2 years ago

calculate distance matrix

            dist_matrix_list = []
            for d_idx in range(feat_gallery.shape[0] // 100):
                dist_matrix = torch.pairwise_distance(feat_gallery[d_idx * 100:d_idx * 100 + **100**], test_feat_map)
                dist_matrix_list.append(dist_matrix)
            dist_matrix = torch.cat(dist_matrix_list, 0)

I don't know the meaning of parameter of 100. it will compare the tensors of 100-256-1-1 and 1-256-64-64

KenenHitomichi commented 2 years ago

I believe it's a matter of GPU's memory. The whole process is equal to: dist_matrix = torch.pairwise_distance(feat_gallery, test_feat_map) However, if you want to compute it all at once, pytorch will allocate a huge number of GPU's memory (layer1 requires nearly 45GB per test sample). Calculating them separately (e.g. 100 pixels at a time) can reduce the usage of memory.