KhronosGroup / NNEF-Tools

The NNEF Tools repository contains tools to generate and consume NNEF documents
https://www.khronos.org/nnef
222 stars 58 forks source link

Inception v3 TF model is not converted #139

Closed dvorotnev closed 4 years ago

dvorotnev commented 4 years ago

I try to convert the Inception v3 model in NNEF model zoo from TF to NNEF with the following commands:

wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/model_zoo/upload_20180427/inception_v3_2018_04_27.tgz
tar -xf inception_v3_2018_04_27.tgz
python -m nnef_tools.convert --input-format=tf --output-format=nnef --input-model=./inception_v3.pb --output-model=model.nnef --input-shapes='{"input": (1,299,299,3)}'

But after refactoring of NNEF Tools, the model is not converted with a message:

Conversion for operation type(s) 'Shape' is not implemented

This can be resolved with a following custom-converters script according to the TF documentation:

from nnef_tools.conversion import Transform

CUSTOM_TRANSFORMS = {
    'Shape':
        Transform(
            type='constant',
            outputs='!O[0]',
            attribs={
                'shape': '!list([I[0].rank])',
                'dtype': '!out_type',
                'value': '!ensure_list(I[0].shape)',
            }
        ),
}

But I think, that it is better to add a conversion support of the Shape operation in the tf_to_nnef converter.

gyenesvi commented 4 years ago

This is not the right way to solve this, since converting shapes (and subsequent computation on those shapes) to constants is more complicated and only possible if the network actually has static shapes (could be dynamic as well).

However, the converter has the --fold-constants option, which should do exactly this, did you try that? It will only work if the input nodes of the network has static shapes (no None-s), or you explicitly supply static shapes in place of dynamic ones with the --input-shapes option. Let me know if that works as expected.

dvorotnev commented 4 years ago

With the --fold-constants flag the model is converted well. Thank you!