Initialization. Args: graph_def: A GraphDef message of the graph to be used in inference. GraphDef of default graph is used when None. init_op: Op to be used in initialization. clear_devices: If device info of the graph should be cleared upon export. default_grap
(self,
graph_def=None,
init_op=None,
clear_devices=False,
default_graph_signature=None,
named_graph_signatures=None,
assets_collection=None,
assets_callback=gfile_copy_callback)
| 152 | @deprecated("2017-06-30", |
| 153 | "No longer supported. Switch to SavedModel immediately.") |
| 154 | def init(self, |
| 155 | graph_def=None, |
| 156 | init_op=None, |
| 157 | clear_devices=False, |
| 158 | default_graph_signature=None, |
| 159 | named_graph_signatures=None, |
| 160 | assets_collection=None, |
| 161 | assets_callback=gfile_copy_callback): |
| 162 | """Initialization. |
| 163 | |
| 164 | Args: |
| 165 | graph_def: A GraphDef message of the graph to be used in inference. |
| 166 | GraphDef of default graph is used when None. |
| 167 | init_op: Op to be used in initialization. |
| 168 | clear_devices: If device info of the graph should be cleared upon export. |
| 169 | default_graph_signature: Default signature of the graph. |
| 170 | named_graph_signatures: Map of named input/output signatures of the graph. |
| 171 | assets_collection: A collection of constant asset filepath tensors. If set |
| 172 | the assets will be exported into the asset directory. |
| 173 | assets_callback: callback with two argument called during export with the |
| 174 | list of files to copy and the asset path. |
| 175 | Raises: |
| 176 | RuntimeError: if init is called more than once. |
| 177 | TypeError: if init_op is not an Operation or None. |
| 178 | ValueError: if asset file path tensors are not non-empty constant string |
| 179 | scalar tensors. |
| 180 | """ |
| 181 | # Avoid Dangerous default value [] |
| 182 | if named_graph_signatures is None: |
| 183 | named_graph_signatures = {} |
| 184 | assets = [] |
| 185 | if assets_collection: |
| 186 | for asset_tensor in assets_collection: |
| 187 | asset_filepath = self._file_path_value(asset_tensor) |
| 188 | if not asset_filepath: |
| 189 | raise ValueError("invalid asset filepath tensor %s" % asset_tensor) |
| 190 | basename = os.path.basename(asset_filepath) |
| 191 | assets.append((basename, asset_tensor)) |
| 192 | self._assets_to_copy[asset_filepath] = basename |
| 193 | |
| 194 | if self._has_init: |
| 195 | raise RuntimeError("init should be called only once") |
| 196 | self._has_init = True |
| 197 | |
| 198 | if graph_def or clear_devices: |
| 199 | copy = graph_pb2.GraphDef() |
| 200 | if graph_def: |
| 201 | copy.CopyFrom(graph_def) |
| 202 | else: |
| 203 | copy.CopyFrom(ops.get_default_graph().as_graph_def()) |
| 204 | if clear_devices: |
| 205 | for node in copy.node: |
| 206 | node.device = "" |
| 207 | graph_any_buf = Any() |
| 208 | graph_any_buf.Pack(copy) |
| 209 | ops.add_to_collection(constants.GRAPH_KEY, graph_any_buf) |
| 210 | |
| 211 | if init_op: |