from tensorflow.keras.preprocessing.image import ImageDataGenerator
target_size=(224,224) # set the size of the images
color_mode='rgb' # set the type of image
class_mode= 'categorical' # set the class mode
batch_size=32 # set the batch size
val_split=.2 # set % of images to use for validation
subset='training' # set to 'training', or 'valiatiom' or leave as None
train_gen=ImageDataGenerator(validation_split=val_split).flow_from_datafram(df,
x_col='image_path',
y_col='followers_like_ratio',target_size=target_size,color_mode=color_mode,
class_mode=class_mode, batch_size=batch_size,shuffle=True, seed=123,
subset='training')
valid_gen= ImageDataGenerator(validation_split=val_split).flow_from_datafram(df,
x_col='image_path',
y_col='followers_like_ratio',target_size=target_size,color_mode=color_mode,
class_mode=class_mode, batch_size=batch_size,shuffle=True, seed=123,
subset='validation')
from sklearn.model_selection import train_test_split
train_size=.8 # set the % to use for training
train_df, test_df=train_test_split(df, train_size=train_size, shuffle=True, randoom_state=123)
1条答案
按热度按时间j0pj023g1#
我假设image_path是映像的完整路径,还假设followers_like_path中的wntry是表示类标签的STRINGS,您可以使用ImageDataGenerator.flow_from_datafame创建一个生成器,以便将数据加载到model.fit中。
如果你有一个test_df,你可以创建一个测试生成器。你可以使用sklearn train_test_split将你的原始数据框分离成train_df和test_df,如下所示
现在在验证和训练生成器中使用train_df,在测试生成器中使用test_df