Skip to content Skip to sidebar Skip to footer

Tensorflow Reshaping A Tensor

I'm trying to use tf.nn.sparse_softmax_cross_entropy_with_logits and I have followed the answer by user Olivier Moindrot [here][1] but I'm getting a dimension error I'm building a

Solution 1:

Let's forget about softmax and use a simpler tf.nn.sigmoid_cross_entropy_with_logits here:

  • with sigmoid, you only need one prediction per pixel
    • if pred[pixel] > 0.5, you predict 1
    • if pred[pixel] < 0.5, you predict 0
  • the shape of prediction and target should then be [batch_size, 40000]
pred = conv_net(x, weights, biases, keep_prob)  # shape [batch_size, 40000]
flattened_y = tf.reshape(y, [-1, 40000])  # shape [batch_size, 40000]

loss = tf.nn.sigmoid_cross_entropy_with_logits(pred, flattened_y)

Solution 2:

Using sparse softmax is going to be of help only after the last layer you want to resize the image to the original size (200*200).In this case using reshape as you have would ensure that the the code would be error free. But in your case you don't have to use sparse softmax. To see why check the dimensions of "pred".

Post a Comment for "Tensorflow Reshaping A Tensor"