-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable more Ops for Keras PTQ and Support Mix-precision (#835)
Signed-off-by: zehao-intel <[email protected]>
- Loading branch information
1 parent
62be9d1
commit 6997518
Showing
4 changed files
with
181 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2022 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import json | ||
import tensorflow as tf | ||
from tensorflow.keras import activations | ||
from tensorflow.keras import backend | ||
from tensorflow.keras import constraints | ||
from tensorflow.keras import initializers | ||
from tensorflow.keras import regularizers | ||
from tensorflow.keras.layers import MaxPooling2D | ||
from tensorflow.keras.layers import AveragePooling2D | ||
from tensorflow import quantization | ||
|
||
class QAvgPool2D(AveragePooling2D): | ||
def __init__(self, | ||
pool_size=(2, 2), | ||
strides=None, | ||
padding="valid", | ||
data_format=None, | ||
min_value=-10000, | ||
max_value=10000, | ||
**kwargs): | ||
super(QAvgPool2D, self).__init__( | ||
pool_size=pool_size, | ||
strides=strides, | ||
padding=padding, | ||
data_format=data_format, | ||
**kwargs) | ||
self.min_value = json.loads(min_value) | ||
self.max_value = json.loads(max_value) | ||
|
||
|
||
class QMaxPool2D(MaxPooling2D): | ||
def __init__(self, | ||
pool_size=(2, 2), | ||
strides=None, | ||
padding="valid", | ||
data_format=None, | ||
min_value=-10000, | ||
max_value=10000, | ||
**kwargs): | ||
super(QMaxPool2D, self).__init__( | ||
pool_size=pool_size, | ||
strides=strides, | ||
padding=padding, | ||
data_format=data_format, | ||
**kwargs) | ||
self.min_value = json.loads(min_value) | ||
self.max_value = json.loads(max_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters