Converting Convolutional Layer from Caffe to Tensorflow
<p>I'm trying to implement Richard Zhang's colorization model (<a href="http://richzhang.github.io/colorization/" rel="nofollow noreferrer">http://richzhang.github.io/colorization/</a>) in Tensorflow, and I've been working on implementing the architecture. I'm basically trying to convert the author's Caffe model into Tensorflow: while I was able to complete most of the conversion, my architecture seems to be buggy (dimensional issues during the optimization step). I've been trying to debug why it doesn't work, with minimal results, and I want to take a step back and make sure I'm implementing the model correctly. </p>

<p>For example, here is one of the author's convolutional layers:</p>

<pre><code>layer {
  name: "bw_conv1_1"
  type: "Convolution"
  bottom: "data_l"
  top: "conv1_1"
  # param {lr_mult: 0 decay_mult: 0} 
  # param {lr_mult: 0 decay_mult: 0} 
  convolution_param {
    num_output: 64
    pad: 1
    kernel_size: 3
  }
}
layer {
  name: "relu1_1"
  type: "ReLU"
  bottom: "conv1_1"
  top: "conv1_1"
}
layer {
  name: "conv1_2"
  type: "Convolution"
  bottom: "conv1_1"
  top: "conv1_2"
  # param {lr_mult: 0 decay_mult: 0} 
  # param {lr_mult: 0 decay_mult: 0} 
  convolution_param {
    num_output: 64
    pad: 1
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "relu1_2"
  type: "ReLU"
  bottom: "conv1_2"
  top: "conv1_2"
}
layer {
  name: "conv1_2norm"
  type: "BatchNorm"
  bottom: "conv1_2"
  top: "conv1_2norm"
  batch_norm_param{ }
  param {lr_mult: 0 decay_mult: 0}
  param {lr_mult: 0 decay_mult: 0}
  param {lr_mult: 0 decay_mult: 0}
}    
</code></pre>

<p>And here is my attempt at the corresponding Tensorflow code:</p>

<pre><code># some initial functions
def conv(x, W, stride):
    return tf.nn.conv2d(x, W, strides=[1, stride, stride, 1],
    padding='SAME')

def weight_variable(shape):
    initial = tf.truncated_normal(shape, stddev=0.1)
    return tf.Variable(initial)

def bias_variable(shape):
    initial = tf.constant(0.1, shape=shape)
    return tf.Variable(initial)

# conv layer 1 code
Wconv1_1 = weight_variable([3, 3, 1, 64])
bconv1_1 = bias_variable([64])

# x is the input value with shape [n, 256, 256, 1]
Rconv1_1 = tf.nn.relu(conv(x, Wconv1_1, 1) + bconv1_1)

Wconv1_2 = weight_variable([3, 3, 64, 64])
bconv1_2 = bias_variable([64])

Rconv1_2 = tf.nn.relu(conv(Rconv1_1, Wconv1_2, 2) + bconv1_2)

Rnorm1 = batch_norm(Rconv1_2, 64, phase_train)
</code></pre>

<p>Does this look like it's on the right track? I want to make sure I'm not gravely misinterpreting anything about Caffe or Tensorflow, as I'm new to both. Thanks!</p>