简体   繁体   中英

How do i set the categorical labels and split the data into train,test and dev splits using Tensorflow?

Hi I have processed data in this format. There are 10 Folds each with 6 folders. In these folders there are labels of 0, 5 and 10 with their respective images. Does Tensorflow have any built in functionality to do this for me?


frames

├── Fold1_part1

│   ├── 01

│   │   ├── 0

│   │   │   ├── 00001.jpg

│   │   │   ├── 00006.jpg

│   │   │   ├── 00011.jpg

│   │   │   ├── 00016.jpg

│   │   │   ├── 00021.jpg

Found out how to do it but had to reorder the folder. I created new folders for each category and moved the images into them, then I used the code below:

test_datagen = ImageDataGenerator(
    rescale=1. / 255,
    rotation_range = 180,
    width_shift_range = 0.2,
    height_shift_range = 0.2,
    brightness_range = (0.8, 1.2),
    shear_range = 0.2,
    zoom_range = 0.2,
    horizontal_flip = True,
    vertical_flip = True,
    validation_split = 0.1

)

train_datagen = ImageDataGenerator(
    rotation_range = 180,
    width_shift_range = 0.2,
    height_shift_range = 0.2,
    brightness_range = (0.8, 1.2),
    rescale = 1. / 255,
    shear_range = 0.2,
    zoom_range = 0.2,
    horizontal_flip = True,
    vertical_flip = True,
    validation_split = 0.1
)

train_generator = train_datagen.flow_from_directory(
    train_data_dir,
    target_size = (img_width, img_height),
    batch_size = batch_size,
    class_mode ='binary',
    seed = 42
)

validation_generator = test_datagen.flow_from_directory(
    validation_data_dir,
    target_size = (img_width, img_height),
    batch_size = batch_size,
    class_mode = 'binary',
    seed = 42
)

history = model.fit_generator(
    train_generator,
    steps_per_epoch = nb_train_samples // batch_size,
    epochs = epochs,
    validation_data = validation_generator,
    validation_steps = nb_validation_samples // batch_size)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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