Repository: opencv
Issue: error: (-2:Unspecified error) Input layer not found: functional_1/lstm_1/zeros_1/packed/1 in function 'cv::dnn::dnn4_v20200609::`anonymous-namespace'::TFImporter::connect'
Labels: feature,category: dnn

##### System information (version)
<!-- Example
- OpenCV => 4.4
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2017
-->

- OpenCV => 4.4
- Operating System / Platform => Windows 64 Bit
- Compiler =>  Visual Studio 2017

##### Detailed description

<!-- your description -->
I tried to load **tensorflow frozen graph .pb file** using `cv2.dnn.readNet()`, the code is modified from:
[https://github.com/leimao/Frozen_Graph_TensorFlow/blob/master/TensorFlow_v2/example_2.py](https://github.com/leimao/Frozen_Graph_TensorFlow/blob/master/TensorFlow_v2/example_2.py).
It's a multi-input and multi-output model. However, if I use the simple example from [https://github.com/leimao/Frozen_Graph_TensorFlow/blob/master/TensorFlow_v2/example_1.py](https://github.com/leimao/Frozen_Graph_TensorFlow/blob/master/TensorFlow_v2/example_1.py).
Everything works. 
Does it because the OpenCV doesn't support enough layers?
##### Steps to reproduce

<!-- to add code example fence it with triple backticks and optional file extension
    ```.py
    // C++ code example
    ```
 or attach as .txt or .zip file
-->
```python
import tensorflow as tf
from tensorflow import keras
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2
import numpy as np

from utils import wrap_frozen_graph

num_tags = 12  # Number of unique issue tags
num_words = 10000  # Size of vocabulary obtained when preprocessing text data
num_departments = 4  # Number of departments for predictions
# Dummy input data
title_data = np.random.randint(num_words, size=(1280, 10)).astype("float32")
body_data = np.random.randint(num_words, size=(1280, 100)).astype("float32")
tags_data = np.random.randint(2, size=(1280, num_tags)).astype("float32")
# Dummy target data
priority_targets = np.random.random(size=(1280, 1))
dept_targets = np.random.randint(2, size=(1280, num_departments))
def main():

    # Dummy example copied from TensorFlow
    # https://www.tensorflow.org/guide/keras/functional#models_with_multiple_inputs_and_outputs


    title_input = keras.Input(
        shape=(None,), name="title"
    )  # Variable-length sequence of ints
    body_input = keras.Input(shape=(None,), name="body")  # Variable-length sequence of ints
    tags_input = keras.Input(
        shape=(num_tags,), name="tags"
    )  # Binary vectors of size `num_tags`

    # Embed each word in the title into a 64-dimensional vector
    title_features = keras.layers.Embedding(num_words, 64)(title_input)
    # Embed each word in the text into a 64-dimensional vector
    body_features = keras.layers.Embedding(num_words, 64)(body_input)

    # Reduce sequence of embedded words in the title into a single 128-dimensional vector
    title_features = keras.layers.LSTM(128)(title_features)
    # Reduce sequence of embedded words in the body into a single 32-dimensional vector
    body_features = keras.layers.LSTM(32)(body_features)

    # Merge all available features into a single large vector via concatenation
    x = keras.layers.concatenate([title_features, body_features, tags_input])

    # Stick a logistic regression for priority prediction on top of the features
    priority_pred = keras.layers.Dense(1, name="priority")(x)
    # Stick a department classifier on top of the features
    department_pred = keras.layers.Dense(num_departments, name="department")(x)

    # Instantiate an end-to-end model predicting both priority and department
    model = keras.Model(
        inputs=[title_input, body_input, tags_input],
        outputs=[priority_pred, department_pred],
    )

    model.compile(
        optimizer=keras.optimizers.RMSprop(1e-3),
        loss=[
            keras.losses.BinaryCrossentropy(from_logits=True),
            keras.losses.CategoricalCrossentropy(from_logits=True),
        ],
        loss_weights=[1.0, 0.2],
    )

    model.fit(
        {"title": title_data, "body": body_data, "tags": tags_data},
        {"priority": priority_targets, "department": dept_targets},
        epochs=2,
        batch_size=32,
    )

    predictions = model.predict({"title": title_data[0:1], "body": body_data[0:1], "tags": tags_data[0:1]})
    predictions_priority = predictions[0]
    predictions_department = predictions[1]

    print("-" * 50)
    print("Example TensorFlow prediction reference:")
    print(predictions_priority)
    print(predictions_department)

    # Save model to SavedModel format
    tf.saved_model.save(model, "./models/complex_model")

    full_model = tf.function(lambda x: model(x))
    full_model = full_model.get_concrete_function(x=(tf.TensorSpec(model.inputs[0].shape, model.inputs[0].dtype), tf.TensorSpec(model.inputs[1].shape, model.inputs[1].dtype), tf.TensorSpec(model.inputs[2].shape, model.inputs[2].dtype)))

    # Get frozen ConcreteFunction
    # https://github.com/tensorflow/tensorflow/issues/36391#issuecomment-596055100
    frozen_func = convert_variables_to_constants_v2(full_model, lower_control_flow=False)
    frozen_func.graph.as_graph_def()

    layers = [op.name for op in frozen_func.graph.get_operations()]
    print("-" * 50)
    print("Frozen model layers: ")
    for layer in layers:
        print(layer)

    print("-" * 50)
    print("Frozen model inputs: ")
    print(frozen_func.inputs)
    print("Frozen model outputs: ")
    print(frozen_func.outputs)

    # Save frozen graph from frozen ConcreteFunction to hard drive
    tf.io.write_graph(graph_or_graph_def=frozen_func.graph,
                        logdir="./frozen_models",
                        name="complex_frozen_graph.pb",
                        as_text=False)

def test_cv():
    import cv2
    net = cv2.dnn_ClassificationModel("./frozen_models/complex_frozen_graph.pb")
    print(dir(net))
    net.setInputSize(28,28)
    print(net.classify([title_data[0:1],body_data[0:1],tags_data[0:1]]))
    print(priority_targets[0],dept_targets[0])
 

if __name__ == "__main__":

    main()
    test_cv()
```
##### Issue submission checklist

 - [ ] I report the issue, it's not a question
   <!--
   OpenCV team works with answers.opencv.org, Stack Overflow and other communities
   to discuss problems. Tickets with question without real issue statement will be
   closed.
   -->
 - [x] I checked the problem with documentation, FAQ, open issues,
       answers.opencv.org, Stack Overflow, etc and have not found solution
   <!--
   Places to check:
   * OpenCV documentation: https://docs.opencv.org
   * FAQ page: https://github.com/opencv/opencv/wiki/FAQ
   * OpenCV forum: https://answers.opencv.org
   * OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
   -->
 - [x] I updated to latest OpenCV version and the issue is still there
   <!--
   master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
   OpenCV team supports only latest release for each branch.
   The ticket is closed, if the problem is not reproduced with modern version.
   -->
 - [ ] There is reproducer code and related data files: videos, images, onnx, etc
   <!--
   The best reproducer -- test case for OpenCV that we can add to the library.
   Recommendations for media files and binary files:
   * Try to reproduce the issue with images and videos in opencv_extra repository
     to reduce attachment size
   * Use PNG for images, if you report some CV related bug, but not image reader
     issue
   * Attach the image as archite to the ticket, if you report some reader issue.
     Image hosting services compress images and it breaks the repro code.
   * Provide ONNX file for some public model or ONNX file with with random weights,
     if you report ONNX parsing or handling issue. Architecture details diagram
     from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
   -->