You are missing the operation that correspond to nn = tf.layers.Flatten()(p2).
You want to add in your forward out = out.view(out.size(0), -1) beween the last convolution and the first fully connected.