Skip to content

Commit

Permalink
++
Browse files Browse the repository at this point in the history
  • Loading branch information
achanhon committed Feb 8, 2024
1 parent 7538e20 commit 338804f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions geometry/firsttest/smaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ def forward(self, x):
def computeDist(A):
A_expanded = A.unsqueeze(1)
A_diff = A_expanded - A_expanded.permute(0, 2, 1)
D = A_diff.pow(2)
D = A_diff.pow(2)
return D.mean(0)


with torch.no_grad():
net = FeatureExtractor()

Expand All @@ -51,26 +50,26 @@ def computeDist(A):

print("extract stats")
allfeatures.cuda().half()
# norm = torch.sqrt((allfeatures**2).sum(0).unsqueeze(0)).half()
# allfeatures = allfeatures / (norm + 0.0001)
norm = torch.sqrt((allfeatures**2).sum(0).unsqueeze(0)).half()
meannorm = norm.flatten().mean()

allfeatures = allfeatures.flatten(1)
assert allfeatures.shape == (128, 310 * 310)

# GRAM = torch.matmul(torch.transpose(allfeatures, 0, 1), allfeatures)
GRAM = computeDist(allfeatures)
#GRAM = torch.matmul(torch.transpose(allfeatures, 0, 1), allfeatures)
GRAM = computeDist( allfeatures)
del allfeatures
torch.diagonal(GRAM).fill_(-1)
assert GRAM.shape == (310 * 310, 310 * 310)

maxGRAM, _ = GRAM.max(1)
assert GRAM.shape[0] == 310 * 310
del GRAM

seuil = sorted(list(maxGRAM.cpu().numpy()))
seuil = seuil[-100]
maxGRAM = maxGRAM.view(310, 310)
print((maxGRAM > seuil).float().sum())
print((maxGRAM>seuil).float().sum())

image620 = torch.nn.functional.interpolate(image, size=310, mode="bilinear")
image620 = image620[0] / 255
Expand Down

0 comments on commit 338804f

Please sign in to comment.