File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
tensorflow_model_optimization/python/core/quantization/keras Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -172,6 +172,11 @@ def quantize_apply(model):
172
172
'annotated with `quantize_annotate`. There are no layers '
173
173
'to quantize.' )
174
174
175
+ if not model .built :
176
+ raise ValueError ('quantization cannot be applied to a model which has not'
177
+ 'been built yet. Please call `model.build(input_shape)`'
178
+ 'before quantizing your model.' )
179
+
175
180
def _clone_model_with_weights (model_to_clone ):
176
181
cloned_model = keras .models .clone_model (model_to_clone )
177
182
cloned_model .set_weights (model_to_clone .get_weights ())
Original file line number Diff line number Diff line change @@ -179,6 +179,14 @@ def testRaisesErrorNoAnnotatedLayers_Functional(self):
179
179
with self .assertRaises (ValueError ):
180
180
quantize_emulate .quantize_apply (model )
181
181
182
+ def testRaisesErrorModelNotBuilt (self ):
183
+ model = keras .Sequential ([
184
+ quantize_annotate (keras .layers .Dense (10 ), ** self .quant_params1 )])
185
+
186
+ self .assertFalse (model .built )
187
+ with self .assertRaises (ValueError ):
188
+ quantize_emulate .quantize_apply (model )
189
+
182
190
# Quantization Apply Tests
183
191
184
192
def _get_annotated_sequential_model (self ):
You can’t perform that action at this time.
0 commit comments