Example #1
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
Example #2
0
def createModel(parameters):

    img_prep = ImagePreprocessing()
    img_prep.add_samplewise_zero_center()

    imgaug = tflearn.ImageAugmentation()
    imgaug.add_random_flip_leftright()
    imgaug.add_random_flip_updown()
    imgaug.add_random_90degrees_rotation()

    # Building convolutional network
    network = input_data(shape=[None, 64, 64, 3], data_preprocessing=img_prep, data_augmentation=imgaug, name='input')
    network = conv_2d(network, parameters.CNN1FeatureSize, parameters.CNN1Size, activation='relu', regularizer="L2")  # padding same
    network=batch_normalization(network)

    if parameters.CNN2Size > 0:
        network = conv_2d(network, parameters.CNN2FeatureSize, parameters.CNN2Size, activation='relu', regularizer="L2")#2. CNN
        network=batch_normalization(network)
    if parameters.CNN3Size > 0:
        network = conv_2d(network, parameters.CNN3FeatureSize, parameters.CNN3Size, activation='relu', regularizer="L2")#3. CNN
        network=batch_normalization(network)
        network = max_pool_2d(network, 2)
    if parameters.CNN4Size > 0:
        network = conv_2d(network, parameters.CNN4FeatureSize, parameters.CNN4Size, activation='relu', regularizer="L2")#4. CNN
        network=batch_normalization(network)
        network = max_pool_2d(network, 2)

        network = conv_2d(network, parameters.CNN4FeatureSize, parameters.CNN4Size, activation='relu', regularizer="L2")#5. CNN
        network=batch_normalization(network)
        network = max_pool_2d(network, 2)
	
    #if parameters.FullyConn1Size > 0:
    #    network = fully_connected(network, parameters.FullyConn1Size, activation='relu',  regularizer="L2")
    #    network=batch_normalization(network)
    #    #network = dropout(network, 0.2)
    if parameters.FullyConn2Size > 0:
        network = fully_connected(network, parameters.FullyConn1Size, activation='relu', regularizer="L2")
        network=batch_normalization(network)
        network = dropout(network, 0.2)
    if parameters.FullyConn2Size > 0:
        network = fully_connected(network, parameters.FullyConn2Size, activation='relu', regularizer="L2")
        network=batch_normalization(network)
        network = dropout(network, 0.2)
 


    g = tflearn.fully_connected(network, 2, activation='softmax')
    g = tflearn.regression(g, optimizer='SGD', loss='categorical_crossentropy', metric='default' , learning_rate=0.01,batch_size=64)
    return g
    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
Example #4
0
CLASSES = 10

#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])