本文整理匯總了Python中tensorflow.python.lib.io.file_io.atomic_write_string_to_file方法的典型用法代碼示例。如果您正苦於以下問題:Python file_io.atomic_write_string_to_file方法的具體用法?Python file_io.atomic_write_string_to_file怎麽用?Python file_io.atomic_write_string_to_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.lib.io.file_io
的用法示例。
在下文中一共展示了file_io.atomic_write_string_to_file方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: upload_schema
# 需要導入模塊: from tensorflow.python.lib.io import file_io [as 別名]
# 或者: from tensorflow.python.lib.io.file_io import atomic_write_string_to_file [as 別名]
def upload_schema(self): # type: () -> None
if not self.schema:
raise ValueError(
"Cannot upload a schema since no schema_path was provided. Either provide one, or "
"use write_stats_and_schema so that a schema can be inferred first."
)
file_io.atomic_write_string_to_file(self.schema_snapshot_path,
self.schema.SerializeToString())
示例2: upload_anomalies
# 需要導入模塊: from tensorflow.python.lib.io import file_io [as 別名]
# 或者: from tensorflow.python.lib.io.file_io import atomic_write_string_to_file [as 別名]
def upload_anomalies(self): # type: () -> None
if self.anomalies.anomaly_info:
file_io.atomic_write_string_to_file(self.anomalies_path,
self.anomalies.SerializeToString())
示例3: _SetState
# 需要導入模塊: from tensorflow.python.lib.io import file_io [as 別名]
# 或者: from tensorflow.python.lib.io.file_io import atomic_write_string_to_file [as 別名]
def _SetState(self, state):
file_io.atomic_write_string_to_file(self._state_file,
text_format.MessageToString(state))
示例4: update_checkpoint_state
# 需要導入模塊: from tensorflow.python.lib.io import file_io [as 別名]
# 或者: from tensorflow.python.lib.io.file_io import atomic_write_string_to_file [as 別名]
def update_checkpoint_state(save_dir,
model_checkpoint_path,
all_model_checkpoint_paths=None,
latest_filename=None):
"""Updates the content of the 'checkpoint' file.
This updates the checkpoint file containing a CheckpointState
proto.
Args:
save_dir: Directory where the model was saved.
model_checkpoint_path: The checkpoint file.
all_model_checkpoint_paths: List of strings. Paths to all not-yet-deleted
checkpoints, sorted from oldest to newest. If this is a non-empty list,
the last element must be equal to model_checkpoint_path. These paths
are also saved in the CheckpointState proto.
latest_filename: Optional name of the checkpoint file. Default to
'checkpoint'.
Raises:
RuntimeError: If the save paths conflict.
"""
# Writes the "checkpoint" file for the coordinator for later restoration.
coord_checkpoint_filename = _GetCheckpointFilename(save_dir, latest_filename)
ckpt = generate_checkpoint_state_proto(
save_dir,
model_checkpoint_path,
all_model_checkpoint_paths=all_model_checkpoint_paths)
if coord_checkpoint_filename == ckpt.model_checkpoint_path:
raise RuntimeError("Save path '%s' conflicts with path used for "
"checkpoint state. Please use a different save path." %
model_checkpoint_path)
# Preventing potential read/write race condition by *atomically* writing to a
# file.
file_io.atomic_write_string_to_file(coord_checkpoint_filename,
text_format.MessageToString(ckpt))
示例5: write_graph
# 需要導入模塊: from tensorflow.python.lib.io import file_io [as 別名]
# 或者: from tensorflow.python.lib.io.file_io import atomic_write_string_to_file [as 別名]
def write_graph(graph_or_graph_def, logdir, name, as_text=True):
"""Writes a graph proto to a file.
The graph is written as a binary proto unless `as_text` is `True`.
```python
v = tf.Variable(0, name='my_variable')
sess = tf.Session()
tf.train.write_graph(sess.graph_def, '/tmp/my-model', 'train.pbtxt')
```
or
```python
v = tf.Variable(0, name='my_variable')
sess = tf.Session()
tf.train.write_graph(sess.graph, '/tmp/my-model', 'train.pbtxt')
```
Args:
graph_or_graph_def: A `Graph` or a `GraphDef` protocol buffer.
logdir: Directory where to write the graph. This can refer to remote
filesystems, such as Google Cloud Storage (GCS).
name: Filename for the graph.
as_text: If `True`, writes the graph as an ASCII proto.
"""
if isinstance(graph_or_graph_def, ops.Graph):
graph_def = graph_or_graph_def.as_graph_def()
else:
graph_def = graph_or_graph_def
# gcs does not have the concept of directory at the moment.
if not file_io.file_exists(logdir) and not logdir.startswith('gs:'):
file_io.recursive_create_dir(logdir)
path = os.path.join(logdir, name)
if as_text:
file_io.atomic_write_string_to_file(path, str(graph_def))
else:
file_io.atomic_write_string_to_file(path, graph_def.SerializeToString())
示例6: write_metadata
# 需要導入模塊: from tensorflow.python.lib.io import file_io [as 別名]
# 或者: from tensorflow.python.lib.io.file_io import atomic_write_string_to_file [as 別名]
def write_metadata(metadata, path):
"""Write metadata to given path, in JSON format.
Args:
metadata: A `DatasetMetadata` to write.
path: a path to a directory where metadata should be written.
"""
if not file_io.file_exists(path):
file_io.recursive_create_dir(path)
schema_file = os.path.join(path, 'schema.pbtxt')
ascii_proto = text_format.MessageToString(metadata.schema)
file_io.atomic_write_string_to_file(schema_file, ascii_proto, overwrite=True)
示例7: _update_checkpoint_state
# 需要導入模塊: from tensorflow.python.lib.io import file_io [as 別名]
# 或者: from tensorflow.python.lib.io.file_io import atomic_write_string_to_file [as 別名]
def _update_checkpoint_state(save_dir,
model_checkpoint_path,
all_model_checkpoint_paths=None,
latest_filename=None,
save_relative_paths=False):
"""Updates the content of the 'checkpoint' file.
This updates the checkpoint file containing a CheckpointState
proto.
Args:
save_dir: Directory where the model was saved.
model_checkpoint_path: The checkpoint file.
all_model_checkpoint_paths: List of strings. Paths to all not-yet-deleted
checkpoints, sorted from oldest to newest. If this is a non-empty list,
the last element must be equal to model_checkpoint_path. These paths
are also saved in the CheckpointState proto.
latest_filename: Optional name of the checkpoint file. Default to
'checkpoint'.
save_relative_paths: If `True`, will write relative paths to the checkpoint
state file.
Raises:
RuntimeError: If any of the model checkpoint paths conflict with the file
containing CheckpointSate.
"""
# Writes the "checkpoint" file for the coordinator for later restoration.
coord_checkpoint_filename = _GetCheckpointFilename(save_dir, latest_filename)
if save_relative_paths:
if os.path.isabs(model_checkpoint_path):
rel_model_checkpoint_path = os.path.relpath(
model_checkpoint_path, save_dir)
else:
rel_model_checkpoint_path = model_checkpoint_path
rel_all_model_checkpoint_paths = []
for p in all_model_checkpoint_paths:
if os.path.isabs(p):
rel_all_model_checkpoint_paths.append(os.path.relpath(p, save_dir))
else:
rel_all_model_checkpoint_paths.append(p)
ckpt = generate_checkpoint_state_proto(
save_dir,
rel_model_checkpoint_path,
all_model_checkpoint_paths=rel_all_model_checkpoint_paths)
else:
ckpt = generate_checkpoint_state_proto(
save_dir,
model_checkpoint_path,
all_model_checkpoint_paths=all_model_checkpoint_paths)
if coord_checkpoint_filename == ckpt.model_checkpoint_path:
raise RuntimeError("Save path '%s' conflicts with path used for "
"checkpoint state. Please use a different save path." %
model_checkpoint_path)
# Preventing potential read/write race condition by *atomically* writing to a
# file.
file_io.atomic_write_string_to_file(coord_checkpoint_filename,
text_format.MessageToString(ckpt))
示例8: write_graph
# 需要導入模塊: from tensorflow.python.lib.io import file_io [as 別名]
# 或者: from tensorflow.python.lib.io.file_io import atomic_write_string_to_file [as 別名]
def write_graph(graph_or_graph_def, logdir, name, as_text=True):
"""Writes a graph proto to a file.
The graph is written as a binary proto unless `as_text` is `True`.
```python
v = tf.Variable(0, name='my_variable')
sess = tf.Session()
tf.train.write_graph(sess.graph_def, '/tmp/my-model', 'train.pbtxt')
```
or
```python
v = tf.Variable(0, name='my_variable')
sess = tf.Session()
tf.train.write_graph(sess.graph, '/tmp/my-model', 'train.pbtxt')
```
Args:
graph_or_graph_def: A `Graph` or a `GraphDef` protocol buffer.
logdir: Directory where to write the graph. This can refer to remote
filesystems, such as Google Cloud Storage (GCS).
name: Filename for the graph.
as_text: If `True`, writes the graph as an ASCII proto.
Returns:
The path of the output proto file.
"""
if isinstance(graph_or_graph_def, ops.Graph):
graph_def = graph_or_graph_def.as_graph_def()
else:
graph_def = graph_or_graph_def
# gcs does not have the concept of directory at the moment.
if not file_io.file_exists(logdir) and not logdir.startswith('gs:'):
file_io.recursive_create_dir(logdir)
path = os.path.join(logdir, name)
if as_text:
file_io.atomic_write_string_to_file(path, str(graph_def))
else:
file_io.atomic_write_string_to_file(path, graph_def.SerializeToString())
return path
示例9: write_graph
# 需要導入模塊: from tensorflow.python.lib.io import file_io [as 別名]
# 或者: from tensorflow.python.lib.io.file_io import atomic_write_string_to_file [as 別名]
def write_graph(graph_or_graph_def, logdir, name, as_text=True):
"""Writes a graph proto to a file.
The graph is written as a text proto unless `as_text` is `False`.
```python
v = tf.Variable(0, name='my_variable')
sess = tf.Session()
tf.train.write_graph(sess.graph_def, '/tmp/my-model', 'train.pbtxt')
```
or
```python
v = tf.Variable(0, name='my_variable')
sess = tf.Session()
tf.train.write_graph(sess.graph, '/tmp/my-model', 'train.pbtxt')
```
Args:
graph_or_graph_def: A `Graph` or a `GraphDef` protocol buffer.
logdir: Directory where to write the graph. This can refer to remote
filesystems, such as Google Cloud Storage (GCS).
name: Filename for the graph.
as_text: If `True`, writes the graph as an ASCII proto.
Returns:
The path of the output proto file.
"""
if isinstance(graph_or_graph_def, ops.Graph):
graph_def = graph_or_graph_def.as_graph_def()
else:
graph_def = graph_or_graph_def
# gcs does not have the concept of directory at the moment.
if not file_io.file_exists(logdir) and not logdir.startswith('gs:'):
file_io.recursive_create_dir(logdir)
path = os.path.join(logdir, name)
if as_text:
file_io.atomic_write_string_to_file(path,
text_format.MessageToString(graph_def))
else:
file_io.atomic_write_string_to_file(path, graph_def.SerializeToString())
return path
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:46,代碼來源:graph_io.py