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

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

Closed sunday-llight closed 1 month ago

sunday-llight commented 2 months 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'

sunday-llight commented 2 months ago

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

cqylunlun commented 2 months 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. 检查数据集完整性。
whiterAutumn commented 4 weeks ago

@cqylunlun 您好,请问MVTec-AD数据集中的前景掩码和ground_truth有什么区别吗,训练自己的数据集如果没有这两种数据是否可行呢

cqylunlun commented 4 weeks ago
  1. 前景掩码的作用是使得图像级的缺陷合成在物体表面上,而非在背景上;ground_truth为测试集中真实缺陷样本的标签掩码。
  2. 如果您自己的数据集没有前景掩码,根据经验检测精度不会出现明显下降。请参考Foreground Mask节进行配置。
  3. 如果您自己的数据集没有ground_truth,请参考问题 #8 的步骤修改源码。
whiterAutumn commented 4 weeks ago

@cqylunlun 非常感谢您的回复,谢谢。