Giter Site home page Giter Site logo

Comments (7)

sushreebarsa avatar sushreebarsa commented on August 17, 2024

@luanft

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.

luanft avatar luanft commented on August 17, 2024

@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.

sawantkumar avatar sawantkumar commented on August 17, 2024

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.

luanft avatar luanft commented on August 17, 2024

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?

  1. float64[-inf, 0, +inf] to [-128, 0, 127]
  2. float64[0, +inf] to [-128, 0, 127]

from tensorflow.

sawantkumar avatar sawantkumar commented on August 17, 2024

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.

luanft avatar luanft commented on August 17, 2024

@sawantkumar Thank you. I got the issue. No problems with RELU activation. Let me close the bug.

from tensorflow.

google-ml-butler avatar google-ml-butler commented on August 17, 2024

Are you satisfied with the resolution of your issue?
Yes
No

from tensorflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.