Hi, Marvin! I am trying to use your code to train a model. But I came up with the error below:
ValueError: No gradients provided for any variable, check your graph for ops that do not support gradients, between variables ["<tf.Variable 'conv1_1/filter:0' shape=(3, 3, 3, 64) dtype=float32_ref>", ......,"<tf.Variable 'upscore32/up_filter:0' shape=(16, 16, 37, 37) dtype=float32_ref>"] and loss Tensor("content_vgg/loss/total_loss:0", shape=(), dtype=float32)
I know this is not a bug issue but it did take me a lot time to check where the issue lies. I am wondering if you have any idea about this case.
here is my train code
# read data, get batch image/depth/label
# tensor with dtype uint8
NUM_CLASSES = 37
vgg_fcn = fcn8_vgg.FCN8VGG()
with tf.name_scope("content_vgg"):
vgg_fcn.build(img, num_classes=NUM_CLASSES, debug=True, train=True)
Logits = vgg_fcn.pred_up
Loss = loss(logits=Logits, labels=label, num_classes=NUM_CLASSES)
train_op = tf.train.AdamOptimizer(1e-3).minimize(Loss)
print('Finished building Network.')
start training
with tf.Session() as sess:
logging.info("Start Initializing Variabels.")
init = tf.global_variables_initializer()
sess.run(init)
print('Training the Network')
sess.run(train_op)
- I use Dataset API to read batch images.
As your original code use placeholder to read data and the placeholder(dtype:'float') will give image a Implicit conversion, I change a lit bit in `fcn8_vgg.py`:
with tf.name_scope('Processing'):
# here I cast image tensor form uint8 to float32
rgb = tf.cast(rgb, dtype=tf.float32)
red, green, blue = tf.split(rgb, 3, 3)
bgr = tf.concat([
blue - VGG_MEAN[0],
green - VGG_MEAN[1],
red - VGG_MEAN[2],
], 3)
and in `loss.py`:
with tf.name_scope('loss'):
# I cast logits to float32 beacuse the loss.py mention that logit has to be a float tensor
logits = tf.to_float(tf.reshape(logits, (-1, num_classes)))
# logits = tf.reshape(logits, (-1, num_classes))
epsilon = tf.constant(value=1e-4)
labels = tf.to_float(tf.reshape(labels, (-1, num_classes)))
softmax = tf.nn.softmax(logits) + epsilon
if head is not None:
cross_entropy = -tf.reduce_sum(tf.multiply(labels * tf.log(softmax),
head), reduction_indices=[1])
else:
cross_entropy = -tf.reduce_sum(
labels * tf.log(softmax), reduction_indices=[1])
cross_entropy_mean = tf.reduce_mean(cross_entropy,
name='xentropy_mean')
tf.add_to_collection('losses', cross_entropy_mean)
loss = tf.add_n(tf.get_collection('losses'), name='total_loss')
return loss
That is all I changed. My `tensorflow__version__` is 1.4.0
There are wrong connections in my graph, can you give me some advice?
Hi, Marvin! I am trying to use your code to train a model. But I came up with the error below:
ValueError: No gradients provided for any variable, check your graph for ops that do not support gradients, between variables ["<tf.Variable 'conv1_1/filter:0' shape=(3, 3, 3, 64) dtype=float32_ref>", ......,"<tf.Variable 'upscore32/up_filter:0' shape=(16, 16, 37, 37) dtype=float32_ref>"] and loss Tensor("content_vgg/loss/total_loss:0", shape=(), dtype=float32)
I know this is not a bug issue but it did take me a lot time to check where the issue lies. I am wondering if you have any idea about this case.
trainImg, trainDepth, trainLabel = Dataset.getDataName(split='train') dataset = Dataset.create_dataset(trainImg, trainDepth, trainLabel, batchsize=32) iterator = dataset.make_one_shot_iterator() (img, depth, label) = iterator.get_next()
build the network
NUM_CLASSES = 37 vgg_fcn = fcn8_vgg.FCN8VGG() with tf.name_scope("content_vgg"): vgg_fcn.build(img, num_classes=NUM_CLASSES, debug=True, train=True) Logits = vgg_fcn.pred_up Loss = loss(logits=Logits, labels=label, num_classes=NUM_CLASSES) train_op = tf.train.AdamOptimizer(1e-3).minimize(Loss) print('Finished building Network.')
start training
with tf.Session() as sess: logging.info("Start Initializing Variabels.") init = tf.global_variables_initializer() sess.run(init)