python - 开始使用我自己的数据集启动 google-cloud-ml

标签 python tensorflow google-cloud-ml

我成功执行了所有步骤 of the online tutorial for google cloud ml .

但是由于本教程中使用的数据集已经是 TFRecord,所以我不太了解如何将我的 numpy 数据集转换为 TFRecord。

然后,我尝试使用 this a little bit modified code compared to the official convert_to_records.py 创建我的 TFRecord .我的理解是我们只能将原始变量转换为 TFRecord,这就是为什么使用将浮点列表转换为字节的技巧。 然后我必须在某个地方将我的字符串转换回 float 列表。因此,我尝试使用第 97 行或第 98 行 in my modified script model.py 来执行此任务。 .

不幸的是,这些尝试都没有奏效。我总是收到以下错误消息:

ValueError: rank of shape must be at least 2 not: 1

这是因为我的变量 features 的形状是 (batch_size,) 而不是 (batch_size, IMAGE_PIXELS)。但我不明白为什么。

我是不是尝试以错误的方式启动 google-cloud-ml,还是需要调整更多参数?

最佳答案

该错误表明预期的秩为 2(矩阵),但该值实际上为秩 1(向量)。我怀疑这是因为 np.tostring() 返回单个字符串而不是字符串列表。

我认为这有点切题,因为我认为您的 float 到字符串和字符串到 float 的转换不一致。您可以使用 numpy 的内置 tostring() 方法将 float 转换为字符串。返回数据的字节表示:即

import numpy as np
x = np.array([1.0, 2.0])
print x.tostring()

返回

�?@

而不是

['1.0', '2.0']

后者是 tf.string_to_number 所期望的。

您可以使浮点到字符串和字符串到浮点的转换保持一致,但我认为更好的解决方案是只将数据表示为 float 。例如:

def _int64_feature(value):
  return tf.train.Feature(int64_list=tf.train.Int64List(value=value))

def _float_feature(value):
  return tf.train.Feature(float_list=tf.train.FloatList(value=value))

e = tf.train.Example(features=tf.train.Features(feature={
          'labels': _int64_feature([10]),
          'features': _float_feature([100.0, 200, ....])}))

feature_map = {
      'labels': tf.FixedLenFeature(
          shape=[1], dtype=tf.int64, default_value=[-1]),
      'features': tf.FixedLenFeature(
          shape=[NUM_PIXELS], dtype=tf.float32),
}
result = tf.parse_example([e.SerializeToString()], features=feature_map)

A Feature proto允许将 float32 存储在 float_list 中。如果您使用的是 float64,则只需将 float 转换为字节。您的数据是 float32,所以这是不必要的。

关于python - 开始使用我自己的数据集启动 google-cloud-ml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40217891/

相关文章:

多 GPU 下的 Tensorflow 处理性能

Python ml 引擎预测 : How can I make a googleapiclient. discovery.build 持久?

tensorflow - 使用 Google ML 引擎和 Google Storage 存储大量图像进行训练的最佳实践

python - Django (1.9) makemigrations 在 bool 字段上没有得到 Blank=True

python - 如何将这个字符串拆分成它的单个字符?

python - Django 分页对象与 Postgresql QuerySets 有问题

java - 如何获取 tensorflow 服务中的模型状态

python - 由于判别器输出为负,Tensorflow GAN 判别器损失 NaN

machine-learning - GPU 在参数服务器上进行数据并行训练是否高效?

python - Convert_obj_two.py 语法错误