I am following this tutorial for learning TensorFlow Slim but upon running the following code for Inception:
import numpy as np
import os
import tensorflow a
explicitly writing the name of the arguments solves the problem.
instead of
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
use
net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
I found most people answering wrong way. Its just due to the change in the tf.concat. It works in the following way.
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
use the following
net = tf.concat(values=[branch_0, branch_1, branch_2, branch_3],axis=3,)
Remember while passing the keyword arguments should be before the others.
I got same error when I did the work.
I found that
logits = tf.nn.xw_plus_b(tf.concat(outputs, 0), w, b)
loss = tf.reduce_mean(
tf.nn.softmax_cross_entropy_with_logits(
labels=tf.concat(train_labels, 0), logits=logits))
The output is shape=(10, 64, 64)
.
The code want concat outputs[0] to outputs[9] => get a new shape(640,64).
But the "tf.concat" API may not allow to do this.
(train_labels same to this)
So I write to
A = tf.concat(0,[outputs[0],outputs[1]])
A = tf.concat(0,[A,outputs[2]])
A = tf.concat(0,[A,outputs[3]])
A = tf.concat(0,[A,outputs[4]])
A = tf.concat(0,[A,outputs[5]])
A = tf.concat(0,[A,outputs[6]])
A = tf.concat(0,[A,outputs[7]])
A = tf.concat(0,[A,outputs[8]])
A = tf.concat(0,[A,outputs[9]])
B = tf.concat(0,[train_labels[0],train_labels[1]])
B = tf.concat(0,[B,train_labels[2]])
B = tf.concat(0,[B,train_labels[3]])
B = tf.concat(0,[B,train_labels[4]])
B = tf.concat(0,[B,train_labels[5]])
B = tf.concat(0,[B,train_labels[6]])
B = tf.concat(0,[B,train_labels[7]])
B = tf.concat(0,[B,train_labels[8]])
B = tf.concat(0,[B,train_labels[9]])
logits = tf.nn.xw_plus_b(tf.concat(0, A), w, b)
loss = tf.reduce_mean(
tf.nn.softmax_cross_entropy_with_logits(
labels=tf.concat(0, B), logits=logits))
It can run!
I got the same problem when using the 1.0 released and I could make it work without having to roll back on a previous version.
The problem is caused by change in the api. That discussion helped me to find the solution: Google group > Recent API Changes in TensorFlow
You just have to update all the line with tf.concat
for example
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
should be changed to
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
Note:
I was able to use the models without problem. But I still got error afterward when wanting to load the pretrained weight. Seems that the slim module got several changed since they made the checkpoint file. The graph created by the code and the one present in the checkpoint file were different.
Note2:
I was able to use the pretrain weights for inception_resnet_v2 by adding to all conv2d layer biases_initializer=None