forked from SoftwareDesignXRays/tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquantize_training.i
More file actions
70 lines (57 loc) · 2.23 KB
/
quantize_training.i
File metadata and controls
70 lines (57 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Copyright 2016 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.
==============================================================================*/
%include "tensorflow/python/platform/base.i"
%{
#include "tensorflow/core/graph/quantize_training.h"
#include "tensorflow/core/lib/core/status.h"
static PyObject* DoQuantizeTrainingOnGraphDefHelper(
const string& input_graph,
int num_bits,
TF_Status* out_status) {
string result;
// TODO(suharshs): Make the QuantizeAndDequantizeV2 configurable.
tensorflow::Status status =
tensorflow::DoQuantizeTrainingOnSerializedGraphDef(input_graph, num_bits,
"QuantizeAndDequantizeV2", &result);
if (!status.ok()) {
Set_TF_Status_from_Status(out_status, status);
Py_RETURN_NONE;
}
PyObject* py_str = PyBytes_FromStringAndSize(result.data(), result.size());
if (!py_str) {
Set_TF_Status_from_Status(out_status,
tensorflow::Status(tensorflow::error::INTERNAL,
"Failed to generate serialized string of the rewritten graph."));
Py_RETURN_NONE;
}
return py_str;
}
%}
%ignoreall
%unignore DoQuantizeTrainingOnGraphDefHelper;
// Wrap this function
PyObject* DoQuantizeTrainingOnGraphDefHelper(
const string& input_graph,
int num_bits,
TF_Status* out_status);
%insert("python") %{
def do_quantize_training_on_graphdef(input_graph, num_bits):
from tensorflow.core.framework.graph_pb2 import GraphDef
from tensorflow.python.framework import errors
with errors.raise_exception_on_not_ok_status() as status:
graph = GraphDef()
result_graph_string = DoQuantizeTrainingOnGraphDefHelper(
input_graph.SerializeToString(), num_bits, status)
graph.ParseFromString(result_graph_string)
return graph
%}
%unignoreall