【问题标题】:Preprocessing in image recognition图像识别中的预处理
【发布时间】:2019-06-21 01:06:08
【问题描述】:

我是图像识别的初学者,需要一些有关预处理图像的帮助。

  1. 我使用迁移学习模型resnet18来做识别工作。我得到: In [3]: pretrainedmodels.pretrained_settings['resnet18'] Out[3]: {'imagenet': {'url': 'https://download.pytorch.org/models/resnet18- 5c106cde.pth', 'input_space': 'RGB', 'input_size': [3, 224, 224], 'input_range': [0, 1], 'mean': [0.485, 0.456, 0.406], 'std': [0.229, 0.224, 0.225], 'num_classes': 1000}}

我发现meanstd 与我的图像数据集完全不同。

我应该如何标准化我的 trainset?使用上面的均值和标准还是使用我自己计算的均值和标准?

  1. 我将数据集分为train_setvalid_settest_set

我有两种方法:

A.计算它们的均值和标准差并分别归一化

B.计算整个数据集的均值和标准差,然后进行归一化。

哪一个是对的?

3.我应该什么时候进行标准化?在data_augmentation之前还是在data_augmentation之后?

【问题讨论】:

    标签: python image-processing computer-vision pytorch image-recognition


    【解决方案1】:

    如果您使用自己的数据集和预训练的权重训练新模型,则需要为新数据集设置新的均值和标准差。

    基本上,您需要重复 ImageNet 的操作过程。编写一个脚本来计算整个数据集的一般 [mean, std] 值。

    但请记住注意您的数据集分布,因为它肯定会影响模型性能。

    然后为您的 train/valset 单独定义一个转换器方法。通常我们不会像在现实世界场景中那样标准化测试集,您的模型将接收不同类型的数据。在构建数据集时,您应该执行规范化过程以及其他增强技术。

    例如,考虑这个玩具示例

    "transformer": {
        "train": transforms.Compose([
            transforms.Resize(size=299),
            transforms.RandomHorizontalFlip(p=0.2),
            transforms.ToTensor(),
            transforms.Normalize(new_mean, new_std)
        ]),
        "valid": transforms.Compose([
            transforms.Resize(size=299),
            transforms.ToTensor(),
        ])
    }
    
    train_ds = CustomDataset(type="train", transformer=transformer["train"])
    valid_ds = CustomDataset(type="valid", transformer=transformer["valid"])
    

    如果您有更多困惑,请告诉我

    【讨论】:

      猜你喜欢
      • 2011-10-17
      • 2012-07-12
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 2018-02-09
      • 2014-10-24
      • 1970-01-01
      相关资源
      最近更新 更多