使用存储在Google Cloud上的训练TFRecords

13
我的目标是在我本地运行Tensorflow训练应用程序时,使用存储在Google Cloud存储上的训练数据(格式:tfrecords)。 (为什么是本地?:在将其转换为云ML的培训包之前,我正在测试)。 根据此线程,我不需要做任何事情,因为底层的Tensorflow API应该能够读取gs://(网址) 然而,情况并非如此,我看到的错误格式为: 2017年6月6日15:38:55.589068:I tensorflow/core/platform/cloud/retrying_utils.cc:77] 操作失败,将在1.38118秒后自动重试(10次尝试中的第1次),原因是:不可用:执行HTTP请求时出错(HTTP响应代码为0,错误代码为6,错误消息为“无法解析主机'metadata'”)。 2017年6月6日15:38:56.976396:I tensorflow/core/platform/cloud/retrying_utils.cc:77] 操作失败,将在1.94469秒后自动重试(10次尝试中的第2次),原因是:不可用:执行HTTP请求时出错(HTTP响应代码为0,错误代码为6,错误消息为“无法解析主机'metadata'”)。 2017年6月6日15:38:58.925964:I tensorflow/core/platform/cloud/retrying_utils.cc:77] 操作失败,将在2.76491秒后自动重试(10次尝试中的第3次),原因是:不可用:执行HTTP请求时出错(HTTP响应代码为0,错误代码为6,错误消息为“无法解析主机'metadata'”)。 我无法确定从哪里开始调试此错误。 以下是重现问题并显示我正在使用的tensorflow API的代码片段。
def _preprocess_features(features):
        """Function that returns preprocessed images"""

def _parse_single_example_from_tfrecord(value):
    features = (
        tf.parse_single_example(value,
                                features={'image_raw': tf.FixedLenFeature([], tf.string),
                                          'label': tf.FixedLenFeature([model_config.LABEL_SIZE], tf.int64)
                                          })
        )
    return features

def _read_and_decode_tfrecords(filename_queue):
    reader = tf.TFRecordReader()
    # Point it at the filename_queue
    _, value = reader.read(filename_queue)
    features = _parse_single_example_from_tfrecord(value)
    # decode the binary string image data
    image, label = _preprocess_features(features)
    return image, label

def test_tfread(filelist):
  train_filename_queue = (
    tf.train.string_input_producer(filelist,
                                   num_epochs=None,
                                   shuffle=True))
  image, label = (
    _read_and_decode_tfrecords(train_filename_queue))
  return image

images= test_tfread(["gs://test-bucket/t.tfrecords"])
sess = tf.Session(config=tf.ConfigProto(
                allow_soft_placement=True,
                log_device_placement=True))
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
try:
  for step in range(model_config.MAX_STEPS):
      _ = sess.run([images])
finally:
  # When done, ask the threads to stop.
  coord.request_stop()
# Finally, wait for them to join (i.e. cleanly shut down)
coord.join(threads)
1个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
27

请尝试执行以下命令:

gcloud auth application-default login


太棒了!这个可行 - 谢谢!你能告诉我如何在我的训练包部署到Google Cloud ML时以编程方式实现这一点吗? - 7hacker
在CloudML上运行时,这是不必要的。如果您遇到问题,请报告这些问题。(但是,您始终可以使用subprocess.check_call(["gcloud", "auth", "application-default', "login"]) - rhaertel80

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,