python - 如何为列表数据和数组标签的tensoflow模型列表制作输入管道
问题描述
我有一个列表格式的训练数据及其数组格式的标签。从这些中组合 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]), 数组([], dtype=int64), 数组([ 0, 12, 3]), 数组([ 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), 数组([14, 9, 3, 10, 2]), 数组([1]),
解决方案
推荐阅读
- machine-learning - 了解卷积层形状
- asp.net-core - 如何在 .net core 的列表中重定向另一个视图页面
- java - 我怎么知道选择了另一个类的 JButton?
- python - 在 Ubuntu 18.04 上将 python 包安装到 salome_meca 的 python 发行版
- css - React router dom links are not scrolling to the correct section of the page (not scrolling at all)
- android - Xamarin.essentials FilePicker 将选定的外部文件复制到缓存文件夹
- git - Git 相同的代码库但有变化?遗产?
- python - 我可以将这三个循环变为一个循环或做其他事情来使这段代码更快吗?
- python - 如何将 .last() 与 groupby 中的其他聚合一起使用以按日期顺序排序
- python - Transform content to String in Python 3 using BeautifulSoup