【发布时间】: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