![](/img/trans.png)
[英]Prediction from a Deployed SCIKITLEARN model at Google Cloud ML-Engine
[英]Reading data from bucket in Google ml-engine (tensorflow)
我在从Google托管的存储桶中读取数据时遇到问题。 我有一个包含我需要访问的约1000个文件的存储桶,保存在(例如)gs:// my-bucket / data
使用命令行或其他Google Python客户端中的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使用张量流读取器对象
谢谢你的帮助! (另外ps我的数据是二进制的)
物有所值。 我也在阅读文件时遇到了问题,特别是在datalab笔记本中的谷歌云存储中的二进制文件。 我设法做到的第一种方法是使用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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.