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):
172172 'annotated with `quantize_annotate`. There are no layers '
173173 'to quantize.' )
174174
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+
175180 def _clone_model_with_weights (model_to_clone ):
176181 cloned_model = keras .models .clone_model (model_to_clone )
177182 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):
179179 with self .assertRaises (ValueError ):
180180 quantize_emulate .quantize_apply (model )
181181
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+
182190 # Quantization Apply Tests
183191
184192 def _get_annotated_sequential_model (self ):
You can’t perform that action at this time.
0 commit comments