简体   繁体   English

深度学习 Denoisy Model 与 imageDataGenerator

[英]deep learning Denoisy Model with imageDataGenerator

I have this code:我有这个代码:

epochs =50
batch_size = 5
validation_split = 0.2


datagen = tf.keras.preprocessing.image.ImageDataGenerator(validation_split=validation_split )


train_generator = datagen.flow(
    X_train_noisy, y_train_denoisy, batch_size=batch_size, 
    subset='training'
)

val_generator = datagen.flow(
    X_train_noisy, y_train_denoisy, batch_size=batch_size,
    subset='validation'
)

history = model.fit(train_generator,
         steps_per_epoch=(len(X_train_noisy)*(1-validation_split)) // batch_size, epochs=epochs,
                    validation_data = val_generator, validation_steps=(len(X_train_noisy)*validation_split)//batch_size)

X_train_noisy and y_train_denoisy are ndarray ([20,512,512,1]) pe But I get this error: X_train_noisy 和 y_train_denoisy 是 ndarray ([20,512,512,1]) pe 但我得到这个错误:

training and validation subsets have different number of classes after the split训练和验证子集在拆分后具有不同数量的类

How can I solve that?我该如何解决?

thanks!谢谢!

probably what happened is when the data is split for training and validation, the set of files selected for validation did not include any files in one or more of the classes.可能发生的情况是,当数据被拆分以进行训练和验证时,选择用于验证的文件集不包括一个或多个类中的任何文件。 This can happen when your data set is small.当您的数据集很小时,可能会发生这种情况。 Try increasing the validation_split to a larger value say like.5 and see if the problem goes away.尝试将validation_split 增加到更大的值,比如5,看看问题是否消失。 It should.它应该。 Then reduce the size of the validation split until the error reoccurs.然后减小验证拆分的大小,直到错误再次发生。 That will determine the minimum split value you can use.这将确定您可以使用的最小拆分值。 Remember the split is randomized so set the split value at something above the minimum value.请记住拆分是随机的,因此请将拆分值设置为高于最小值。 Another (BETTER) alternative is to split the data using sklearn train_test_split.另一种(更好的)替代方法是使用 sklearn train_test_split 拆分数据。 This function has a parameter stratify that splits the data but ensures that all classes are included in the two component.这个 function 有一个参数 stratify 可以拆分数据,但确保所有类都包含在两个组件中。 See code below请参阅下面的代码

from sklearn.model_selection import train_test_split
X_train_noisy, X_valid_noisy, y_train_denoisy, y_valid_denoisy=train_test_split(X_train_noisy,
       y_train_denoisy, test_size=validation_split, 
      shuffle=True, random_state=123, 
      stratify=y_train_denoisy)

now use these split variable in model.fit现在在 model.fit 中使用这些拆分变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM