如何为列表数据和数组标签的tensoflow模型列表制作输入管道

时间:2021-07-11 20:10:56

标签: python numpy tensorflow

我有一个列表格式的训练数据及其数组格式的标签。从这些中组合 tf.data.Dataset 的最佳方法是什么。以下是我的示例代码。

for i in range(100):
  ind = np.random.randint(0,10)
  x = np.random.randint(0, 19, (ind, ))
  lst.append(x)

y = np.random.randint(0,100, (100,))


data = tf.data.Dataset.from_generator(lambda : (lst, y), output_types=( tf.int32, tf.int32), output_shapes = ((None, ), ( )))

for i in data.padded_batch(10):
  print(i)

但我不断收到此错误

generator` 生成了与预期结构不匹配的元素。预期的结构是 (tf.int32, tf.int32),但产生的元素是 [array([], dtype=int64), array([ 0, 14, 6, 2, 5, 13]), array([ 0, 11, 8, 11]), 数组([ 6, 9, 0, 17, 12, 10]), 数组([12, 3, 8]), 数组([11, 9]), 数组([ 3, 11, 17, 1]), array([], dtype=int64), array([ 0, 12, 3]), array([ 6, 3, 0, 13, 2, 6, 12, 17, 12]), 数组([ 2, 9, 1, 17, 4, 17]), 数组([15, 17, 4, 12, 2, 6, 10, 15, 7]), 数组([16, 5] , 2, 11]), 数组([11, 11, 10, 1, 11, 9, 9]), 数组([10, 5, 9]), 数组([3, 7, 1, 4, 6, 6]), 数组([], dtype=int64), 数组([15, 6, 6, 3, 0, 16, 1, 7, 10]), 数组([ 9, 15, 16, 1, 6, 8, 16, 13, 4]), 数组([13, 0]), 数组([2]), 数组([ 0, 14, 11, 9, 13, 3, 14, 15]), 数组([ ], dtype=int64), array([14, 9, 3, 10, 2]), array([1]), array([], dtype=int64), array([10, 12, 4, 14, 3]), 数组([2]), 数组([], dtype=int64), 数组([ 7, 17, 3, 6, 3, 8, 13, 18, 6]), 数组([ 5, 1 , 1, 13, 3]), 数组([10, 12]), 数组([ 1, 6, 13, 0, 7]), 数组([1 8, 15, 0, 6]), 数组([], dtype=int64), 数组([11, 3, 16, 13, 11, 17, 7, 0, 0]), 数组([11, 6] ), 数组([4, 2]), 数组([17, 5, 12, 4, 2]), 数组([10, 2, 10, 8]), 数组([ 6, 16, 16, 8, 12, 2, 16, 14, 8]), 数组([11]), 数组([16]), 数组([11, 8, 3, 4, 8, 6, 18, 5, 16]), 数组([11, 16, 9, 4, 1, 11, 16]), 数组([ 8, 3, 11, 17, 0]), 数组([16, 8, 9, 14, 3... 回溯(最近一次通话):

0 个答案:

没有答案