【问题标题】:Colab: cache dataset on TPUColab:在 TPU 上缓存数据集
【发布时间】:2018-12-08 12:06:58
【问题描述】:

我想设置类似于the following colab notebook 的东西。我有一个 100MB 的单 TFRecord,我想使用 TPU 对其进行训练。

我的训练输入函数如下:

def train_input_fn(batch_size=1024):
  dataset = tf.data.TFRecordDataset(TRAIN_RECORD)
  dataset = dataset.cache()
  dataset = dataset.repeat()
  dataset = dataset.shuffle(100)
  dataset = dataset.map(parse_fn)
  dataset = dataset.batch(batch_size, drop_remainder=True)
  return dataset

据我了解,当使用 TPU 时,数据集不能驻留在机器硬盘上,这就是我添加dataset.cache() 的原因。但我还是得到了

UnimplementedError(回溯见上文):文件系统方案“[本地]”未实现(文件:“train.tfrecord”)

【问题讨论】:

    标签: tensorflow tensorflow-datasets tpu


    【解决方案1】:

    TPU 需要谷歌云存储。不支持本地存储。

    https://cloud.google.com/tpu/docs/troubleshooting#cannot_use_local_filesystem

    【讨论】:

      【解决方案2】:

      看起来错误出现在这一行 dataset = tf.data.TFRecordDataset(TRAIN_RECORD) 上,它适用于本地 fs。我认为您应该像在笔记本中那样在训练功能之外加载数据。

      【讨论】:

      • 但是加载TFRecord不是只能在训练函数内部完成吗?我尝试将前两行移出函数并得到local variable 'dataset' referenced before assignment
      • 只需为此使用不同的变量,例如data = tf.data.TFRecordDataset(TRAIN_RECORD) 和函数 dataset = data.cache() ...
      • 我仍然收到File system scheme '[local]' not implemented...。当cache()ing 在输入函数之外时也是如此。
      • 你能分享完整的堆栈跟踪或笔记本吗?
      • 附注我认为的问题是tf 推迟了这些命令的实际执行,直到您运行整个管道。您应该在运行 tf 管道之前加载数据。
      猜你喜欢
      • 1970-01-01
      • 2021-05-17
      • 2021-07-28
      • 2020-10-19
      • 2019-12-06
      • 2021-10-05
      • 2020-04-04
      • 2019-07-29
      • 2021-02-17
      相关资源
      最近更新 更多