TensorFlow: Rerun network with a different input tensor?

Viewed 2341

Suppose I have a typical CNN model in TensorFlow.

def inference(images):
    # images: 4D tensor of [batch_size, IMAGE_SIZE, IMAGE_SIZE, 3] size.
    conv_1 = conv_layer(images, 64, 7, 2)
    pool_2 = pooling_layer(conv_1, 2, 2)
    conv_3 = conv_layer(pool_2, 192, 3, 1)
    pool_4 = pooling_layer(conv_3, 2, 2)
    ...
    conv_28 = conv_layer(conv_27, 1024, 3, 1)
    fc_29 = fc_layer(conv_28, 512)
    fc_30 = fc_layer(fc_29, 4096)
    return fc_30

A typical forward pass could be done like this:

images = input()
logits = inference(images)
output = sess.run([logits])

Now suppose my input function now returns a pair of arguments, left_images and right_images (stereo camera). I want to run right_images up to conv_28 and left_images up to fc_30. So something like this

images = tf.placeholder(tf.float32, [batch_size, IMAGE_SIZE, IMAGE_SIZE, 3])
left_images, right_images = input()
conv_28, fc_30 = inference(images)
right_images_val = sess.run([conv_28], feed_dict={images: right_images})
left_images_val = sess.run([fc_30], feed_dict={images: left_images})

This however fails with

TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, or numpy ndarrays.

I want to avoid having to evaluate inputs to then feed it back to TensorFlow. Calling inference twice with different arguments will also not work because functions like conv_layer create variables.

Is it possible to rerun the network with a different input tensor?

1 Answers
Related