Пример #1
0
        attr.train_data_dir,
        target_size=(attr.img_width, attr.img_height),
        batch_size=attr.batch_size,
        shuffle=True,
        class_mode='binary')

    attr.validation_generator = test_datagen.flow_from_directory(
        attr.validation_data_dir,
        target_size=(attr.img_width, attr.img_height),
        batch_size=attr.batch_size,
        shuffle=True,
        class_mode='binary')

    attr.test_generator = test_datagen.flow_from_directory(
        attr.test_data_dir,
        target_size=(attr.img_width, attr.img_height),
        batch_size=1,
        shuffle=False,
        class_mode='binary')

    # calculate steps based on number of images and batch size
    attr.calculate_steps()

    attr.increment_seq()

    # Persist execution attributes for session resume
    save_execution_attributes(attr, attr.summ_basename + '-execution-attributes.properties')

    time_callback = TimeCallback()

    callbacks = [time_callback, EarlyStopping(monitor='val_acc', patience=20, mode='max', restore_best_weights=True),
                 ModelCheckpoint(attr.curr_basename + "-ckweights.h5", mode='max', verbose=1, monitor='val_acc', save_best_only=True)]
Пример #2
0
    # compile model using accuracy as main metric, rmsprop (gradient descendent)
    attr.model.compile(loss='binary_crossentropy',
                  optimizer=RMSprop(lr=0.000001),
                  metrics=['accuracy'])

    # this is the augmentation configuration we will use for training
    train_datagen = create_image_generator(False, True)

    # this is the augmentation configuration we will use for testing:
    # nothing is done.
    test_datagen = create_image_generator(False, False)

    attr.train_generator = multimodal_flow_from_directory_generator(attr.train_data_dir, attr.csv_path, train_datagen, attr.batch_size, attr.img_height, attr.img_width, 'binary', True)
    attr.validation_generator = multimodal_flow_from_directory_generator(attr.validation_data_dir, attr.csv_path, test_datagen, attr.batch_size, attr.img_height, attr.img_width, 'binary', True)
    attr.test_generator = multimodal_flow_from_directory_generator(attr.test_data_dir, attr.csv_path, test_datagen, 1, attr.img_height, attr.img_width, 'binary', False)

    print("[INFO] Calculating samples and steps...")
    attr.calculate_samples_len()

    attr.calculate_steps()

    attr.increment_seq()

    # Persist execution attributes for session resume
    save_execution_attributes(attr, attr.summ_basename + '-execution-attributes.properties')

    time_callback = TimeCallback()

    callbacks = [time_callback, EarlyStopping(monitor='val_acc', patience=3, mode='max', restore_best_weights=True),
                 ModelCheckpoint(attr.curr_basename + "-ckweights.h5", mode='max', verbose=1, monitor='val_acc', save_best_only=True)]
Пример #3
0
                                                    channels=3,
                                                    classes=2,
                                                    should_shuffle=True,
                                                    is_categorical=True,
                                                    is_debug=False,
                                                    width_shift=0.2,
                                                    height_shift=0.2,
                                                    rotation_angle=15,
                                                    shear_factor=10,
                                                    zoom_factor=0.2)

    attr.test_generator = MultimodalGenerator(npy_path=attr.numpy_path +
                                              '/test-categorical.npy',
                                              batch_size=1,
                                              height=attr.img_height,
                                              width=attr.img_width,
                                              channels=3,
                                              classes=2,
                                              should_shuffle=False,
                                              is_categorical=True,
                                              is_debug=False)

    print("[INFO] Calculating samples and steps...")
    attr.calculate_samples_len()

    attr.calculate_steps()

    attr.increment_seq()

    callbacks_top = [
        ModelCheckpoint(attr.curr_basename + "-mid-ckweights.h5",
                        monitor='val_acc',
Пример #4
0
    attr.increment_seq()

    # Persist execution attributes for session resume
    save_execution_attributes(attr, attr.summ_basename + '-execution-attributes.properties')

    # this is the augmentation configuration we will use for training
    train_datagen = create_image_generator(False, True)

    # this is the augmentation configuration we will use for testing:
    # nothing is done.
    test_datagen = create_image_generator(False, False)

    attr.train_generator = multimodal_flow_generator(images_train, attributes_train, labels_train, train_datagen, attr.batch_size)
    attr.validation_generator = multimodal_flow_generator(images_valid, attributes_valid, labels_valid, test_datagen, attr.batch_size)
    attr.test_generator = multimodal_flow_generator(images_test, attributes_test, labels_test, test_datagen, 1)

    time_callback = TimeCallback()

    callbacks = [time_callback, EarlyStopping(monitor='val_acc', patience=10, mode='max', restore_best_weights=True),
                 ModelCheckpoint(attr.curr_basename + "-ckweights.h5", mode='max', verbose=1, monitor='val_acc', save_best_only=True)]


    # training time
    history = attr.model.fit_generator(
        attr.train_generator,
        steps_per_epoch=attr.steps_train,
        epochs=attr.epochs,
        validation_data=attr.validation_generator,
        validation_steps=attr.steps_valid,
        use_multiprocessing=True,
Пример #5
0
                                                        class_mode='categorical')

    # save and look at how the data augmentations look like
    # save_to_dir=os.path.join(os.path.abspath(train_data_dir), '../preview')
    # save_prefix='aug',
    # save_format='jpeg')

    attr.validation_generator = test_datagen.flow_from_directory(attr.validation_data_dir,
                                                                  target_size=(attr.img_width, attr.img_height),
                                                                  batch_size=attr.batch_size,
                                                                  shuffle=True,
                                                                  class_mode='categorical')

    attr.test_generator = test_datagen.flow_from_directory(
            attr.test_data_dir,
            target_size=(attr.img_height, attr.img_width),
            batch_size=1,
            class_mode='categorical',
            shuffle=False)

    attr.model.compile(optimizer=SGD(lr=0.0001,momentum=0.9), loss='categorical_crossentropy', metrics=['accuracy'])

    plot_model(attr.model, to_file=attr.summ_basename + '-architecture.png')

    # calculate steps based on number of images and batch size
    attr.calculate_steps()
    attr.increment_seq()

    callbacks = [
        ModelCheckpoint(attr.curr_basename + "-mid-ckweights.h5", monitor='val_acc', verbose=1, save_best_only=True),
        EarlyStopping(monitor='val_acc', patience=10, verbose=0)
    ]