Ejemplo n.º 1
0
def strides():
    """
    Tests an example CNN with additional unusual strides.
    :return: None.
    """
    num_imgs = 10
    nncg = NNCG()
    strides = Sequential()
    strides.add(
        Convolution2D(4, (3, 3),
                      input_shape=(101, 101, 1),
                      activation='relu',
                      padding='same',
                      strides=(3, 3)))
    strides.add(MaxPooling2D(pool_size=(2, 2)))
    strides.add(
        Convolution2D(8, (3, 3),
                      padding='valid',
                      activation='relu',
                      strides=(2, 3)))
    strides.add(Convolution2D(16, (3, 3), padding='valid', activation='relu'))
    strides.add(Flatten())
    strides.add(Dense(2, activation='softmax'))
    images = random_imdb(num_imgs, strides.input.shape[1:].as_list())
    nncg.keras_compile(images, strides, 'strides.c')
    print_success('strides')
Ejemplo n.º 2
0
def dense_model():
    """
    Tests an example CNN with a Dense layer and valid padding.
    :return: None.
    """
    num_imgs = 10
    nncg = NNCG()
    dense_model = Sequential()
    dense_model.add(
        Convolution2D(8, (3, 3),
                      input_shape=(70, 50, 1),
                      activation='relu',
                      padding='same'))
    dense_model.add(MaxPooling2D(pool_size=(2, 2)))
    dense_model.add(
        Convolution2D(16, (3, 3),
                      padding='valid',
                      activation='relu',
                      bias_initializer='random_uniform'))
    dense_model.add(MaxPooling2D(pool_size=(2, 2)))
    dense_model.add(
        Convolution2D(32, (3, 3),
                      padding='valid',
                      activation='relu',
                      bias_initializer='random_uniform'))
    dense_model.add(MaxPooling2D(pool_size=(2, 2)))
    dense_model.add(Dropout(0.4))
    dense_model.add(Flatten())
    dense_model.add(Dense(2, activation='softmax'))
    images = random_imdb(num_imgs, dense_model.input.shape[1:].as_list())
    nncg.keras_compile(images, dense_model, 'dense_model.c')
    print_success('dense_model')
Ejemplo n.º 3
0
def no_dense():
    """
    Tests an example CNN with no dense layer.
    :return: None
    """
    num_imgs = 10
    nncg = NNCG()
    no_dense = Sequential()
    no_dense.add(
        Convolution2D(4, (3, 3),
                      input_shape=(36, 18, 1),
                      activation='relu',
                      padding='same'))
    no_dense.add(MaxPooling2D(pool_size=(2, 2)))
    no_dense.add(
        Convolution2D(8, (3, 3),
                      padding='same',
                      activation='relu',
                      bias_initializer='random_uniform'))
    no_dense.add(MaxPooling2D(pool_size=(2, 2)))
    no_dense.add(
        Convolution2D(16, (3, 3),
                      padding='same',
                      activation='relu',
                      bias_initializer='random_uniform'))  # Could be softmax
    no_dense.add(MaxPooling2D(pool_size=(4, 2)))
    no_dense.add(Dropout(0.4))
    no_dense.add(Convolution2D(2, (2, 2), activation='softmax'))
    no_dense.add(Flatten())
    images = random_imdb(num_imgs, no_dense.input.shape[1:].as_list())
    nncg.keras_compile(images, no_dense, 'no_dense.c')
    print_success('no_dense')
Ejemplo n.º 4
0
def VGG19_test():
    """
    Tests a full VGG19.
    :return: None.
    """
    num_imgs = 1
    nncg = NNCG()
    vgg19_m = VGG19(weights=None)
    db = random_imdb(num_imgs, vgg19_m.input.shape[1:].as_list())
    nncg.keras_compile(db, vgg19_m, 'vgg19.c', weights_method='stdio')
    print_success('VGG19')
Ejemplo n.º 5
0
def VGG19_quantized_test(db):
    """
    Tests a full VGG19 using quantization.
    :param db: Image database to test with real images.
    :return: None.
    """
    nncg = NNCG()
    vgg19_m = VGG19(weights='imagenet')
    nncg.keras_compile(db,
                       vgg19_m,
                       'vgg19.c',
                       weights_method='stdio',
                       quatization=True,
                       arch='sse3',
                       test_mode='classification')
    print_success('VGG19')
Ejemplo n.º 6
0
model_path = "model.h5"
code_path = "."

if args.imgdb_path is not None:
    imgdb_path = args.imgdb_path

if args.model_path is not None:
    model_path = args.model_path

if args.code_path is not None:
    code_path = args.code_path

images = load_imdb(imgdb_path)
model = load_model(model_path, compile=False)

general_generator = NNCG()
general_generator.keras_compile(images["images"],
                                model,
                                code_path,
                                "qsse3",
                                arch="sse3",
                                testing=1000,
                                quatization=True,
                                test_mode='classification')
sse_generator = NNCG()
sse_generator.keras_compile(images["images"],
                            model,
                            code_path,
                            "sse3",
                            arch="sse3",
                            testing=1000)
Ejemplo n.º 7
0
parser.add_argument('-b', '--database-path', dest='imgdb_path',
                    help='Path to the image database to use for training. '
                         'Default is img.db in current folder.')
parser.add_argument('-m', '--model-path', dest='model_path',
                    help='Store the trained model using this path. Default is model.h5.')
parser.add_argument('-c', '--code-path', dest='code_path',
                    help='Path where the file is to be stored. Default is current directory')

args = parser.parse_args()

imgdb_path = "img.db"
model_path = "model.h5"
code_path = "."

if args.imgdb_path is not None:
    imgdb_path = args.imgdb_path

if args.model_path is not None:
    model_path = args.model_path

if args.code_path is not None:
    code_path = args.code_path

images = load_imdb(imgdb_path)
model = load_model(model_path, compile=False)

general_generator = NNCG()
general_generator.keras_compile(images["images"], model, code_path, "gen", arch="general", testing=1000)
sse_generator = NNCG()
sse_generator.keras_compile(images["images"], model, code_path, "sse3", arch="sse3", testing=1000)