Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert tensorflow pb (in NCHW format with ResizeOp) into OpenVino IR? #652

Closed
ausk opened this issue May 28, 2020 · 11 comments
Closed
Labels
bug Something isn't working category: MO Model Optimizer
Milestone

Comments

@ausk
Copy link

ausk commented May 28, 2020

Hi, I have a tensorflow pb model in NCHW format,how to convert it into OpenVino IR?

If I convert it directly, then I get

<layer id="0" name="image_input" type="Parameter" version="opset1">
    <data element_type="f16" shape="1,224,1,224"/>
    <output>
        <port id="0" precision="FP16">
            <dim>1</dim>
            <dim>224</dim>
            <dim>1</dim>
            <dim>224</dim>
        </port>
    </output>
</layer>

What openvino thinks: nhwc(1,1,224,224) => nchw(1,224,1,224)
But actually, it is: nchw(1,1,224,224) => nwch(1,224,1,224).

While there is no predefined NWCH format in openvino.

So does anyone know how to convert the pb(in NCHW format) into IR?

@ilyachur ilyachur added question Further information is requested category: MO Model Optimizer labels May 28, 2020
@ilyachur
Copy link
Contributor

@lazarevevgeny Can you help?

@lazarevevgeny
Copy link
Contributor

If your TF model is in NCHW layout you need to specify --disable_nhwc_to_nchw command line parameter when you convert the model.

@ausk
Copy link
Author

ausk commented May 28, 2020

@ilyachur @lazarevevgeny Thank you guys.

I convert the pb( NCHW) with option --disable_nhwc_to_nchw.

And when I run infer use openvino ( just in CPU first), I get one error:

Interpolate operation should be converted to Interp.

The openvino info:

 Device info:                CPU
        MKLDNNPlugin version ......... 2.1
        Build ........... 42025

My pb model contain Node ResizeNearNeighbor. If I convert the pb with --disable_nhwc_to_nchw, then I get a IR with such desc:

<layer id="285" name="fpn0/ResizeNearestNeighbor/Cast_125703_const" type="Const" version="opset1">
    <data element_type="i64" offset="47474976" shape="2" size="16"/>
    <output>
        <port id="1" precision="I64">
            <dim>2</dim>
        </port>
    </output>
</layer>
<layer id="286" name="fpn0/ResizeNearestNeighbor" type="Interpolate" version="opset1">
    <data align_corners="0" antialias="0" axes="1,2" mode="nearest" pads_begin="0" pads_end="0"/>
    <input>
        <port id="0">
            <dim>1</dim>
            <dim>14</dim>
            <dim>14</dim>
            <dim>128</dim>
        </port>
        <port id="1">
            <dim>2</dim>
        </port>
    </input>
    <output>
        <port id="2" precision="FP16">
            <dim>1</dim>
            <dim>28</dim>
            <dim>28</dim>
            <dim>128</dim>
        </port>
    </output>
</layer>

Then what should I do?

@ausk
Copy link
Author

ausk commented May 28, 2020

I make a small pb model (in OpenVino 2020.R2):

image

myresize_nchw.zip

You can test with it.

@ilyachur
Copy link
Contributor

ilyachur commented May 28, 2020

@ausk Thank you for the reproducer.

I checked it on the last master and the problem is that at the current moment OpenVINO supports Interpolate operation which is performed over spatial dimensions only.

Unfortunately in your case Interpolate is performed on axises 1, 2.

@ilyachur ilyachur added bug Something isn't working and removed question Further information is requested labels May 28, 2020
@ilyachur
Copy link
Contributor

We will look to this problem and find solution to fix it.

@lazarevevgeny
Copy link
Contributor

@ilyachur it is a different story. The MO does not convert the model correctly. During the conversion the Transpose before ResizeNearestNeighbor should be removed because in OpenVINO Interpolate works in NCHW layout but in TF the ResizeNearestNeighbor expects input in the NHWC layout. This is a tricky bug to be solved on the MO side.

@ausk
Copy link
Author

ausk commented May 29, 2020

@ilyachur @lazarevevgeny Thank you for your help. Best regards.

@ausk ausk changed the title How to convert tensorflow pb (in NCHW format) into OpenVino IR? How to convert tensorflow pb (in NCHW format with ResizeOp) into OpenVino IR? Jun 18, 2020
@lazarevevgeny
Copy link
Contributor

@ausk, the issue has been fixed. Please, take the MO from the master branch and convert the model again. Then use IE from OpenVINO 2020.4 to infer the model. Closing the ticket.

@lazarevevgeny lazarevevgeny added this to the 2021.1 milestone Jul 30, 2020
@witignite
Copy link

witignite commented Dec 7, 2020

@ausk Could you let me know how you created a nice graph figure from the pb model?

@lazarevevgeny
Copy link
Contributor

@witignite , you can use Netron to visualize the graph.

redradist pushed a commit to redradist/openvino that referenced this issue Oct 6, 2023
* update the dockerfile to use cuda base image and correct apt nvidia packages

* Return cudnn into Dockerfile, adds drivers

* Update README.md

---------

Co-authored-by: Dariusz Trawinski <Dariusz.Trawinski@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working category: MO Model Optimizer
Projects
None yet
Development

No branches or pull requests

4 participants