Skip to content

ValueError: to_annotate can only be a keras.layers.Layer instance. You passed an instance of type: Dense. #1180

Description

@ningjingzhiwei

import tensorflow as tf
from tensorflow.keras import layers, models
import tensorflow_model_optimization as tfmot

Use quantize_annotate_layer to annotate that the Dense layer

should be quantized.

input_shape = (20,)
annotated_model = tf.keras.Sequential([
tfmot.quantization.keras.quantize_annotate_layer(tf.keras.layers.Dense(20, input_shape=input_shape)),
tf.keras.layers.Flatten()
])

Use quantize_apply to actually make the model quantization aware.

quant_aware_model = tfmot.quantization.keras.quantize_apply(annotated_model)
quant_aware_model.summary()

when run the above code, error appears:"ValueError: to_annotate can only be a keras.layers.Layer instance. You passed an instance of type: Dense." Can anyone find the way to fix it? Thanks a lot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions