yoeo / guesslangtools

Tool to build a training dataset for Guesslang, the programming language guesser
MIT License
22 stars 7 forks source link

how to transform .pb to .onnx #5

Closed yjmm10 closed 3 years ago

yjmm10 commented 3 years ago

I try to transform .pb to .onnx, but failed. Can you give me some advice or provide the file of onnx

yoeo commented 3 years ago

Hello @yjmm10,

I just tried the conversion with the official tool https://github.com/onnx/tensorflow-onnx and I failed as well:

python -m tf2onnx.convert  --saved-model guesslang/data/model/  --output model.onnx
...
2021-07-06 20:32:13.850571: E tensorflow/core/grappler/grappler_item_builder.cc:669] Init node head/predictions/class_string_lookup/table_init/LookupTableImportV2 doesn't exist in graph

But when I load the graph I can find the node on the graph. Mean that the issue is on the tool:

from guesslang.model import load

model_dir = './guesslang/data/model'
model = load(model_dir)

found = None
for operation in model.graph.get_operations():
    if 'head/predictions/class_string_lookup/table_init/LookupTableImportV2' in operation.name:
        found = operation
        break

print(found)
# <tf.Operation 'head/predictions/class_string_lookup/table_init/LookupTableImportV2' type=LookupTableImportV2>

For me, you can either:

yjmm10 commented 3 years ago

@yoeo

Thanks, I will try to convert the model to a simpler format like TFLite then convert it to ONNX. If it doesn't work, i should ask developers for help