当前位置: 首页>>代码示例>>Python>>正文


Python file_io.delete_file函数代码示例

本文整理汇总了Python中tensorflow.python.lib.io.file_io.delete_file函数的典型用法代码示例。如果您正苦于以下问题:Python delete_file函数的具体用法?Python delete_file怎么用?Python delete_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了delete_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _v1_asset_saved_model

 def _v1_asset_saved_model(self):
   export_graph = ops.Graph()
   vocab_path = os.path.join(self.get_temp_dir(), "vocab.txt")
   with open(vocab_path, "w") as f:
     f.write("alpha\nbeta\ngamma\n")
   with export_graph.as_default():
     initializer = lookup_ops.TextFileInitializer(
         vocab_path,
         key_dtype=dtypes.string,
         key_index=lookup_ops.TextFileIndex.WHOLE_LINE,
         value_dtype=dtypes.int64,
         value_index=lookup_ops.TextFileIndex.LINE_NUMBER)
     table = lookup_ops.HashTable(
         initializer, default_value=-1)
     start = array_ops.placeholder(
         shape=None, dtype=dtypes.string, name="in")
     output = table.lookup(start, name="out")
     with session_lib.Session() as session:
       session.run([table.initializer])
       path = os.path.join(self.get_temp_dir(), "saved_model", str(ops.uid()))
       simple_save.simple_save(
           session,
           path,
           inputs={"start": start},
           outputs={"output": output},
           legacy_init_op=table.initializer)
   file_io.delete_file(vocab_path)
   return path
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:28,代码来源:load_v1_in_v2_test.py

示例2: test_table

 def test_table(self):
   initializer = lookup_ops.TextFileInitializer(
       self._vocab_path,
       key_dtype=dtypes.string,
       key_index=lookup_ops.TextFileIndex.WHOLE_LINE,
       value_dtype=dtypes.int64,
       value_index=lookup_ops.TextFileIndex.LINE_NUMBER)
   root = util.Checkpoint(table=lookup_ops.HashTable(
       initializer, default_value=-1))
   root.table_user = def_function.function(
       root.table.lookup,
       input_signature=[tensor_spec.TensorSpec(None, dtypes.string)])
   self.assertEqual(
       2,
       self.evaluate(root.table_user(constant_op.constant("gamma"))))
   save_dir = os.path.join(self.get_temp_dir(), "saved_model")
   save.save(root, save_dir)
   file_io.delete_file(self._vocab_path)
   self.assertAllClose(
       {"output_0": [2, 0]},
       _import_and_infer(save_dir, {"keys": ["gamma", "alpha"]}))
   second_dir = os.path.join(self.get_temp_dir(), "second_dir")
   # Asset paths should track the location the SavedModel is loaded from.
   file_io.rename(save_dir, second_dir)
   self.assertAllClose(
       {"output_0": [2, 1]},
       _import_and_infer(second_dir, {"keys": ["gamma", "beta"]}))
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:27,代码来源:save_test.py

示例3: testFileWrite

 def testFileWrite(self):
   file_path = os.path.join(self.get_temp_dir(), "temp_file")
   file_io.write_string_to_file(file_path, "testing")
   self.assertTrue(file_io.file_exists(file_path))
   file_contents = file_io.read_file_to_string(file_path)
   self.assertEqual(b"testing", file_contents)
   file_io.delete_file(file_path)
开发者ID:AI-MR-Related,项目名称:tensorflow,代码行数:7,代码来源:file_io_test.py

示例4: create_object_test

def create_object_test():
  """Verifies file_io's object manipulation methods ."""
  starttime = int(round(time.time() * 1000))
  dir_name = "%s/tf_gcs_test_%s" % (FLAGS.gcs_bucket_url, starttime)
  print("Creating dir %s." % dir_name)
  file_io.create_dir(dir_name)

  # Create a file in this directory.
  file_name = "%s/test_file.txt" % dir_name
  print("Creating file %s." % file_name)
  file_io.write_string_to_file(file_name, "test file creation.")

  list_files_pattern = "%s/test_file*.txt" % dir_name
  print("Getting files matching pattern %s." % list_files_pattern)
  files_list = file_io.get_matching_files(list_files_pattern)
  print(files_list)

  assert len(files_list) == 1
  assert files_list[0] == file_name

  # Cleanup test files.
  print("Deleting file %s." % file_name)
  file_io.delete_file(file_name)

  # Delete directory.
  print("Deleting directory %s." % dir_name)
  file_io.delete_recursively(dir_name)
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:27,代码来源:gcs_smoke.py

示例5: _tito_out

    def _tito_out(tensor_in):
      checkpoint_dir = tmp_dir
      if tmp_dir is None:
        checkpoint_dir = tempfile.mkdtemp()

      g = tf.Graph()
      with g.as_default():
        si = tf.placeholder(dtype=tensor_in.dtype, shape=tensor_in.shape, name=tensor_in.op.name)
        so = tito_in(si)
        all_vars = tf.contrib.slim.get_variables_to_restore(exclude=exclude)
        saver = tf.train.Saver(all_vars)
        # Downloading the checkpoint from GCS to local speeds up saver.restore() a lot.
        checkpoint_tmp = os.path.join(checkpoint_dir, 'checkpoint')
        with file_io.FileIO(checkpoint, 'r') as f_in, file_io.FileIO(checkpoint_tmp, 'w') as f_out:
          f_out.write(f_in.read())
        with tf.Session() as sess:
          saver.restore(sess, checkpoint_tmp)
          output_graph_def = tf.graph_util.convert_variables_to_constants(sess,
                                                                          g.as_graph_def(),
                                                                          [so.op.name])
        file_io.delete_file(checkpoint_tmp)
        if tmp_dir is None:
          shutil.rmtree(checkpoint_dir)

      tensors_out = tf.import_graph_def(output_graph_def,
                                        input_map={si.name: tensor_in},
                                        return_elements=[so.name])
      return tensors_out[0]
开发者ID:googledatalab,项目名称:pydatalab,代码行数:28,代码来源:feature_transforms.py

示例6: testRename

 def testRename(self):
   file_path = os.path.join(self.get_temp_dir(), "temp_file")
   file_io.write_string_to_file(file_path, "testing")
   rename_path = os.path.join(self.get_temp_dir(), "rename_file")
   file_io.rename(file_path, rename_path)
   self.assertTrue(file_io.file_exists(rename_path))
   self.assertFalse(file_io.file_exists(file_path))
   file_io.delete_file(rename_path)
开发者ID:AI-MR-Related,项目名称:tensorflow,代码行数:8,代码来源:file_io_test.py

示例7: testCopyOverwriteFalse

 def testCopyOverwriteFalse(self):
   file_path = os.path.join(self.get_temp_dir(), "temp_file")
   file_io.write_string_to_file(file_path, "testing")
   copy_path = os.path.join(self.get_temp_dir(), "copy_file")
   file_io.write_string_to_file(copy_path, "copy")
   with self.assertRaises(errors.AlreadyExistsError):
     file_io.copy(file_path, copy_path, overwrite=False)
   file_io.delete_file(file_path)
   file_io.delete_file(copy_path)
开发者ID:AI-MR-Related,项目名称:tensorflow,代码行数:9,代码来源:file_io_test.py

示例8: testCopy

 def testCopy(self):
   file_path = os.path.join(self.get_temp_dir(), "temp_file")
   file_io.write_string_to_file(file_path, "testing")
   copy_path = os.path.join(self.get_temp_dir(), "copy_file")
   file_io.copy(file_path, copy_path)
   self.assertTrue(file_io.file_exists(copy_path))
   self.assertEqual(b"testing", file_io.read_file_to_string(file_path))
   file_io.delete_file(file_path)
   file_io.delete_file(copy_path)
开发者ID:AI-MR-Related,项目名称:tensorflow,代码行数:9,代码来源:file_io_test.py

示例9: delete_file

 def delete_file(self, filename):
     """Proxy for tensorflow.python.lib.io.file_io.delete_file function. Mocks
     the function if a real GCS bucket is not available for testing.
     """
     if not self.mock_gcs:
         tf_file_io.delete_file(filename)
     elif filename.startswith(self._gcs_prefix):
         self.local_objects.pop(filename)
     else:
         os.remove(filename)
开发者ID:ZhangXinNan,项目名称:keras,代码行数:10,代码来源:test_utils.py

示例10: testRenameOverwriteFalse

 def testRenameOverwriteFalse(self):
   file_path = os.path.join(self.get_temp_dir(), "temp_file")
   file_io.write_string_to_file(file_path, "testing")
   rename_path = os.path.join(self.get_temp_dir(), "rename_file")
   file_io.write_string_to_file(rename_path, "rename")
   with self.assertRaises(errors.AlreadyExistsError):
     file_io.rename(file_path, rename_path, overwrite=False)
   self.assertTrue(file_io.file_exists(rename_path))
   self.assertTrue(file_io.file_exists(file_path))
   file_io.delete_file(rename_path)
   file_io.delete_file(file_path)
开发者ID:AI-MR-Related,项目名称:tensorflow,代码行数:11,代码来源:file_io_test.py

示例11: testAtomicWriteStringToFileOverwriteFalse

 def testAtomicWriteStringToFileOverwriteFalse(self):
   file_path = os.path.join(self._base_dir, "temp_file")
   file_io.atomic_write_string_to_file(file_path, "old", overwrite=False)
   with self.assertRaises(errors.AlreadyExistsError):
     file_io.atomic_write_string_to_file(file_path, "new", overwrite=False)
   file_contents = file_io.read_file_to_string(file_path)
   self.assertEqual("old", file_contents)
   file_io.delete_file(file_path)
   file_io.atomic_write_string_to_file(file_path, "new", overwrite=False)
   file_contents = file_io.read_file_to_string(file_path)
   self.assertEqual("new", file_contents)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:11,代码来源:file_io_test.py

示例12: test_plot_model_rnn

 def test_plot_model_rnn(self):
   model = keras.Sequential()
   model.add(
       keras.layers.LSTM(
           16, return_sequences=True, input_shape=(2, 3), name='lstm'))
   model.add(keras.layers.TimeDistributed(keras.layers.Dense(5, name='dense')))
   dot_img_file = 'model_2.png'
   try:
     vis_utils.plot_model(model, to_file=dot_img_file, show_shapes=True)
     self.assertTrue(file_io.file_exists(dot_img_file))
     file_io.delete_file(dot_img_file)
   except ImportError:
     pass
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:13,代码来源:vis_utils_test.py

示例13: testGetMatchingFiles

 def testGetMatchingFiles(self):
   dir_path = os.path.join(self.get_temp_dir(), "temp_dir")
   file_io.create_dir(dir_path)
   files = ["file1.txt", "file2.txt", "file3.txt"]
   for name in files:
     file_path = os.path.join(dir_path, name)
     file_io.write_string_to_file(file_path, "testing")
   expected_match = [os.path.join(dir_path, name) for name in files]
   self.assertItemsEqual(file_io.get_matching_files(os.path.join(dir_path,
                                                                 "file*.txt")),
                         expected_match)
   for name in files:
     file_path = os.path.join(dir_path, name)
     file_io.delete_file(file_path)
开发者ID:AI-MR-Related,项目名称:tensorflow,代码行数:14,代码来源:file_io_test.py

示例14: test_plot_model_cnn

 def test_plot_model_cnn(self):
   model = keras.Sequential()
   model.add(
       keras.layers.Conv2D(
           filters=2, kernel_size=(2, 3), input_shape=(3, 5, 5), name='conv'))
   model.add(keras.layers.Flatten(name='flat'))
   model.add(keras.layers.Dense(5, name='dense'))
   dot_img_file = 'model_1.png'
   try:
     vis_utils.plot_model(model, to_file=dot_img_file, show_shapes=True)
     self.assertTrue(file_io.file_exists(dot_img_file))
     file_io.delete_file(dot_img_file)
   except ImportError:
     pass
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:14,代码来源:vis_utils_test.py

示例15: test_assets

  def test_assets(self):
    file1 = self._make_asset("contents 1")
    file2 = self._make_asset("contents 2")

    root = tracking.AutoCheckpointable()
    root.asset1 = tracking.TrackableAsset(file1)
    root.asset2 = tracking.TrackableAsset(file2)

    save_dir = os.path.join(self.get_temp_dir(), "save_dir")
    save.save(root, save_dir, signatures={})

    file_io.delete_file(file1)
    file_io.delete_file(file2)
    load_dir = os.path.join(self.get_temp_dir(), "load_dir")
    file_io.rename(save_dir, load_dir)

    imported = load.load(load_dir)
    with open(imported.asset1.asset_path.numpy(), "r") as f:
      self.assertEquals("contents 1", f.read())
    with open(imported.asset2.asset_path.numpy(), "r") as f:
      self.assertEquals("contents 2", f.read())
开发者ID:gautam1858,项目名称:tensorflow,代码行数:21,代码来源:load_test.py


注:本文中的tensorflow.python.lib.io.file_io.delete_file函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。