Skip to content

DNN-TF: let StridedSlice layer support const input#22628

Closed
WanliZhong wants to merge 1 commit intoopencv:4.xfrom
WanliZhong:issue#22597
Closed

DNN-TF: let StridedSlice layer support const input#22628
WanliZhong wants to merge 1 commit intoopencv:4.xfrom
WanliZhong:issue#22597

Conversation

@WanliZhong
Copy link
Copy Markdown
Member

This PR try to fix #22597.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@WanliZhong WanliZhong added category: dnn pr: needs test New functionality requires minimal tests set labels Oct 12, 2022
@WanliZhong
Copy link
Copy Markdown
Member Author

@rogday Hi, it doesn't seem easy to generate a const input node for this test. This may take much more time than it takes to fix the issue. Do you have some suggestions or can I not generate the test?
image

@rogday
Copy link
Copy Markdown
Member

rogday commented Oct 16, 2022

Hey @WanliZhong! I didn't work with TF in a long time, but I have an old snippet where I needed to cut the model for debugging purposes. You could try to do the same. Not sure if it still works or if there are any bugs :D
I think you're supposed to call save_graph() with the name of new output node.

with tf.gfile.FastGFile('model.pb', 'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())

nodes = [x for x in graph_def.node]


def save_graph(graph_def, node_name):
    visited = set()
    name_to_node = dict([(node.name, node) for node in nodes])

    def make_graph(node_name):
        nonlocal visited
        if node_name in visited:
            return []
        visited.add(node_name)

        node = name_to_node[node_name]

        graph = [node]
        for child_name in node.input:
            graph += make_graph(child_name)

        return graph
    
    del graph_def.node[:]
    new_nodes = make_graph(node_name)
    graph_def.node.extend(new_nodes)
    
    table = node_name.maketrans("/", "_")
    tf.train.write_graph(graph_def, "output_dir", 'new_model.pb', as_text=False)

If you don't manage to cut the model, I think it's okay to merge without test if the problem disappears.

@WanliZhong
Copy link
Copy Markdown
Member Author

THANKS! I will try this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: dnn pr: needs test New functionality requires minimal tests set

Projects

None yet

2 participants