def test_vbs1(self): with tf.Graph().as_default(): # Data loading and preprocessing import zqtflearn.datasets.mnist as mnist X, Y, testX, testY = mnist.load_data(one_hot=True) X = X.reshape([-1, 28, 28, 1]) testX = testX.reshape([-1, 28, 28, 1]) X = X[:20, :, :, :] Y = Y[:20, :] testX = testX[:10, :, :, :] testY = testY[:10, :] # Building convolutional network network = input_data(shape=[None, 28, 28, 1], name='input') network = conv_2d(network, 32, 3, activation='relu', regularizer="L2") network = max_pool_2d(network, 2) network = local_response_normalization(network) network = conv_2d(network, 64, 3, activation='relu', regularizer="L2") network = max_pool_2d(network, 2) network = local_response_normalization(network) network = fully_connected(network, 128, activation='tanh') network = dropout(network, 0.8) network = fully_connected(network, 256, activation='tanh') network = dropout(network, 0.8) network = fully_connected(network, 10, activation='softmax') network = regression(network, optimizer='adam', learning_rate=0.01, loss='categorical_crossentropy', name='target') # Training model = zqtflearn.DNN(network, tensorboard_verbose=3) model.fit({'input': X}, {'target': Y}, n_epoch=1, batch_size=10, validation_set=({ 'input': testX }, { 'target': testY }), validation_batch_size=5, snapshot_step=10, show_metric=True, run_id='convnet_mnist_vbs') self.assertEqual(model.train_ops[0].validation_batch_size, 5) self.assertEqual(model.train_ops[0].batch_size, 10)
def make_core_network(network): network = zqtflearn.reshape(network, [-1, 28, 28, 1], name="reshape") network = conv_2d(network, 32, 3, activation='relu', regularizer="L2") network = max_pool_2d(network, 2) network = local_response_normalization(network) network = conv_2d(network, 64, 3, activation='relu', regularizer="L2") network = max_pool_2d(network, 2) network = local_response_normalization(network) network = fully_connected(network, 128, activation='tanh') network = dropout(network, 0.8) network = fully_connected(network, 256, activation='tanh') network = dropout(network, 0.8) network = fully_connected(network, 10, activation='softmax') return network
def test_vm1(self): with tf.Graph().as_default(): # Data loading and preprocessing import zqtflearn.datasets.mnist as mnist X, Y, testX, testY = mnist.load_data(one_hot=True) X = X.reshape([-1, 28, 28, 1]) testX = testX.reshape([-1, 28, 28, 1]) X = X[:10, :, :, :] Y = Y[:10, :] # Building convolutional network network = input_data(shape=[None, 28, 28, 1], name='input') network = conv_2d(network, 32, 3, activation='relu', regularizer="L2") network = max_pool_2d(network, 2) network = local_response_normalization(network) network = conv_2d(network, 64, 3, activation='relu', regularizer="L2") network = max_pool_2d(network, 2) network = local_response_normalization(network) network = fully_connected(network, 128, activation='tanh') network = dropout(network, 0.8) network = fully_connected(network, 256, activation='tanh') network = dropout(network, 0.8) # construct two varaibles to add as additional "valiation monitors" # these varaibles are evaluated each time validation happens (eg at a snapshot) # and the results are summarized and output to the tensorboard events file, # together with the accuracy and loss plots. # # Here, we generate a dummy variable given by the sum over the current # network tensor, and a constant variable. In practice, the validation # monitor may present useful information, like confusion matrix # entries, or an AUC metric. with tf.name_scope('CustomMonitor'): test_var = tf.reduce_sum(tf.cast(network, tf.float32), name="test_var") test_const = tf.constant(32.0, name="custom_constant") print("network=%s, test_var=%s" % (network, test_var)) network = fully_connected(network, 10, activation='softmax') network = regression(network, optimizer='adam', learning_rate=0.01, loss='categorical_crossentropy', name='target', validation_monitors=[test_var, test_const]) # Training model = zqtflearn.DNN(network, tensorboard_verbose=3) model.fit({'input': X}, {'target': Y}, n_epoch=1, validation_set=({ 'input': testX }, { 'target': testY }), snapshot_step=10, show_metric=True, run_id='convnet_mnist') # check for validation monitor variables ats = tf.get_collection("Adam_testing_summaries") print("ats=%s" % ats) self.assertTrue( len(ats) == 4 ) # should be four variables being summarized: [loss, test_var, test_const, accuracy] session = model.session print("session=%s" % session) trainer = model.trainer print("train_ops = %s" % trainer.train_ops) top = trainer.train_ops[0] vmtset = top.validation_monitors_T print("validation_monitors_T = %s" % vmtset) with model.session.as_default(): ats_var_val = zqtflearn.variables.get_value(vmtset[0]) ats_const_val = zqtflearn.variables.get_value(vmtset[1]) print("summary values: var=%s, const=%s" % (ats_var_val, ats_const_val)) self.assertTrue( ats_const_val == 32) # test to make sure the constant made it through
net = relu( batch_normalization( conv_2d(net, 1536, 1, bias=False, activation=None, name='Conv2d_7b_1x1'))) net = avg_pool_2d(net, net.get_shape().as_list()[1:3], strides=2, padding='VALID', name='AvgPool_1a_8x8') net = flatten(net) net = dropout(net, dropout_keep_prob) loss = fully_connected(net, num_classes, activation='softmax') network = zqtflearn.regression(loss, optimizer='RMSprop', loss='categorical_crossentropy', learning_rate=0.0001) model = zqtflearn.DNN(network, checkpoint_path='inception_resnet_v2', max_checkpoints=1, tensorboard_verbose=2, tensorboard_dir="./tflearn_logs/") model.fit(X, Y, n_epoch=1000, validation_set=0.1, shuffle=True,
128, 4, padding='valid', activation='relu', regularizer="L2") branch3 = conv_1d(network, 128, 5, padding='valid', activation='relu', regularizer="L2") network = merge([branch1, branch2, branch3], mode='concat', axis=1) network = tf.expand_dims(network, 2) network = global_max_pool(network) network = dropout(network, 0.5) network = fully_connected(network, 2, activation='softmax') network = regression(network, optimizer='adam', learning_rate=0.001, loss='categorical_crossentropy', name='target') # Training model = zqtflearn.DNN(network, tensorboard_verbose=0) model.fit(trainX, trainY, n_epoch=5, shuffle=True, validation_set=(testX, testY), show_metric=True, batch_size=32)
network = conv_2d(network, 256, 3, activation='relu') network = conv_2d(network, 256, 3, activation='relu') network = conv_2d(network, 256, 3, activation='relu') network = max_pool_2d(network, 2, strides=2) network = conv_2d(network, 512, 3, activation='relu') network = conv_2d(network, 512, 3, activation='relu') network = conv_2d(network, 512, 3, activation='relu') network = max_pool_2d(network, 2, strides=2) network = conv_2d(network, 512, 3, activation='relu') network = conv_2d(network, 512, 3, activation='relu') network = conv_2d(network, 512, 3, activation='relu') network = max_pool_2d(network, 2, strides=2) network = fully_connected(network, 4096, activation='relu') network = dropout(network, 0.5) network = fully_connected(network, 4096, activation='relu') network = dropout(network, 0.5) network = fully_connected(network, 17, activation='softmax') network = regression(network, optimizer='rmsprop', loss='categorical_crossentropy', learning_rate=0.0001) # Training model = zqtflearn.DNN(network, checkpoint_path='model_vgg', max_checkpoints=1, tensorboard_verbose=0)
# Data loading and preprocessing import zqtflearn.datasets.mnist as mnist X, Y, testX, testY = mnist.load_data(one_hot=True) X = X.reshape([-1, 28, 28, 1]) testX = testX.reshape([-1, 28, 28, 1]) # Building convolutional network network = input_data(shape=[None, 28, 28, 1], name='input') #highway convolutions with pooling and dropout for i in range(3): for j in [3, 2, 1]: network = highway_conv_2d(network, 16, j, activation='elu') network = max_pool_2d(network, 2) network = batch_normalization(network) network = fully_connected(network, 128, activation='elu') network = fully_connected(network, 256, activation='elu') network = fully_connected(network, 10, activation='softmax') network = regression(network, optimizer='adam', learning_rate=0.01, loss='categorical_crossentropy', name='target') # Training model = zqtflearn.DNN(network, tensorboard_verbose=0) model.fit(X, Y, n_epoch=20, validation_set=(testX, testY), show_metric=True,
# Real-time data preprocessing img_prep = ImagePreprocessing() img_prep.add_featurewise_zero_center() img_prep.add_featurewise_stdnorm() # Real-time data augmentation img_aug = ImageAugmentation() 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='adam', loss='categorical_crossentropy', learning_rate=0.001) # Train using classifier model = zqtflearn.DNN(network, tensorboard_verbose=0) model.fit(X, Y, n_epoch=50, shuffle=True, validation_set=(X_test, Y_test), show_metric=True, batch_size=96, run_id='cifar10_cnn')
from zqtflearn.layers.embedding_ops import embedding from zqtflearn.layers.recurrent import bidirectional_rnn, BasicLSTMCell from zqtflearn.layers.estimator import regression # IMDB Dataset loading train, test, _ = imdb.load_data(path='imdb.pkl', n_words=10000, valid_portion=0.1) trainX, trainY = train testX, testY = test # Data preprocessing # Sequence padding trainX = pad_sequences(trainX, maxlen=200, value=0.) testX = pad_sequences(testX, maxlen=200, value=0.) # Converting labels to binary vectors trainY = to_categorical(trainY) testY = to_categorical(testY) # Network building net = input_data(shape=[None, 200]) net = embedding(net, input_dim=20000, output_dim=128) net = bidirectional_rnn(net, BasicLSTMCell(128), BasicLSTMCell(128)) net = dropout(net, 0.5) net = fully_connected(net, 2, activation='softmax') net = regression(net, optimizer='adam', loss='categorical_crossentropy') # Training model = zqtflearn.DNN(net, clip_gradients=0., tensorboard_verbose=2) model.fit(trainX, trainY, validation_set=0.1, show_metric=True, batch_size=64)
activation='relu', name='block5_conv2') block5_conv3 = conv_2d(block5_conv2, 512, 3, activation='relu', name='block5_conv3') block5_conv4 = conv_2d(block5_conv3, 512, 3, activation='relu', name='block5_conv4') block4_pool = max_pool_2d(block5_conv4, 2, strides=2, name='block4_pool') flatten_layer = zqtflearn.layers.core.flatten(block4_pool, name='Flatten') fc1 = fully_connected(flatten_layer, 4096, activation='relu') dp1 = dropout(fc1, 0.5) fc2 = fully_connected(dp1, 4096, activation='relu') dp2 = dropout(fc2, 0.5) network = fully_connected(dp2, 1000, activation='rmsprop') regression = zqtflearn.regression(network, optimizer='adam', loss='categorical_crossentropy', learning_rate=0.001) model = zqtflearn.DNN(regression, checkpoint_path='vgg19', tensorboard_dir="./logs")
name='inception_5b_pool') inception_5b_pool_1_1 = conv_2d(inception_5b_pool, 128, filter_size=1, activation='relu', name='inception_5b_pool_1_1') inception_5b_output = merge([ inception_5b_1_1, inception_5b_3_3, inception_5b_5_5, inception_5b_pool_1_1 ], axis=3, mode='concat') pool5_7_7 = avg_pool_2d(inception_5b_output, kernel_size=7, strides=1) pool5_7_7 = dropout(pool5_7_7, 0.4) # fc loss = fully_connected(pool5_7_7, 17, activation='softmax') network = regression(loss, optimizer='momentum', loss='categorical_crossentropy', learning_rate=0.001) # to train model = zqtflearn.DNN(network, checkpoint_path='model_googlenet', max_checkpoints=1, tensorboard_verbose=2) model.fit(X, Y, n_epoch=1000, validation_set=0.1,