1
votes

I have two similar tensors; one has all the found valid boxes, and the other has all of the indexes where they belonged.

Tensor("valid_boxes:0", shape=(?, 9), dtype=float32)

Tensor("valid_boxes_indexes:0", shape=(?, 4), dtype=int64)

I need a map_fun which access both variables. I tried this:

operation = tf.map_fn(lambda x: generate_bounding_box(x[0], x[1][1], x[1][0], x[1][2], grid_h, grid_w, anchors), (valid_boxes, valid_boxes_indexes))

Tensorflow gave me the following:

ValueError: The two structures don't have the same nested structure.

First structure: type=tuple str=(tf.float32, tf.int64)

Second structure: type=Tensor str=Tensor("map_14/while/stack:0", shape=(5,), dtype=float32)

More specifically: Substructure "type=tuple str=(tf.float32, tf.int64)" is a sequence, while substructure "type=Tensor str=Tensor("map_14/while/stack:0", shape=(5,), dtype=float32)" is not

Is there any way to do this properly?

Thanks!

1

1 Answers

1
votes

You need to specify a dtype when the input and output values do not have the same structure. From the documentation of tf.map_fn:

Furthermore, fn may emit a different structure than its input. For example, fn may look like: fn = lambda t1: return (t1 + 1, t1 - 1). In this case, the dtype parameter is not optional: dtype must be a type or (possibly nested) tuple of types matching the output of fn.

Try with this:

operation = tf.map_fn(
    lambda x: generate_bounding_box(x[0], x[1][1], x[1][0], x[1][2],
                                    grid_h, grid_w, anchors),
    (valid_boxes, valid_boxes_indexes)
    dtype=tf.float32)