![](/img/trans.png)
[英]changing numpy array from type int64 to type int32 corrupts the data
[英]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.