cqylunlun / GLASS

[ECCV 2024] Official Implementation and Dataset Release for <A Unified Anomaly Synthesis Strategy with Gradient Ascent for Industrial Anomaly Detection and Localization>
MIT License
156 stars 19 forks source link

A Bug? [glass.py: line 271] #4

Closed SimpleXP closed 3 months ago

SimpleXP commented 3 months ago

should self.c /= len(training_data) in upper level with the for loop?

SimpleXP commented 3 months ago

this part:

for i, data in enumerate(training_data):
    img = data["image"]
    img = img.to(torch.float).to(self.device)
    batch_mean = torch.mean(img, dim=0)
    if i == 0:
        self.c = batch_mean
    else:
        self.c += batch_mean
    self.c /= len(training_data)

should be:

for i, data in enumerate(training_data):
    img = data["image"]
    img = img.to(torch.float).to(self.device)
    batch_mean = torch.mean(img, dim=0)
    if i == 0:
        self.c = batch_mean
    else:
        self.c += batch_mean
self.c /= len(training_data)

right?

cqylunlun commented 3 months ago

Thank you very much for your careful review. You clearly pointed out the bug. We have found that it was introduced when we accidentally indented self.c /= len(training_data) while removing Chinese comments. The bug at line 271 in glass.py has now been fixed.