I built a neural network for pixel-wise classification of 3D-images.
The classification task is very simple and does not call for a convolutional network, instead I calculate a number of features (Gaussian, LoG, Sobel,etc...) and feed these together with the original value into a classical MLP. Since the calculation of this features is very slow and does not take advantage of my GPU, I thought a Tensorflow implementation might help:
First I read a binary file and create one batch with a 3D array and 1 channel:
data_dir="/Users/Me/Documents/Data/"
filenames = [os.path.join(data_dir,'File_%05d.bin' % i ) for i in range(100)]
filename_queue = tf.train.string_input_producer(filenames)
Stack= BinChunkReader(filename_queue) #custom reader
sess = tf.Session()
print(sess.run(tf.shape(Stack))) #outputs [1 100 100 100 1]
Then I create a 3D kernel using a custom function and define the 3D convolution:
kernel=np.ones((11,11,11,1,1),dtype='int32')
kernel[:,:,:,0,0]=Get3DKernel("LoG", Radius=6,Param=5) #custom function to produce a kernel
kernel_init=tf.constant(kernel)
TF_kernel=tf.get_variable('LoG_filter', initializer= kernel_init)
LoG=tf.nn.conv3d(Stack,TF_kernel,[1,1,1,1,1],"SAME")
but trying to run this
sess = tf.Session()
sess.run(LoG)
produces the following error:
InvalidArgumentError: No OpKernel was registered to support Op 'Conv3D' with these attrs. Registered devices: [CPU], Registered kernels:
device='CPU'; T in [DT_FLOAT]
device='CPU'; T in [DT_DOUBLE]
[[Node: Conv3D_1 = Conv3D[T=DT_INT32, padding="SAME", strides=[1, 1, 1, 1, 1]](Reshape, LoG_filter/read)]]
The first question: what does this error mean and how do I implement a 3D convolution?
The second question: am I right in my assumption that implementing this in tensorflow (currently implemented with scikit-image) will be of advantage for the execution speed?
kernel=np.ones((11,11,11,1,1),dtype='float32')instead - GPhiloRegistered Devices :[CPU]in the error code seems to mean Tensorflow does not see your GPU... - GPhilo