Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some questions about training a custom dataset? #43

Open
iangiu opened this issue Oct 31, 2023 · 13 comments
Open

Some questions about training a custom dataset? #43

iangiu opened this issue Oct 31, 2023 · 13 comments

Comments

@iangiu
Copy link

iangiu commented Oct 31, 2023

Dear author, thank you very much for your work! However, I am puzzled by the following questions when i trained a model with a custom dataset.

  1. If i try to infer a new dataset, i don't need to finetune the pretrain model which you provided. Is it right? However, i can't make sense that i got a very poor result.
  2. When i infer a image with 1600*1600 pixels, it takes a few seconds. Is it normal?
  3. Whether the 8-shot pre-trained model can be used to infer support-set containing more pictures. Will it make any difference to the results?
    Looking forward to your reply! Thanks a lot!
@iangiu iangiu changed the title How to train a custom dataset? Some questions about training a custom dataset? Oct 31, 2023
@hjh151220
Copy link

Can you teach me how to create a support set for my dataset

@iangiu
Copy link
Author

iangiu commented Nov 6, 2023

@hjh151220
hi, you can refer to the following codes:

from torch.utils.data import Dataset
import os
from torchvision import transforms
from PIL import Image
import torch


class MVTecSupportDataset(Dataset):
    def __init__(self,
                 dataset_path='../data/mvtec_anomaly_detection',
                 class_name='bottle',
                 is_train=True,
                 resize=224,
                 ):
        self.dataset_path = dataset_path
        self.class_name = class_name
        self.is_train = is_train
        self.resize = resize
        # load dataset
        self.support_dir = self.load_dataset_folder()
        # set transforms
        self.transform = transforms.Compose([
            transforms.Resize(resize, Image.ANTIALIAS),
            transforms.ToTensor(),
        ])

    def __getitem__(self, idx):
        support = self.support_dir[idx]
        support_img = Image.open(support).convert('RGB')
        support_img = self.transform(support_img)
        return support_img

    def __len__(self):
        return len(self.support_dir)

    def load_dataset_folder(self):
        phase = 'train'
        img_dir = os.path.join(self.dataset_path, self.class_name, phase, 'good')
        import pdb;pdb.set_trace()
        img_fpath_list = sorted(
                [os.path.join(img_dir, f) for f in os.listdir(img_dir) if f.endswith('.jpg')])
        return img_fpath_list


data_path = "data"
obj = "bottle"
img_size = (224, 224)
shot = 8
inferences = 1
support_dataset = MVTecSupportDataset(data_path, class_name=obj, is_train=True, resize=img_size)
support_data_loader = torch.utils.data.DataLoader(support_dataset, batch_size=shot, shuffle=True)
save_img_list = []
for i in range(inferences):
    support_img = iter(support_data_loader).next()
    save_img_list.append(support_img)
torch.save(save_img_list, f'regAD/data/support_set/{obj}/{shot}_{inferences}.pt')

@hjh151220
Copy link

hjh151220 commented Nov 7, 2023 via email

@hjh151220
Copy link

Do you know how to visualize the results of detecting anomalies

@hamzagorgulu
Copy link

Hi @iangiu, have you found answers to your questions? I am in the same phase. Thanks.

@genzhengmiaohong
Copy link

Dear author, thank you very much for your work! However, I am puzzled by the following questions when i trained a model with a custom dataset.

  1. If i try to infer a new dataset, i don't need to finetune the pretrain model which you provided. Is it right? However, i can't make sense that i got a very poor result.
  2. When i infer a image with 1600*1600 pixels, it takes a few seconds. Is it normal?
  3. Whether the 8-shot pre-trained model can be used to infer support-set containing more pictures. Will it make any difference to the results?
    Looking forward to your reply! Thanks a lot!

您好,请问您在推理的时候是否使用其他数据集的训练结果,然后来推理自己的数据集?但是作者提供的test中都需要使用到groundTruth,如果没有groundTruth,该怎么办呢?期待您的回答。

@iangiu
Copy link
Author

iangiu commented Feb 26, 2024

Hi @iangiu, have you found answers to your questions? I am in the same phase. Thanks.

sorry, I haven't figure out these questions. I gave up on the project.

@iangiu
Copy link
Author

iangiu commented Feb 26, 2024

Dear author, thank you very much for your work! However, I am puzzled by the following questions when i trained a model with a custom dataset.

  1. If i try to infer a new dataset, i don't need to finetune the pretrain model which you provided. Is it right? However, i can't make sense that i got a very poor result.
  2. When i infer a image with 1600*1600 pixels, it takes a few seconds. Is it normal?
  3. Whether the 8-shot pre-trained model can be used to infer support-set containing more pictures. Will it make any difference to the results?
    Looking forward to your reply! Thanks a lot!

您好,请问您在推理的时候是否使用其他数据集的训练结果,然后来推理自己的数据集?但是作者提供的test中都需要使用到groundTruth,如果没有groundTruth,该怎么办呢?期待您的回答。

需要自己标注的。这个项目我已经不跟了,感觉结果不太对。

@genzhengmiaohong
Copy link

己标注的。这个项目我已经不跟了,感觉结果不太对

好的,感谢您的解答。因为我现在只有正样本和未标注的负样本,需求也是如此,根本没可能去做标注,对于这种需求您有什么模型推荐嘛?

@iangiu
Copy link
Author

iangiu commented Feb 26, 2024

己标注的。这个项目我已经不跟了,感觉结果不太对

好的,感谢您的解答。因为我现在只有正样本和未标注的负样本,需求也是如此,根本没可能去做标注,对于这种需求您有什么模型推荐嘛?

https://github.com/openvinotoolkit/anomalib,可以参考这个项目,这里面有很多zero-shot的算法实现,你可以用这个做一些实验

@genzhengmiaohong
Copy link

己标注的。这个项目我已经不跟了,感觉结果不太对

好的,感谢您的解答。因为我现在只有正样本和未标注的负样本,需求也是如此,根本没可能去做标注,对于这种需求您有什么模型推荐嘛?

https://github.com/openvinotoolkit/anomalib,可以参考这个项目,这里面有很多zero-shot的算法实现,你可以用这个做一些实验

非常感谢!!

@zhang1025l
Copy link

@hjh151220 hi, you can refer to the following codes:

from torch.utils.data import Dataset
import os
from torchvision import transforms
from PIL import Image
import torch


class MVTecSupportDataset(Dataset):
    def __init__(self,
                 dataset_path='../data/mvtec_anomaly_detection',
                 class_name='bottle',
                 is_train=True,
                 resize=224,
                 ):
        self.dataset_path = dataset_path
        self.class_name = class_name
        self.is_train = is_train
        self.resize = resize
        # load dataset
        self.support_dir = self.load_dataset_folder()
        # set transforms
        self.transform = transforms.Compose([
            transforms.Resize(resize, Image.ANTIALIAS),
            transforms.ToTensor(),
        ])

    def __getitem__(self, idx):
        support = self.support_dir[idx]
        support_img = Image.open(support).convert('RGB')
        support_img = self.transform(support_img)
        return support_img

    def __len__(self):
        return len(self.support_dir)

    def load_dataset_folder(self):
        phase = 'train'
        img_dir = os.path.join(self.dataset_path, self.class_name, phase, 'good')
        import pdb;pdb.set_trace()
        img_fpath_list = sorted(
                [os.path.join(img_dir, f) for f in os.listdir(img_dir) if f.endswith('.jpg')])
        return img_fpath_list


data_path = "data"
obj = "bottle"
img_size = (224, 224)
shot = 8
inferences = 1
support_dataset = MVTecSupportDataset(data_path, class_name=obj, is_train=True, resize=img_size)
support_data_loader = torch.utils.data.DataLoader(support_dataset, batch_size=shot, shuffle=True)
save_img_list = []
for i in range(inferences):
    support_img = iter(support_data_loader).next()
    save_img_list.append(support_img)
torch.save(save_img_list, f'regAD/data/support_set/{obj}/{shot}_{inferences}.pt')

请问 我是小白, 第一次跟这个项目,为什么用这个代码找不到相应数据集的路径啊

@hjh151220
Copy link

hjh151220 commented Mar 28, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants