tensorflow / tensorflow/model-optimization

Trying to quantise MobileNetv3 small Exception encountered when calling layer "tf.__operators__.add_137"

Open
#980 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.6k
Forks
349
Avg merge
3d 2h
Merged PRs (30d)
1

Description

There has recently been an article saying mobilenetv3 can be used for QAT
https://blog.tensorflow.org/2022/06/Adding-Quantization-aware-Training-and-Pruning-to-the-TensorFlow-Model-Garden.html

However when I run this code:

from tensorflow.keras.applications import MobileNetV3Small
import tensorflow_model_optimization as tfmot

model = MobileNetV3Small(
    input_shape=(224, 224, 3),
    include_top=True,
    weights=None,
    classes=200,
)

qat_model = tfmot.quantization.keras.quantize_model(model)

I get this error:

AttributeError: Exception encountered when calling layer "tf.__operators__.add_56" (type TFOpLambda).

'list' object has no attribute 'dtype'

Call arguments received by layer "tf.__operators__.add_56" (type TFOpLambda):
  • x=['tf.Tensor(shape=(None, 112, 112, 16), dtype=float32)']
  • y=3.0
  • name=None

I am using an m1 Mac:
conda
Python 3.10.4
tensorflow-macos 2.9.2
tensorflow-metal 0.5.0
tensorflow-model-optimization 0.7.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the exception with MobileNetV3Small and tfmot.quantization.keras.quantize_model using the listed TensorFlow and optimization-tool versions. Trace how the quantization path handles the TFOpLambda addition, then verify that the model quantizes successfully and that a regression test covers this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.