【问题标题】:TensorFlow Dataset Generator With Mixed Datatypes具有混合数据类型的 TensorFlow 数据集生成器
【发布时间】:2018-09-28 01:46:18
【问题描述】:

我正在使用 TensorFlow Datasets API (https://www.tensorflow.org/guide/datasets),特别是,我将它与建议使用生成器函数的 TensorFlow Estimators API (https://www.tensorflow.org/guide/datasets_for_estimators) 一起使用。

我在编写生成具有不同输出类型(例如,int、float 和 string 的混合)的特征的生成器函数时遇到问题。我已经弄清楚如何指定与生成器不同的特征+标签类型。 ..但仅当所有标签类型都相同时。

但是...假设您要发出多种特征类型(例如,在典型的 import85 TensorFlow 演示的情况下,您会将汽车品牌和模型作为字符串发出(稍后会被归类为下游) 以及作为 float32 的 Highway-MPG 和作为 int 的门数。如何在数据集上指定 from_generator 调用各种特征类型?

数据集 = tf.data.Dataset。 from_generator(generator=self._generator, output_types=(tf.float32, tf.int32), output_shapes=(tf.TensorShape([None]),tf.TensorShape([1])))

我已经尝试过显而易见的使用方法 output_types=((tf.float32, tf.float32, tf.string, tf.string), tf.int32) 没有运气。任何帮助将不胜感激。

【问题讨论】:

    标签: tensorflow tensorflow-datasets tensorflow-estimator


    【解决方案1】:

    来自official documentation

    tf.Tensor 不可能有一种以上的数据类型。但是,可以将任意数据结构序列化为字符串并将其存储在 tf.Tensors 中。

    因此,您可能需要将它们存储为字符串,然后使用 decode_raw 等函数评估它们。

    【讨论】:

      猜你喜欢
      • 2013-04-08
      • 1970-01-01
      • 2020-07-31
      • 2018-11-14
      • 1970-01-01
      • 2012-09-04
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      相关资源
      最近更新 更多