繁体   English   中英

InvalidArgumentError:数据 t InvalidArgumentError:组件 0 处的数据类型不匹配:预期 int32 但得到 int64 - Tensorflow

[英]InvalidArgumentError: Data t InvalidArgumentError: Data type mismatch at component 0: expected int32 but got int64 - Tensorflow

我正在尝试在课程之后用 Tensorflow 训练 model,但我收到了上述错误。

这是我的代码的相关部分:

element_spec = ({'input_ids': tf.TensorSpec(shape=(16, 512), dtype=tf.int32, name=None),
  'attention_masks': tf.TensorSpec(shape=(16, 512), dtype=tf.int32, name=None)},
 tf.TensorSpec(shape=(16, 5), dtype=tf.float64, name=None))

train_ds = tf.data.experimental.load('train', element_spec)
val_ds = tf.data.experimental.load('val', element_spec)

#in order to keep the history of our runs
history = model.fit(
    train_ds,
    validation_data = val_ds,
    epochs = 3
)

我尝试在我的笔记本电脑上运行它(没有特定的 GPU)并且它需要永远,所以我决定在 google colab 上运行同样的东西,但我得到了这个我觉得奇怪的错误:

Epoch 1/3

---------------------------------------------------------------------------

InvalidArgumentError                      Traceback (most recent call last)

<ipython-input-146-9b8dacb137ae> in <module>()
      3     train_ds,
      4     validation_data = val_ds,
----> 5     epochs = 3
      6 )

1 frames

/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     57     ctx.ensure_initialized()
     58     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 59                                         inputs, attrs, num_outputs)
     60   except core._NotOkStatusException as e:
     61     if name is not None:

InvalidArgumentError:  Data type mismatch at component 0: expected int32 but got int64.
     [[node IteratorGetNext
 (defined at /usr/local/lib/python3.7/dist-packages/keras/engine/training.py:866)
]] [Op:__inference_train_function_16829]

Errors may have originated from an input operation.
Input Source operations connected to node IteratorGetNext:
In[0] iterator (defined at /usr/local/lib/python3.7/dist-packages/keras/engine/training.py:1216)

问题只是以某种方式将 epoch = 3 从 int64 更改为 int32?

好的,我想通了,我在元素规范中定义了“dtype=tf.int32”,只是将它们更改为“dtype=tf.int64”,它现在可以工作了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM