Comments (7)
Please make sure the conversion is done correctly;
# Convert the model to TFLite
converter = tf.lite.TFLiteConverter.from_keras_model(nn_model)
tflite_model = converter.convert()
# Save the TFLite model
with open('model.tflite', 'wb') as f:
f.write(tflite_model)
Kindly ensure that there is no post-processing step that alters the output values, especially turning positive values into negatives.
Thank you!
from tensorflow.
@sushreebarsa
Yes, the conversion is done correctly. Also, I didn't modify the tensor output. So, it cannot change the output.
Please see my attached run log and script.
sample_dir.tar.gz
###################################################################
Converting to tf lite model...
/home/users/luant/nn_models_env/lib/python3.10/site-packages/tensorflow/lite/python/convert.py:953: UserWarning: Statistics for quantized inputs were expected, but not specified; continuing anyway.
warnings.warn(
2024-06-28 14:54:56.289495: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:378] Ignored output_format.
2024-06-28 14:54:56.289531: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:381] Ignored drop_control_dependency.
2024-06-28 14:54:56.290169: I tensorflow/cc/saved_model/reader.cc:83] Reading SavedModel from: /tmp/tmpk0b4s6xx
2024-06-28 14:54:56.310480: I tensorflow/cc/saved_model/reader.cc:51] Reading meta graph with tags { serve }
2024-06-28 14:54:56.310523: I tensorflow/cc/saved_model/reader.cc:146] Reading SavedModel debug info (if present) from: /tmp/tmpk0b4s6xx
2024-06-28 14:54:56.350321: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:388] MLIR V1 optimization pass is not enabled
2024-06-28 14:54:56.367995: I tensorflow/cc/saved_model/loader.cc:233] Restoring SavedModel bundle.
2024-06-28 14:54:56.906898: I tensorflow/cc/saved_model/loader.cc:217] Running initialization op on SavedModel bundle at path: /tmp/tmpk0b4s6xx
2024-06-28 14:54:57.075488: I tensorflow/cc/saved_model/loader.cc:316] SavedModel load for tags { serve }; Status: success: OK. Took 785327 microseconds.
2024-06-28 14:54:57.253047: I tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc:269] disabling MLIR crash reproducer, set env var `MLIR_CRASH_REPRODUCER_DIRECTORY` to enable.
Summary on the non-converted ops:
---------------------------------
* Accepted dialects: tfl, builtin, func
* Non-Converted Ops: 111, Total Ops 189, % non-converted = 58.73 %
* 111 ARITH ops
- arith.constant: 111 occurrences (f32: 108, i32: 3)
(f32: 16)
(f32: 53)
(f32: 1)
(f32: 1)
(f32: 1)
(f32: 2)
(f32: 1)
fully_quantize: 0, inference_type: 6, input_inference_type: INT8, output_inference_type: INT8
###################################################################
from tensorflow.
Hi @luanft
This negative relu outputs that you mentioned are from the quantized model , but if you dequantize the relu outputs back to float, they will be non-negative values.
To verify this just follow the below formula " actual_value = 0.12550510466098785 * (quantized_value + 128) " . Please let me know if you face any problems using the above approach.
from tensorflow.
Hi @sawantkumar,
How to calculate the value of constant 0.12550510466098785 in your formula?
actual_value = 0.12550510466098785 * (quantized_value + 128)
How the converter picks up the range for activation quantization?
- float64[-inf, 0, +inf] to [-128, 0, 127]
- float64[0, +inf] to [-128, 0, 127]
from tensorflow.
Hi @luanft ,
The value of the constant can been seen from the netron screenshot of the conv2d layer . And for calculating the range for conversion from float to int you can look at this
from tensorflow.
@sawantkumar Thank you. I got the issue. No problems with RELU activation. Let me close the bug.
from tensorflow.
Are you satisfied with the resolution of your issue?
Yes
No
from tensorflow.
Related Issues (20)
- Convergence of Actor critic algorthim HOT 1
- Web HOT 2
- Failure building wheel for v2.16.1 from scratch: cannot stat cudnn_backend_base.h HOT 1
- adding type annotations in TensorFlow HOT 1
- Memory leak in training HOT 2
- Aborted (core dumped) in `tf.io.TFRecordOptions`
- Issue with Loading libdelegate.so on Ubuntu 22.04 LTS Using TensorFlow Lite GPU Delegate HOT 2
- "Skipping the delay kernel" warning emitted thousands of times. HOT 1
- Issue with softmax warning appearing in Tensorflow 2.17.0 HOT 2
- Converting model for on-device training fails with "LLVM ERROR: Failed to infer result type(s)." HOT 1
- Aborted (core dumped) in `tf.config.threading.set_intra_op_parallelism_threads` HOT 1
- Segmentation fault (core dumped) in `tf.config.threading.set_inter_op_parallelism_threads`
- Can tflite model maker be used to train MobileNet models?
- Can the TensorFlow Android object detection example support MobileNetV2 and MobileNetV3 tflite models?
- ImportError: DLL load failed while importing _pywrap_tensorflow_internal: Error en una rutina de inicialización de biblioteca de vínculos dinámicos (DLL). HOT 4
- Conv2D is no longer supporting Masking in TF v2.17.0 HOT 5
- AttributeError: 'Sequential' object has no attribute '_get_save_spec'
- How to build python .whl on cmake with flex delegate support?
- Pip install of Tensorflow may be causing issues with MacOS HOT 7
- Building from Source without internet connection HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tensorflow.