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
130 stars 17 forks source link

请问前景掩码文件怎么生成呢?我看配置文件里面fg的默认参数为1,而默认为1的话是直接到数据集文件里面读取前景掩码,所以运行就直接报错了。当把默认参数fg改为0.即不使用前景掩码,其结果又跟论文报告的有较大差距(也可能是我显卡设备不同的原因) #18

Closed Winnne-cod closed 2 weeks ago

Winnne-cod commented 1 month ago
    mask_fg = mask_s = aug_image = torch.tensor([1])
    if self.split == DatasetSplit.TRAIN:
        # print(self.anomaly_source_paths)
        aug = PIL.Image.open(np.random.choice(self.anomaly_source_paths)).convert("RGB")
        if self.rand_aug:
            transform_aug = self.rand_augmenter()
            aug = transform_aug(aug)
        else:
            aug = self.transform_img(aug)

        xlsx_path = './datasets/excel/' + self.dataset_name + '_distribution.xlsx'
        if self.fg == 2:  # choose by file
            try:
                if self.first_read:
                    df = pd.read_excel(xlsx_path)
                    self.class_fg = df.loc[df['Class'] == self.dataset_name + '_' + classname, 'Foreground'].values[0]
                    self.first_read = 0
            except:
                self.class_fg = 1
        elif self.fg == 1:  # with foreground mask
            self.class_fg = 1
        else:  # without foreground mask
            self.class_fg = 0

        if self.class_fg:
            fgmask_path = image_path.split(classname)[0] + 'fg_mask/' + classname + '/' + os.path.split(image_path)[-1]
            mask_fg = PIL.Image.open(fgmask_path)
            mask_fg = torch.ceil(self.transform_mask(mask_fg)[0])

        mask_all = perlin_mask(image.shape, self.imgsize // 8, 0, 6, mask_fg, 1)
        mask_s = torch.from_numpy(mask_all[0])
        mask_l = torch.from_numpy(mask_all[1])

        beta = np.random.normal(loc=self.mean, scale=self.std)
        beta = np.clip(beta, .2, .8)
        aug_image = image * (1 - mask_l) + (1 - beta) * aug * mask_l + beta * image * mask_l

    if self.split == DatasetSplit.TEST and mask_path is not None:
        mask_gt = PIL.Image.open(mask_path).convert('L')
        mask_gt = self.transform_mask(mask_gt)
    else:
        mask_gt = torch.zeros([1, *image.size()[1:]])

FileNotFoundError: [Errno 2] No such file or directory: GLASS/main/datasets/LEISI/fg_mask/leisi/02254.jpg'

Winnne-cod commented 1 month ago

在MPDD数据集上2,3类别都学得比较差 ![image](https://github.com/user-attachments/assets/8a6838d4-5d54-4e8d-a880-342f4e8a706e

cqylunlun commented 4 weeks ago

您好,前景掩码的下载和说明我们放在了Foreground Mask节,请参照 #3 进行配置。另外,我们在不使用前景掩码的配置下进行了多次验证,Bracket_brown和Bracket_white类别未出现明显下降。请您重新检查实验配置,并考虑以下几种可能的解决方案(重要性从高到低):

  1. 每次训练开始前,清空路径./results/models
  2. 每次测试开始前,确保路径./results/models/backbone_0/mpdd_bracket_brown下只有一个ckpt_best_*.pth
  3. 测试时按照代码,默认选择ckpt_best_*.pth
  4. 确保程序运行完所有640个epoch ;
  5. 在单张显卡上重新训练;
  6. 检查数据集完整性。