7

This is the code from Tensorflow's github pages for shape_refiner.cc:

// TODO(b/134547156): TEMPORARY WORKAROUND. If input shape handle is not set
// in outer context, set _Arg node output shape to unknown.
if (outer_context->input(index).SameHandle(ShapeHandle())) {
  LOG(WARNING) << "Function instantiation has undefined input shape at "
               << "index: " << index << " in the outer inference context.";
  node_context->set_output(0, node_context->UnknownShape());
} else {
  node_context->set_output(0, outer_context->input(index));
}

auto* resource = outer_context->input_handle_shapes_and_types(index);
if (resource) {
  node_context->set_output_handle_shapes_and_types(0, *resource);
}

I keep getting the warning set in the above code and it means nothing to me. Should I change my code or is this harmless to my training process? This question links to my other question: How to combine a pre-trained KerasLayer from TensorFlow (v. 2) Hub and tfrecords?

Innat
  • 16,113
  • 6
  • 53
  • 101
kelkka
  • 874
  • 7
  • 18
  • Did you set the input shape handle in the outer context? Perhaps you should show that code too. `SameHandle()` seems to just check the internal pointer for equality and `ShapeHandle()` initializes that pointer to `nullptr`. – Ted Lyngmo Nov 26 '19 at 18:45
  • @TedLyngmo Sorry, I have no clue what any of that means. If it helps, I'm writing my code in Python which happens to be utilising this shape_refiner.cc file. I guess the point is that I don't know what this outer context is, so it's difficult to change that in my code. – kelkka Nov 26 '19 at 20:25
  • Oh, that certainly complicates things. I'd check the documentation for the last call you do in python that makes it print the warning. Perhaps there's something there. The `Tensor` class has a `shape` property with some notes: "_In some cases, the inferred shape may have unknown dimensions. If the caller has additional information about the values of these dimensions, `Tensor.set_shape()` can be used to augment the inferred shape._". Don't know if that's the case here. – Ted Lyngmo Nov 26 '19 at 20:33
  • 1
    @TedLyngmo Thanks, I'll look into to that tomorrow. It's really confusing because I've managed to at least make code output some sensible loss figures and accuracies (contra my other SO post), but then I'm not sure if this error is something I need to be worried about. It's just a warning after all and doesn't stop the algorithm from running ‍♂️ – kelkka Nov 26 '19 at 22:29
  • 1
    @TedLyngmo I've tried image_batch = tf.reshape(image_batch, [-1, 224, 224, 3]) and image_batch.set_shape([B_size, 224, 224, 3]) but neither removed the warning about the undefined shape. – kelkka Nov 27 '19 at 15:50

0 Answers0