- `Constant`
- Bring `Constant` layers unconnected to the model into the model.
- It is assumed that the `-nuo` option is specified because running `onnxsim` will remove constants from the ONNX file.
- Wrap constants in a `Lambda` layer and force them into the model.
- [toy_with_constant.onnx.zip](https://github.com/PINTO0309/onnx2tf/files/15292126/toy_with_constant.onnx.zip)
- Convert test
bash
onnx2tf -i toy_with_constant.onnx -nuo -cotof
|ONNX|TFLite|
|:-:|:-:|
|||

- Inference test
python
import tensorflow as tf
import numpy as np
from pprint import pprint
interpreter = tf.lite.Interpreter(model_path="saved_model/toy_with_constant_float32.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
interpreter.set_tensor(
tensor_index=input_details[0]['index'],
value=np.ones(tuple(input_details[0]['shape']), dtype=np.float32)
)
interpreter.invoke()
variable_output = interpreter.get_tensor(output_details[0]['index'])
constant_output = interpreter.get_tensor(output_details[1]['index'])
print("=================")
print("Variable Output:")
pprint(variable_output)
print("=================")
print("Constant Output:")
pprint(constant_output)
=================
Variable Output:
array([[-0.02787317, -0.05505124, 0.05421712, 0.03526559, -0.14131774,
0.0019211 , 0.08399964, 0.00433664, -0.00984338, -0.03370604]],
dtype=float32)
=================
Constant Output:
array([1., 2., 3., 4., 5.], dtype=float32)
- [Constant outputs removed from ONNX during conversion 627](https://github.com/PINTO0309/onnx2tf/issues/627)