Merge pull request #14955 from guschmue/win-quantized-ops
add support for quantized ops on windows
This commit is contained in:
commit
1577e2d56b
@ -19,23 +19,6 @@ for instructions on how to install a pre-built TensorFlow package on Windows.
|
||||
### Current known limitations
|
||||
* It is not possible to load a custom Op library.
|
||||
* GCS file system is not supported.
|
||||
* The following Ops are not currently implemented:
|
||||
- Dequantize
|
||||
- QuantizeAndDequantize
|
||||
- QuantizedAvgPool
|
||||
- QuantizedBatchNomWithGlobalNormalization
|
||||
- QuantizedBiasAdd
|
||||
- QuantizedConcat
|
||||
- QuantizedConv2D
|
||||
- QuantizedMatmul
|
||||
- QuantizedMaxPoo
|
||||
- QuantizeDownAndShrinkRange
|
||||
- QuantizedRelu
|
||||
- QuantizedRelu6
|
||||
- QuantizedReshape
|
||||
- QuantizeV2
|
||||
- RequantizationRange
|
||||
- Requantize
|
||||
|
||||
## Building with CMake
|
||||
|
||||
|
@ -14,8 +14,8 @@
|
||||
# ==============================================================================
|
||||
include (ExternalProject)
|
||||
|
||||
set(gemmlowp_URL https://mirror.bazel.build/github.com/google/gemmlowp/archive/010bb3e71a26ca1d0884a167081d092b43563996.zip)
|
||||
set(gemmlowp_HASH SHA256=dd2557072bde12141419cb8320a9c25e6ec41a8ae53c2ac78c076a347bb46d9d)
|
||||
set(gemmlowp_URL https://github.com/google/gemmlowp/archive/6a2a90822e8546fc2bfa7044de0faf1c1cb4862f.zip)
|
||||
set(gemmlowp_HASH SHA256=3447948d219f3270383766bbe08942888c0eb4e0ca6663c0e0548502ec5bb77d)
|
||||
set(gemmlowp_BUILD ${CMAKE_CURRENT_BINARY_DIR}/gemmlowp/src/gemmlowp)
|
||||
set(gemmlowp_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/gemmlowp/src/gemmlowp)
|
||||
|
||||
|
@ -150,9 +150,6 @@ list(REMOVE_ITEM tf_core_kernels_srcs ${tf_core_kernels_exclude_srcs})
|
||||
if(WIN32)
|
||||
file(GLOB_RECURSE tf_core_kernels_windows_exclude_srcs
|
||||
# not working on windows yet
|
||||
"${tensorflow_source_dir}/tensorflow/core/kernels/meta_support.*"
|
||||
"${tensorflow_source_dir}/tensorflow/core/kernels/*quantiz*.h"
|
||||
"${tensorflow_source_dir}/tensorflow/core/kernels/*quantiz*.cc"
|
||||
"${tensorflow_source_dir}/tensorflow/core/kernels/neon/*"
|
||||
# not in core - those are loaded dynamically as dll
|
||||
"${tensorflow_source_dir}/tensorflow/contrib/nearest_neighbor/kernels/hyperplane_lsh_probes.cc"
|
||||
|
@ -145,6 +145,8 @@ if (tensorflow_BUILD_PYTHON_TESTS)
|
||||
"${tensorflow_source_dir}/tensorflow/contrib/estimator/python/estimator/*_test.py"
|
||||
"${tensorflow_source_dir}/tensorflow/python/kernel_tests/*.py"
|
||||
"${tensorflow_source_dir}/tensorflow/python/meta_graph_transform/*_test.py"
|
||||
"${tensorflow_source_dir}/tensorflow/python/ops/quantized_conv_ops_test.py"
|
||||
"${tensorflow_source_dir}/tensorflow/python/ops/quantized_ops_test.py"
|
||||
"${tensorflow_source_dir}/tensorflow/python/platform/build_info_test.py"
|
||||
"${tensorflow_source_dir}/tensorflow/python/profiler/*_test.py"
|
||||
"${tensorflow_source_dir}/tensorflow/python/profiler/internal/*_test.py"
|
||||
|
@ -268,6 +268,13 @@ class Im2ColConvFunctor {
|
||||
Im2ColBufferResource<T1, chunk_value_count>* im2col_buffer_resource;
|
||||
std::function<Status(Im2ColBufferResource<T1, chunk_value_count>**)>
|
||||
creator = [](Im2ColBufferResource<T1, chunk_value_count>** resource) {
|
||||
#ifdef _MSC_VER
|
||||
// MSVC complains about the capture of chunk_value_count which oddly
|
||||
// works fine in conv_ops_using_gemm.cc for example.
|
||||
// Define chunk_value_count inside the lambda for now.
|
||||
const int64 chunk_value_count =
|
||||
(kMaxChunkSize + (sizeof(T1) - 1)) / sizeof(T1);
|
||||
#endif
|
||||
*resource = new Im2ColBufferResource<T1, chunk_value_count>();
|
||||
return Status::OK();
|
||||
};
|
||||
|
@ -93,7 +93,7 @@ class Conv2DTest(test.TestCase):
|
||||
quantized_range = ((quantized_max - quantized_min) * range_adjust)
|
||||
range_scale = (quantized_range / number_of_steps)
|
||||
lowest_quantized = -(1 << (number_of_bits - 1))
|
||||
result = np.array([(quantized_min + ((x - lowest_quantized) * range_scale))
|
||||
result = np.array([(quantized_min + ((float(x) - lowest_quantized) * range_scale))
|
||||
for x in quantized.flatten()])
|
||||
return result
|
||||
|
||||
|
57
tensorflow/python/ops/quantized_ops_test.py
Normal file
57
tensorflow/python/ops/quantized_ops_test.py
Normal file
@ -0,0 +1,57 @@
|
||||
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
# ==============================================================================
|
||||
"""Functional tests for quantized operations."""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
|
||||
from tensorflow.python.framework import constant_op
|
||||
from tensorflow.python.framework import dtypes
|
||||
from tensorflow.python.ops import array_ops
|
||||
from tensorflow.python.platform import test
|
||||
|
||||
|
||||
class QuantizedOpsTest(test.TestCase):
|
||||
|
||||
def __init__(self, method_name="runTest"):
|
||||
super(QuantizedOpsTest, self).__init__(method_name)
|
||||
|
||||
def testQuantizeOp(self):
|
||||
expected_output = [1, 1, 2, 127, 255, 255]
|
||||
with self.test_session(use_gpu=False) as sess:
|
||||
x = constant_op.constant([1.0, 1.25, 1.75, 127.0, 255.0, 500.0], shape=[6], dtype=dtypes.float32)
|
||||
x_min = 0.0
|
||||
x_max = 255.0
|
||||
op = array_ops.quantize(x, x_min, x_max, dtypes.quint8, mode="MIN_FIRST")
|
||||
value = sess.run(op)
|
||||
self.assertArrayNear(expected_output, value.output, 0.1)
|
||||
|
||||
def testDequantizeOp(self):
|
||||
expected_output = [1.0, 2.0, 4.0, 8.0, 16.0, 255.0]
|
||||
inp = np.array([1, 2, 4, 8, 16, 255]).astype(np.uint8)
|
||||
with self.test_session(use_gpu=False) as sess:
|
||||
x = constant_op.constant(inp, shape=[6], dtype=dtypes.quint8)
|
||||
x_min = 0.0
|
||||
x_max = 255.0
|
||||
op = array_ops.dequantize(x, x_min, x_max, mode="MIN_FIRST")
|
||||
value = sess.run(op)
|
||||
self.assertArrayNear(expected_output, value, 0.1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test.main()
|
Loading…
Reference in New Issue
Block a user