【问题标题】:converting a keras DirectoryIterator to a torch variable将 keras DirectoryIterator 转换为 torch 变量
【发布时间】:2018-06-26 18:48:36
【问题描述】:

我正在使用 PyTorch 创建一个分类器来对狗和猫进行分类。我的问题是我只有 10000 张猫和狗的图像,8000 张用于训练,2000 张用于测试。因此,为了防止过度拟合,我想使用 keras 的 ImageDataGenerator 函数来生成增强图像。这就是我为那部分所做的

 train_datagen = ImageDataGenerator(rescale = 1./255, #corresponds to rescaling pixel values of the images, rescales the image so that the pixels have values between 0 and 1
                                   shear_range = 0.2, #corresponds to shearing to the images
                                   zoom_range = 0.2, #corresponds to a random zoom on the images
                                   horizontal_flip = True) #filps the images horizontally

test_datagen = ImageDataGenerator(rescale = 1./255) #preprocessing the images of the test set

#since our images are formatted in a certain way we use the flow_from_directory() function
 #Creating the training set
training_set = train_datagen.flow_from_directory('dataset/training_set',
                                                 target_size = (64, 64), 
                                                 batch_size = 32,
                                                 class_mode = 'binary')

#Creating the test set
test_set = test_datagen.flow_from_directory('dataset/test_set',
                                            target_size = (64, 64),
                                            batch_size = 32,
                                            class_mode ='binary')

现在唯一的问题是我需要将 training_set 和 test_set 转换为 Torch 变量,但现在有 DirectoryIterators。那么有没有办法将 training_set 和 test_set 转换为 Torch 变量。或者我可以做和我在这里做的一样的事情,但是使用 pytorch。

谢谢

【问题讨论】:

    标签: deep-learning classification conv-neural-network


    【解决方案1】:

    看看下面的例子,我想它会给你一些关于如何用 PyTorch 实现数据增强的进一步说明:

    https://github.com/jiangqy/Data-Augmentation-Pytorch

    【讨论】:

      猜你喜欢
      • 2019-08-04
      • 2021-02-19
      • 2018-12-02
      • 2020-12-12
      • 2020-02-11
      • 2016-09-05
      • 2014-10-04
      • 2019-02-01
      • 2021-02-02
      相关资源
      最近更新 更多