Example #1
0
def create_network(optimiser):
    # Real-time data preprocessing
    img_prep = ImagePreprocessing()
    img_prep.add_samplewise_stdnorm()
    img_prep.add_featurewise_stdnorm()

    # Real-time data augmentation to add variance to the data
    img_aug = ImageAugmentation()
    img_aug.add_random_blur(sigma_max=3)
    img_aug.add_random_flip_leftright()
    img_aug.add_random_rotation(max_angle=25.)
    # Convolutional network building
    network = input_data(shape=[None, 32, 32, 3],
                         data_preprocessing=img_prep,
                         data_augmentation=img_aug)
    network = conv_2d(network, 32, 3, activation='relu')
    network = max_pool_2d(network, 2)
    network = conv_2d(network, 64, 3, activation='relu')
    network = conv_2d(network, 64, 3, activation='relu')
    network = max_pool_2d(network, 2)
    network = fully_connected(network, 512, activation='relu')
    network = dropout(network, 0.5)
    network = fully_connected(network, 10, activation='softmax')
    network = regression(network,
                         optimizer=optimiser,
                         loss='categorical_crossentropy',
                         learning_rate=0.002)

    return network
Example #2
0
def get_model():
    # Real-time data preprocessing
    img_prep = ImagePreprocessing()
    img_prep.add_samplewise_zero_center()
    img_prep.add_samplewise_stdnorm()

    net = tflearn.input_data(shape=[None, 400], data_preprocessing=img_prep)
    net = tflearn.fully_connected(net, 512, activation='relu')
    net = tflearn.fully_connected(net, 512, activation='relu')
    net = tflearn.fully_connected(net, 400, activation='sigmoid')
    net = tflearn.regression(net, optimizer='adam', loss='binary_crossentropy')
    model = tflearn.DNN(net)

    return net, model
    classifier.HEIGHT = HEIGHT
    classifier.WIDTH = WIDTH
    classifier.IMAGE = HEIGHT
    classifier.CHANNELS = CHANNELS

    print("\t         Path:", args.data_dir)
    print("\tShape (train):", X.shape, Y.shape)
    print("\tShape   (val):", Xv.shape, Yv.shape)
    print("Data loaded!\n")

# Real-time data preprocessing (samplewise or featurewise)
img_prep = None
if (args.pproc):
    img_prep = ImagePreprocessing()
    img_prep.add_samplewise_zero_center()
    img_prep.add_samplewise_stdnorm()
    #img_prep.add_zca_whitening()

# Real-time data augmentation
img_aug = ImageAugmentation()
img_aug.add_random_flip_leftright()
img_aug.add_random_flip_updown()
img_aug.add_random_rotation(max_angle=5.)

# computational resources definition (made changes on TFLearn's config.py)
tflearn.init_graph(num_cores=8, allow_growth=True)

# network definition
network = input_data(
    shape=[None, HEIGHT, WIDTH, CHANNELS],  # shape=[None,IMAGE, IMAGE] for RNN
    data_preprocessing=img_prep,  # NOTE: always check PP
Example #4
0
#HEIGHT   = 240
#WIDTH    = 320
#CHANNELS = 3

# get command line arguments
arch = sys.argv[1]  # name of architecture
modelpath = sys.argv[2]  # path to saved model
layer = sys.argv[3]  # layer name, for example, Conv2D or Conv2D_1
ichannel = int(
    sys.argv[4])  # input channel for displaying kernels and convolutions

# Real-time data preprocessing
img_prep = ImagePreprocessing()
img_prep.add_samplewise_zero_center(
)  # per sample (featurewise is a global value)
img_prep.add_samplewise_stdnorm()  # per sample (featurewise is a global value)

# Real-time data augmentation
img_aug = ImageAugmentation()
img_aug.add_random_flip_leftright()
img_aug.add_random_flip_updown()
img_aug.add_random_rotation(max_angle=10.)

# network definition
network = input_data(
    shape=[None, HEIGHT, WIDTH, CHANNELS],  # shape=[None,IMAGE, IMAGE] for RNN
    data_preprocessing=None,
    data_augmentation=None)

#in2 = input_data(shape=[None,1])
#print(network.shape)