def testPostTrainingQuantize16x8(self): """Test for post-training quantization mode: activations/weights - int16/int8.""" saved_model_dir = os.path.join(self.get_temp_dir(), 'simple_savedmodel') input_size = [5, 5, 3] kernel_size = [3, 3, 1] layer_name = 'test_conv2d' input_0 = keras.layers.Input(shape=input_size) layer_0 = keras.layers.Conv2D( filters=kernel_size[-1], kernel_size=kernel_size[0:2], use_bias=False, name=layer_name)( input_0) model = keras.models.Model(inputs=[input_0], outputs=[layer_0]) keras_layer = [layer for layer in model.layers if layer.name == layer_name ][0] keras_layer.set_weights([ np.random.rand( input_size[-1], kernel_size[0], kernel_size[1], kernel_size[2], ).astype(np.float32) ]) saved_model.save(model, saved_model_dir) model_coverage.test_saved_model( saved_model_dir, post_training_quantize_16x8=True, model_input_size=input_size)
def testFloat(self): saved_model_dir = os.path.join(self.get_temp_dir(), 'simple_savedmodel') with session.Session().as_default() as sess: in_tensor_1 = array_ops.placeholder( shape=[1, 16, 16, 3], dtype=dtypes.float32, name='inputB') in_tensor_2 = array_ops.placeholder( shape=[1, 16, 16, 3], dtype=dtypes.float32, name='inputA') out_tensor = in_tensor_1 + in_tensor_2 inputs = {'x': in_tensor_1, 'y': in_tensor_2} outputs = {'z': out_tensor} saved_model.simple_save(sess, saved_model_dir, inputs, outputs) model_coverage.test_saved_model(saved_model_dir)
def testFloat(self): saved_model_dir = os.path.join(self.get_temp_dir(), 'simple_savedmodel') with ops.Graph().as_default(): with session.Session().as_default() as sess: in_tensor_1 = array_ops.placeholder( shape=[1, 16, 16, 3], dtype=dtypes.float32, name='inputB') in_tensor_2 = array_ops.placeholder( shape=[1, 16, 16, 3], dtype=dtypes.float32, name='inputA') out_tensor = in_tensor_1 + in_tensor_2 inputs = {'x': in_tensor_1, 'y': in_tensor_2} outputs = {'z': out_tensor} saved_model.simple_save(sess, saved_model_dir, inputs, outputs) model_coverage.test_saved_model(saved_model_dir)