<p dir="auto">I have tried all the methods but did not succeed to make a batch processing of images in Go Tensorflow.</p>
<p dir="auto">I have been following this test case for the inception model. I tried many things but did not work.<br>
<a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/go/example_inception_inference_test.go#L199">https://github.com/tensorflow/tensorflow/blob/master/tensorflow/go/example_inception_inference_test.go#L199</a></p>
<p dir="auto">Could anyone help me? I really appreciate any help.</p>
<p dir="auto"><em>Please make sure that this is a bug. As per our <a href="https://github.com/tensorflow/tensorflow/blob/master/ISSUES.md">GitHub Policy</a>, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template</em></p>
<p dir="auto"><strong>System information</strong></p>
<ul dir="auto">
<li>Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes</li>
<li>OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10</li>
<li>TensorFlow installed from (source or binary): Binary</li>
<li>TensorFlow version (use command below): tensorflow-gpu 1.14.0</li>
<li>Python version: 3.6.7</li>
<li>CUDA/cuDNN version: 10</li>
<li>GPU model and memory: GTX1060M</li>
</ul>
<p dir="auto"><strong>Describe the current behavior</strong><br>
Wrapping a model in a TimeDistributed layer creates duplicate nodes in the graph. If we follow the docs <a href="https://keras.io/getting-started/functional-api-guide/#all-models-are-callable-just-like-layers" rel="nofollow">(link)</a> and create a simple Dense Model wrapped in a TD Layer:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    inner_input = keras.layers.Input((2,))
    dense = keras.layers.Dense(2, activation='relu')(inner_input)
    inner_model = keras.Model(inputs=inner_input, outputs=dense)

    full_input = keras.layers.Input((2,2))
    td_2 = keras.layers.TimeDistributed(inner_model)(full_input)
    model = keras.models.Model(full_input, td_2)
    model.compile('SGD', 'mse')"><pre class="notranslate"><code class="notranslate">    inner_input = keras.layers.Input((2,))
    dense = keras.layers.Dense(2, activation='relu')(inner_input)
    inner_model = keras.Model(inputs=inner_input, outputs=dense)

    full_input = keras.layers.Input((2,2))
    td_2 = keras.layers.TimeDistributed(inner_model)(full_input)
    model = keras.models.Model(full_input, td_2)
    model.compile('SGD', 'mse')
</code></pre></div>
<p dir="auto">You end up with this:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/24449147/60799985-d4e60c00-a1a6-11e9-84e8-e0b6ddd2a789.png"><img src="https://user-images.githubusercontent.com/24449147/60799985-d4e60c00-a1a6-11e9-84e8-e0b6ddd2a789.png" alt="bad_td" style="max-width: 100%;"></a><br>
Firstly, if you follow the documentation approach you end up with an additional Dense Layer (Bottom Left). This eats up memory, and happens because you build the inner model then rebuild it again when you build the TimeDistributed model. This can be avoided by parameterizing your model <a href="https://www.tensorflow.org/beta/guide/keras/custom_layers_and_models#building_models" rel="nofollow">(link)</a>, but it can be a very painful workaround if your model is complex. But for demonstrations sake, here's the model as an object:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    class InnerModel(keras.Model):
        def __init__(self):
            super(InnerModel, self).__init__()

            self.dense = keras.layers.Dense(2, activation='relu')

        def call(self, inputs, training=None, mask=None):
            out = self.dense(inputs)
            return out

        def compute_output_shape(self, input_shape):
            return (input_shape[0], 2)

    input = keras.layers.Input((2,2))
    td_model = InnerModel()
    time_dist = keras.layers.TimeDistributed(td_model)(input)
    model = keras.models.Model(input, time_dist)
    model.compile('SGD', 'mse')"><pre class="notranslate"><code class="notranslate">    class InnerModel(keras.Model):
        def __init__(self):
            super(InnerModel, self).__init__()

            self.dense = keras.layers.Dense(2, activation='relu')

        def call(self, inputs, training=None, mask=None):
            out = self.dense(inputs)
            return out

        def compute_output_shape(self, input_shape):
            return (input_shape[0], 2)

    input = keras.layers.Input((2,2))
    td_model = InnerModel()
    time_dist = keras.layers.TimeDistributed(td_model)(input)
    model = keras.models.Model(input, time_dist)
    model.compile('SGD', 'mse')
</code></pre></div>
<p dir="auto">Here's the improved graph:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/24449147/60801864-58552c80-a1aa-11e9-9550-24068fffc43c.png"><img src="https://user-images.githubusercontent.com/24449147/60801864-58552c80-a1aa-11e9-9550-24068fffc43c.png" alt="better_td" style="max-width: 100%;"></a></p>
<p dir="auto">So the additional Dense layer is gone, but there are still two dense layers inside. They have different contents too.<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/24449147/60801763-25ab3400-a1aa-11e9-9721-00482828ed58.png"><img src="https://user-images.githubusercontent.com/24449147/60801763-25ab3400-a1aa-11e9-9721-00482828ed58.png" alt="better_td_internal" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Describe the expected behavior</strong><br>
If you compare to what you get if you just wrap the Dense layer itself:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    full_input = keras.layers.Input((2,2,2))
    td_2 = keras.layers.TimeDistributed(keras.layers.Dense(2, activation='relu'))(full_input)
    model = keras.models.Model(full_input, td_2)
    model.compile('SGD', 'mse')"><pre class="notranslate"><code class="notranslate">    full_input = keras.layers.Input((2,2,2))
    td_2 = keras.layers.TimeDistributed(keras.layers.Dense(2, activation='relu'))(full_input)
    model = keras.models.Model(full_input, td_2)
    model.compile('SGD', 'mse')
</code></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/24449147/60800184-5c337f80-a1a7-11e9-8dd3-901054a537d9.png"><img src="https://user-images.githubusercontent.com/24449147/60800184-5c337f80-a1a7-11e9-8dd3-901054a537d9.png" alt="good_td" style="max-width: 100%;"></a></p>
<p dir="auto">I'd expect wrapping a model should result in a very similar looking graph to wrapping a layer</p>
<p dir="auto"><strong>Code to reproduce the issue</strong><br>
Full code for creating the graphs:<br>
<a href="https://gist.github.com/LukeBolly/0efeca3db275dee97c5f0fbf1f400b5a">https://gist.github.com/LukeBolly/0efeca3db275dee97c5f0fbf1f400b5a</a></p>