Example #1
0
    images_train = file_io.FileHDF5().read(os.path.join(DIR, "train.hdf5"),
                                           "images")
    print("loading labels_train...")
    labels_train = file_io.FileHDF5().read(os.path.join(DIR, "train.hdf5"),
                                           "labels")

    print("loading images_val...")
    images_val = file_io.FileHDF5().read(os.path.join(DIR, "val.hdf5"),
                                         "images")
    print("loading labels_val...")
    labels_val = file_io.FileHDF5().read(os.path.join(DIR, "val.hdf5"),
                                         "labels")
    print("Finish loading hdf5")

    # Train detector
    X_train, X_val, Y_train, Y_val, mean_value = preproc.GrayImgTrainPreprocessor(
    ).run(images_train, labels_train, images_val, labels_val, 2)
    print("mean value of the train images : {}".format(mean_value))  # 107.524
    print("Train image shape is {}, and Validation image shape is {}".format(
        X_train.shape,
        X_val.shape))  # (457723, 32, 32, 1), (113430, 32, 32, 1)
    # mean value of the train images : 108.78421712130333
    # Train image shape is (1279733, 32, 32, 1), and Validation image shape is (317081, 32, 32, 1)

    train_.train_detector(X_train,
                          X_val,
                          Y_train,
                          Y_val,
                          nb_filters=NB_FILTERS,
                          nb_epoch=NB_EPOCH,
                          nb_classes=2,
                          save_file=DETECTOR_FILE)
if __name__ == "__main__":

    images_train = file_io.FileHDF5().read(os.path.join(DIR, "train.hdf5"),
                                           "images")
    labels_train = file_io.FileHDF5().read(os.path.join(DIR, "train.hdf5"),
                                           "labels")

    images_val = file_io.FileHDF5().read(os.path.join(DIR, "val.hdf5"),
                                         "images")
    labels_val = file_io.FileHDF5().read(os.path.join(DIR, "val.hdf5"),
                                         "labels")

    # Train detector
    X_train, X_val, Y_train, Y_val, mean_value = \
        preproc.GrayImgTrainPreprocessor().run(images_train, labels_train, images_val, labels_val, 2)
    # 107.524
    print("mean value of the train images : {}".format(mean_value))
    # (457723, 32, 32, 1), (113430, 32, 32, 1)
    print("Train image shape is {}, and Validation image shape is {}".format(
        X_train.shape, X_val.shape))
    train_.train_detector(X_train,
                          X_val,
                          Y_train,
                          Y_val,
                          nb_filters=NB_FILTERS,
                          nb_epoch=NB_EPOCH,
                          nb_classes=2,
                          save_file=DETECTOR_FILE)

    # Train recognizer