|
9 | 9 | import tensorflow as tf
|
10 | 10 | import numpy as np
|
11 | 11 | from google.protobuf.message import DecodeError
|
| 12 | +from tensorflow.core.framework import tensor_pb2 |
12 | 13 | from tensorflow.core.protobuf import saved_model_pb2
|
13 | 14 | from tensorflow.python.ops import lookup_ops
|
14 | 15 | from tensorflow.python.util import compat
|
@@ -127,8 +128,28 @@ def convert_variables_to_constants_large_model(func):
|
127 | 128 | _FunctionConverterData, _replace_variables_by_constants # pylint: disable=protected-access
|
128 | 129 | except ImportError:
|
129 | 130 | _not_implemented_tf_placeholder("_replace_variables_by_constants")()
|
130 |
| - converter_data = _FunctionConverterData(func=func, lower_control_flow=False, aggressive_inlining=True) |
131 |
| - frozen_graph_def, _ = _replace_variables_by_constants(converter_data=converter_data) |
| 131 | + |
| 132 | + from tensorflow.python.framework import tensor_util, tensor_shape |
| 133 | + make_tensor_proto_original = tensor_util.make_tensor_proto |
| 134 | + # Hack to avoid 2GB check |
| 135 | + def make_tensor_proto_wrapped(values, dtype=None, shape=None, verify_shape=False, allow_broadcast=False): |
| 136 | + try: |
| 137 | + return make_tensor_proto_original(values, dtype, shape, verify_shape, allow_broadcast) |
| 138 | + except ValueError: |
| 139 | + if dtype is None: |
| 140 | + dtype = tf.dtypes.as_dtype(values.dtype).as_datatype_enum |
| 141 | + tensor_proto = tensor_pb2.TensorProto( |
| 142 | + dtype=dtype, |
| 143 | + tensor_shape=tensor_shape.as_shape(values.shape).as_proto()) |
| 144 | + tensor_proto.tensor_content = values.tobytes() |
| 145 | + return tensor_proto |
| 146 | + tensor_util.make_tensor_proto = make_tensor_proto_wrapped |
| 147 | + |
| 148 | + try: |
| 149 | + converter_data = _FunctionConverterData(func=func, lower_control_flow=False, aggressive_inlining=True) |
| 150 | + frozen_graph_def, _ = _replace_variables_by_constants(converter_data=converter_data) |
| 151 | + finally: |
| 152 | + tensor_util.make_tensor_proto = make_tensor_proto_original |
132 | 153 | return frozen_graph_def
|
133 | 154 |
|
134 | 155 |
|
|
0 commit comments