python - “无法将张量添加到批次:元素数量不匹配”,同时遍历数据集
问题描述
我在此处的 Colab 笔记本中包含了代码(直到迭代部分)。我把我的数据喂给了我train_dataset
这样的人。
batch_size = 30
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = (
train_dataset.map(encode_single_sample, num_parallel_calls=tf.data.experimental.AUTOTUNE)
.batch(batch_size) #this one gives the error
.prefetch(buffer_size=tf.data.experimental.AUTOTUNE))
我得到一个InvalidArgumentError: Cannot add tensor to the batch: number of elements does not match。当我遍历数据集时,形状是:[张量]:[78],[批次]:[34] :
for batch in train_dataset.take(1): #error while iterating
上面给出了.batch(batch_size)
错误。我注意到每次我再次运行代码时错误消息中的 [tensor] 和 [batch] 数字都会发生变化。当我更改batch_size
为 1 时代码运行,但我也希望能够更改它。
如果有人可以调试这部分,将不胜感激
编辑 1:我在这里关注 Keras 的 OCR 教程,他们的代码运行良好。
解决方案
推荐阅读
- fortran - 将 abaqus2018 与 vs2016 和 ps2012 链接时发生错误
- javascript - 如何选择位于页面上 iframe 中的 html 元素
- php - form_checkbox 在 PHP 中不起作用(Codeigniter)
- php - 带有 nginx、mysql、php7 和 slimphp 的 Dockerfile
- reactjs - 如何将图标和文本传递给 React 中的按钮?
- python - 将带撇号的单词计数为一个单词但返回两个单词(python)
- python - 将所有 csv 文件从 s3 转换为 parquet
- c++ - 在 std::set 中查找邻居
- dspace - 在 Ubuntu 18.04 上构建 DSpace 6.3 Mirage2 主题时出错
- java - Thymeleaf - 表单中的多个提交按钮