openvinotoolkit / openvino_notebooks

📚 Jupyter notebook tutorials for OpenVINO™
Apache License 2.0
2.37k stars 803 forks source link

A good notebook exercise #31

Closed aswinvk28 closed 1 month ago

aswinvk28 commented 3 years ago

I have a good notebook exercise to demonstrate custom layers as well as eliminating C extensions even for CPU device. Shall that be added here as a new notebook, please?

As per here: https://github.com/nscalo/nd131-people-counter-project-1/blob/main/student-repositories/nd131-openvino-people-counter-newui/custom_layers/arcface/cl_pnorm/user_mo_extensions/middle/PNormReplacement.py

I was able to eliminate custom layers extensions using just Python code in MO (Model Optimizer) using combinations of layers.

My suggestion is shall a demonstration be done to show its use cases in terms of CL, custom layers?

helena-intel commented 3 years ago

Thanks for your suggestion. Can you explain a bit more about what your code does exactly and what you would like to see in a notebook? If you have a demo notebook that demonstrates this that would of course be very interesting!

aswinvk28 commented 3 years ago

The code such as this is quite important.

def reduce_infer(node: Node):
    # some code here

    if not node.keep_dims:
            output_shape = output_shape[np.invert(used_dims)]

    # infer shape from this code
    node.out_port(0).data.set_shape(output_shape)

    # some code here
node.out_port(0).data.set_shape(output_shape)

This is explained only in a web page and I strongly suggest they should be on the openvino notebooks for people to take a look. Also with the Custom Layers, the model optimizer takes in different parameters such as --extensions this I suggest should be on the notebook to be clarifying the idea of conversion.

Code examples such as this in model optimizer creates an additional layer within the network, which is also a nice to have in the notebooks. How the connect method works as opposed to set_destination and set_data is suggested to be an example in the notebook. May be I can deliver a custom layer containing conversion from an image classification problem to a problem of probability.


normalize_node = NormalizeOp(graph, {'name': merge.name + '/Normalize', 
    'eps': 1e-6, 'across_spatial': 0, 'channel_shared': 0}).create_node()

# how to connect layers or nodes
bias_add.out_port(0).connect(normalize_node.in_port(0))

# why disconnect and when to disconnect
merge.in_port(0).disconnect()

# set_destination
normalize_node.out_port(0).get_connection().set_destination(merge.in_port(0))

Thanks

helena-intel commented 3 years ago

I agree, this sounds like a very useful topic for a notebook and we should include it. We are still in the early stages of this repository and have quite a few topics that we want to cover, so I cannot yet give a timeline for this. Thank you for suggesting it, and for the specific examples!

andrei-kochin commented 1 year ago

@aswinvk28 if this is still actual I can suggest you to update your tutorial to use API2.0 and contribute through a PR and we can further review it

github-actions[bot] commented 3 months ago

This issue will be closed in a week because of 9 months of no activity.