本文整理汇总了Python中tensorflow.python.platform.gfile.Remove方法的典型用法代码示例。如果您正苦于以下问题:Python gfile.Remove方法的具体用法?Python gfile.Remove怎么用?Python gfile.Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.platform.gfile
的用法示例。
在下文中一共展示了gfile.Remove方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testWriteScreenOutputToFileWorks
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Remove [as 别名]
def testWriteScreenOutputToFileWorks(self):
output_path = tempfile.mktemp()
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 2>%s\n" % output_path),
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(1, len(ui.unwrapped_outputs))
with gfile.Open(output_path, "r") as f:
self.assertEqual(b"bar\nbar\n", f.read())
# Clean up output file.
gfile.Remove(output_path)
示例2: testAppendingRedirectErrors
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Remove [as 别名]
def testAppendingRedirectErrors(self):
output_path = tempfile.mktemp()
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 2 >> %s\n" % output_path),
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(
["Syntax error for command: babble", "For help, do \"help babble\""],
ui.unwrapped_outputs[0].lines)
# Clean up output file.
gfile.Remove(output_path)
示例3: gfile_copy_callback
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Remove [as 别名]
def gfile_copy_callback(files_to_copy, export_dir_path):
"""Callback to copy files using `gfile.Copy` to an export directory.
This method is used as the default `assets_callback` in `Exporter.init` to
copy assets from the `assets_collection`. It can also be invoked directly to
copy additional supplementary files into the export directory (in which case
it is not a callback).
Args:
files_to_copy: A dictionary that maps original file paths to desired
basename in the export directory.
export_dir_path: Directory to copy the files to.
"""
logging.info("Write assets into: %s using gfile_copy.", export_dir_path)
gfile.MakeDirs(export_dir_path)
for source_filepath, basename in files_to_copy.items():
new_path = os.path.join(
compat.as_bytes(export_dir_path), compat.as_bytes(basename))
logging.info("Copying asset %s to path %s.", source_filepath, new_path)
if gfile.Exists(new_path):
# Guard against being restarted while copying assets, and the file
# existing and being in an unknown state.
# TODO(b/28676216): Do some file checks before deleting.
logging.info("Removing file %s.", new_path)
gfile.Remove(new_path)
gfile.Copy(source_filepath, new_path)
示例4: testWriteToFileSucceeds
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Remove [as 别名]
def testWriteToFileSucceeds(self):
screen_output = debugger_cli_common.RichTextLines(
["Roses are red", "Violets are blue"],
font_attr_segs={0: [(0, 5, "red")],
1: [(0, 7, "blue")]})
file_path = tempfile.mktemp()
screen_output.write_to_file(file_path)
with gfile.Open(file_path, "r") as f:
self.assertEqual(b"Roses are red\nViolets are blue\n", f.read())
# Clean up.
gfile.Remove(file_path)
示例5: testBinaryAndTextFormat
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Remove [as 别名]
def testBinaryAndTextFormat(self):
test_dir = _TestDir("binary_and_text")
filename = os.path.join(test_dir, "metafile")
with self.test_session(graph=tf.Graph()):
# Creates a graph.
tf.Variable(10.0, name="v0")
# Exports the graph as binary format.
tf.train.export_meta_graph(filename, as_text=False)
with self.test_session(graph=tf.Graph()):
# Imports the binary format graph.
saver = tf.train.import_meta_graph(filename)
self.assertIsNotNone(saver)
# Exports the graph as text format.
saver.export_meta_graph(filename, as_text=True)
with self.test_session(graph=tf.Graph()):
# Imports the text format graph.
tf.train.import_meta_graph(filename)
# Writes wrong contents to the file.
tf.train.write_graph(saver.as_saver_def(), os.path.dirname(filename),
os.path.basename(filename))
with self.test_session(graph=tf.Graph()):
# Import should fail.
with self.assertRaisesWithPredicateMatch(
IOError, lambda e: "Cannot parse file"):
tf.train.import_meta_graph(filename)
# Deletes the file
gfile.Remove(filename)
with self.assertRaisesWithPredicateMatch(
IOError, lambda e: "does not exist"):
tf.train.import_meta_graph(filename)
示例6: edit_pb_txt
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Remove [as 别名]
def edit_pb_txt(old_args, export_dir):
"""
Edit file path argument in pbtxt file.
:param old_args: Old file paths need to be copied and edited.
:param export_dir: Directory of the saved model.
"""
assets_extra_dir = os.path.join(export_dir, "./assets.extra")
if not os.path.exists(assets_extra_dir):
os.makedirs(assets_extra_dir)
new_args = []
for one_old in old_args:
if not os.path.exists(one_old):
raise ValueError("{} do not exists!".format(one_old))
one_new = os.path.join(assets_extra_dir, os.path.basename(one_old))
new_args.append(one_new)
logging.info("Copy file: {} to: {}".format(one_old, one_new))
gfile.Copy(one_old, one_new, overwrite=True)
pbtxt_file = os.path.join(export_dir, "saved_model.pbtxt")
tmp_file = pbtxt_file + ".tmp"
logging.info("Editing pbtxt file: {}".format(pbtxt_file))
with open(pbtxt_file, "rt") as fin, open(tmp_file, "wt") as fout:
for line in fin:
for one_old, one_new in zip(old_args, new_args):
line = line.replace(one_old, one_new)
fout.write(line)
gfile.Copy(tmp_file, pbtxt_file, overwrite=True)
gfile.Remove(tmp_file)