I would like to run a multi column deep neural networks in tensorflow like this :
for i in range(num):
output[i] = deepnn(x)
deepnn is copied from this code and has been deleted the last layer and changed to be smaller (C4-C4-64) in order to calculate the result with using the concated output from deepnn.
def deepnn(x):
# Reshape to use within a convolutional neural net.
# Last dimension is for "features" - there is only one here, since images are
# grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.
with tf.name_scope('reshape'):
x_image = tf.reshape(x, [-1, 28, 28, 1])
# First convolutional layer - maps one grayscale image to 32 feature maps.
with tf.name_scope('conv1'):
W_conv1 = weight_variable([5, 5, 1, 4])
b_conv1 = bias_variable([4])
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
# Pooling layer - downsamples by 2X.
with tf.name_scope('pool1'):
h_pool1 = max_pool_2x2(h_conv1)
# Second convolutional layer -- maps 32 feature maps to 64.
with tf.name_scope('conv2'):
W_conv2 = weight_variable([5, 5, 4, 4])
b_conv2 = bias_variable([4])
h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2)
# Second pooling layer.
with tf.name_scope('pool2'):
h_pool2 = max_pool_2x2(h_conv2)
# Fully connected layer 1 -- after 2 round of downsampling, our 28x28 image
# is down to 7x7x64 feature maps -- maps this to 1024 features.
with tf.name_scope('fc1'):
W_fc1 = weight_variable([7 * 7 * 4, 256])
b_fc1 = bias_variable([4])
h_pool2_flat = tf.reshape(h_pool2, [-1, 7*7*4])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)
return h_fc1
But what is wrong is that it calculate very slow (num = 256),and it just use about 40% of my gpu(GTX 1060 6GB)
I think it is the mechanism of tensorflow which makes it slow by calculating it one by one. How can I calculate these neural networks at the same time?
I have tried inter_op_parallelism_threads and intra_op_parallelism_threads but they don't work.