【问题标题】:Failed to rename ; Access denied Tensorflow重命名失败;访问被拒绝 TensorFlow
【发布时间】:2020-06-08 09:03:35
【问题描述】:

我正在尝试使用 mnist dataset 在 jupyter 中使用 tensorflow 2.0 构建机器学习代码。数据集是从 tensorflow-datasets 获取的,但在数据集的初始下载期间,下载后显示错误,即无法重命名数据集,然后中止整个过程。

这是用于加载数据集的行

mnist_dataset, mnist_info = tfds.load(name='mnist', with_info=True, as_supervised=True)

这是错误

Downloading and preparing dataset mnist (11.06 MiB) to C:\Users\Main\tensorflow_datasets\mnist\1.0.0...
Dl Completed...:
0/0 [00:00<?, ? url/s]
Dl Size...:
0/0 [00:00<?, ? MiB/s]
Extraction completed...:
0/0 [00:00<?, ? file/s]






WARNING:tensorflow:From C:\Python38\Anaconda3\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\file_format_adapter.py:209: tf_record_iterator (from tensorflow.python.lib.io.tf_record) is deprecated and will be removed in a future version.
Instructions for updating:
Use eager execution and: 
`tf.data.TFRecordDataset(path)`
WARNING:tensorflow:From C:\Python38\Anaconda3\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\file_format_adapter.py:209: tf_record_iterator (from tensorflow.python.lib.io.tf_record) is deprecated and will be removed in a future version.
Instructions for updating:
Use eager execution and: 
`tf.data.TFRecordDataset(path)`
---------------------------------------------------------------------------
UnknownError                              Traceback (most recent call last)
<ipython-input-2-6bf2983938fb> in <module>
----> 1 mnist_dataset, mnist_info = tfds.load(name='mnist', with_info=True, as_supervised=True)

C:\Python38\Anaconda3\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\api_utils.py in disallow_positional_args_dec(fn, instance, args, kwargs)
     50     _check_no_positional(fn, args, ismethod, allowed=allowed)
     51     _check_required(fn, kwargs)
---> 52     return fn(*args, **kwargs)
     53 
     54   return disallow_positional_args_dec(wrapped)  # pylint: disable=no-value-for-parameter

C:\Python38\Anaconda3\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\registered.py in load(name, split, data_dir, batch_size, in_memory, shuffle_files, download, as_supervised, decoders, with_info, builder_kwargs, download_and_prepare_kwargs, as_dataset_kwargs, try_gcs)
    298   if download:
    299     download_and_prepare_kwargs = download_and_prepare_kwargs or {}
--> 300     dbuilder.download_and_prepare(**download_and_prepare_kwargs)
    301 
    302   if as_dataset_kwargs is None:

C:\Python38\Anaconda3\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\api_utils.py in disallow_positional_args_dec(fn, instance, args, kwargs)
     50     _check_no_positional(fn, args, ismethod, allowed=allowed)
     51     _check_required(fn, kwargs)
---> 52     return fn(*args, **kwargs)
     53 
     54   return disallow_positional_args_dec(wrapped)  # pylint: disable=no-value-for-parameter

C:\Python38\Anaconda3\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\dataset_builder.py in download_and_prepare(self, download_dir, download_config)
    305         self.info.size_in_bytes = dl_manager.downloaded_size
    306         # Write DatasetInfo to disk, even if we haven't computed the statistics.
--> 307         self.info.write_to_directory(self._data_dir)
    308     self._log_download_done()
    309 

C:\Python38\Anaconda3\envs\py3-TF2.0\lib\contextlib.py in __exit__(self, type, value, traceback)
    117         if type is None:
    118             try:
--> 119                 next(self.gen)
    120             except StopIteration:
    121                 return False

C:\Python38\Anaconda3\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\file_format_adapter.py in incomplete_dir(dirname)
    198   try:
    199     yield tmp_dir
--> 200     tf.io.gfile.rename(tmp_dir, dirname)
    201   finally:
    202     if tf.io.gfile.exists(tmp_dir):

C:\Python38\Anaconda3\envs\py3-TF2.0\lib\site-packages\tensorflow\python\lib\io\file_io.py in rename_v2(src, dst, overwrite)
    506   """
    507   _pywrap_file_io.RenameFile(
--> 508       compat.as_bytes(src), compat.as_bytes(dst), overwrite)
    509 
    510 

UnknownError: Failed to rename: C:\Users\Main\tensorflow_datasets\mnist\1.0.0.incompleteI3ZU6X to: C:\Users\Main\tensorflow_datasets\mnist\1.0.0 : Access is denied.
; Input/output error

【问题讨论】:

  • 可能是因为 anaconda 的限制。 stackoverflow.com/questions/60309013/…
  • 在首选 conda 环境中运行 pip install -U tensorflow-datasets 后问题解决。但是,如果有人可以指出该行中的 -U 是否代表更新会更有帮助。
  • -U 表示将“所有指定的软件包升级到最新的可用版本。我也遇到了同样的问题,但pip install -U tensorflow-datasets 没有解决我的问题。

标签: python tensorflow jupyter tensorflow2.0 tensorflow-datasets


【解决方案1】:

已打开一个 GitHub 问题以解决它。

在该线程中,提出了一个临时解决方案,尽管它意味着手动修改一些 TensorFlow 函数。我不确定它是否会对模型性能产生影响,但如果您想尝试一下,我会发布下面的链接:

Windows - tensorflow.python.framework.errors_impl.UnknownError: Failed to rename: #41380

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题。只需将data_dir 属性更改为data_dir=r"D:\data" 并确保它不应该在C: drive 中。你可以走了。

    【讨论】:

      【解决方案3】:

      我在本地运行时遇到了同样的错误。我认为错误是由于下载和存储数据的文件夹的读写权限造成的。

      我通过将 tfds.load() 函数中的 data_dir 参数指定到不需要特殊用户权限的文件夹来修复它。

      这是我的函数调用:

      mnist_dataset, mnist_info = tfds.load(name='mnist', data_dir='C:/', with_info=True, as_supervised=True)
      

      这将为根目录中的数据创建一个文件夹,而不是默认文件夹。

      【讨论】:

        【解决方案4】:

        更改磁盘或数据目录对我不起作用 (Win10)。

        但是,指定数据集的版本是可行的。

        示例: tfds.load(name='celeb_a:2.0.0',... )

        【讨论】:

          【解决方案5】:

          Tensorflow/models/MODEL_NAME /

          对我来说,解决方案是事先确保那里没有“检查点”,出于显而易见的原因,那里有一个检查点文件夹,但我使用的脚本(其他人)他们称之为 ckpt。 0 在不同的位置,所以我基本上将它移到了那个新位置,并从 *above 路径中删除了检查点文件夹。我是一个缺乏经验的编码员,尤其是 python 新手,但我目前正在成功运行训练脚本。

          【讨论】:

            【解决方案6】:

            我尝试让 Tensorflow API 2.0 正常工作,但遇到了与上述相同的错误。 我将模型文件夹指定为与检查点文件夹相同。要修复上面提到的错误,我必须将 Model 和 Checkpoint 文件夹分开。

            【讨论】:

              猜你喜欢
              • 2021-04-04
              • 2020-11-24
              • 2017-05-17
              • 1970-01-01
              • 2023-03-14
              • 1970-01-01
              • 1970-01-01
              • 2023-04-06
              • 2012-09-27
              相关资源
              最近更新 更多