【问题标题】:Reading data from bucket in Google ml-engine (tensorflow)从 Google ml-engine (tensorflow) 中的存储桶中读取数据
【发布时间】:2017-09-19 20:21:16
【问题描述】:

我在从 Google 托管的存储桶中读取数据时遇到问题。 我有一个包含大约 1000 个我需要访问的文件的存储桶,保存在(例如) gs://my-bucket/数据

从命令行或其他 Google 的 Python API 客户端使用 gsutil 我可以访问存储桶中的数据,但是在 google-cloud-ml-engine 上默认不支持导入这些 API。

我需要一种方法来访问数据和文件的名称,可以使用默认的 python 库(即 os)或使用 tensorflow。我知道 tensorflow 在某个地方内置了这个功能,我很难找到

理想情况下,我正在寻找一个命令的替代品,例如 os.listdir() 和另一个 open()

train_data = [read_training_data(filename) for filename in os.listdir('gs://my-bucket/data/')]

read_training_data 使用 tensorflow reader 对象的地方

感谢您的帮助! (另外ps我的数据是二进制的)

【问题讨论】:

    标签: python tensorflow google-cloud-ml-engine


    【解决方案1】:

    如果您只是想将数据读入内存,那么this answer 有您需要的详细信息,即使用file_io 模块。

    也就是说,您可能需要考虑使用 TensorFlow 的内置读取机制,因为它们可以提高性能。

    阅读信息可以在here找到。最新最好的(但还不是官方“核心”TensorFlow 的一部分)是 Dataset API(更多信息here)。

    注意事项:

    • 您使用的是 TensorFlow 可以读取的格式吗?可以转成那种格式吗?
    • “喂食”的开销是否高到足以影响训练性能?
    • 训练集是否太大而无法放入内存?

    如果一个或多个问题的答案是肯定的,尤其是后两个问题,请考虑使用阅读器。

    【讨论】:

    • 这里是一个如何写入文件的具体示例(修改它以供读取很简单,但请注意model 参数是必需的):stackoverflow.com/a/43242029/288875
    • 我不确定它是如何应用的。你的意思是包装 gs: 泡菜中的条目吗?什么是泡菜?
    【解决方案2】:

    为了它的价值。我在读取文件时也遇到了问题,特别是来自数据实验室笔记本中谷歌云存储的二进制文件。我设法做到的第一种方法是使用 gs-utils 将文件复制到我的本地文件系统并使用 tensorflow 正常读取文件。这在文件复制完成后在这里演示。

    这是我的设置单元

    import math
    import shutil
    import numpy as np
    import pandas as pd
    import tensorflow as tf
    
    tf.logging.set_verbosity(tf.logging.INFO)
    pd.options.display.max_rows = 10
    pd.options.display.float_format = '{:.1f}'.format
    

    这是一个用于在本地读取文件作为完整性检查的单元格。

    # this works for reading local file
    audio_binary_local = tf.read_file("100852.mp3")
    waveform = tf.contrib.ffmpeg.decode_audio(audio_binary_local, file_format='mp3', 
    samples_per_second=44100, channel_count=2)
    # this will show that it has two channels of data
    with tf.Session() as sess:
        result = sess.run(waveform)
        print (result)
    

    这里是从 gs: 直接读取文件作为二进制文件。

    # this works for remote files in gs:
    gsfilename = 'gs://proj-getting-started/UrbanSound/data/air_conditioner/100852.mp3'
    # python 2
    #audio_binary_remote = tf.gfile.Open(gsfilename).read()
    # python 3
    audio_binary_remote = tf.gfile.Open(gsfilename, 'rb').read()
    waveform = tf.contrib.ffmpeg.decode_audio(audio_binary_remote, file_format='mp3', samples_per_second=44100, channel_count=2)
    # this will show that it has two channels of data
    with tf.Session() as sess:
      result = sess.run(waveform)
      print (result)
    

    【讨论】:

      猜你喜欢
      • 2017-10-08
      • 1970-01-01
      • 2018-09-18
      • 1970-01-01
      • 2019-11-19
      • 2019-07-11
      • 2018-12-23
      • 1970-01-01
      • 2015-10-16
      相关资源
      最近更新 更多