简体   繁体   English

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

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

I am trying to train a model with Tensorflow following a course and I get the mentioned error.我正在尝试在课程之后用 Tensorflow 训练 model,但我收到了上述错误。

here is the relevant part of my code:这是我的代码的相关部分:

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
)

I tried running it on my laptop(no specific GPUs) and it is taking forever, so I decided to run the same thing on google colab but I get this error which I find odd:我尝试在我的笔记本电脑上运行它(没有特定的 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)

is the problem just somehow changing epoch = 3 from int64 to int32?问题只是以某种方式将 epoch = 3 从 int64 更改为 int32?

ok I figured it out, I had defined " dtype=tf.int32" in element spec, just changed those to " dtype=tf.int64" and it is working now好的,我想通了,我在元素规范中定义了“dtype=tf.int32”,只是将它们更改为“dtype=tf.int64”,它现在可以工作了

暂无
暂无

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

相关问题 将 numpy 数组从 int64 类型更改为 int32 类型会损坏数据 - changing numpy array from type int64 to type int32 corrupts the data Tensorflow:InvalidArgumentError:您必须使用dtype int32为占位符张量&#39;yy&#39;提供值 - Tensorflow: InvalidArgumentError: You must feed a value for placeholder tensor 'yy' with dtype int32 如何解决TensorFlow中的&#39;BiasGrad requires tensor size &lt;= int32 max&#39; InvalidArgumentError? - How to solve the 'BiasGrad requires tensor size <= int32 max' InvalidArgumentError in TensorFlow? tensorflow.python.framework.errors.InvalidArgumentError:记录0中的字段0不是有效的int32:1 0 - tensorflow.python.framework.errors.InvalidArgumentError: Field 0 in record 0 is not a valid int32: 1 0 Tensorflow 错误“TypeError:传递给 'Pack' Op 的 'values' 的列表中的张量具有不完全匹配的类型 [int32, int64, int32, int32, int32]。” - Tensorflow Error “TypeError: Tensors in list passed to 'values' of 'Pack' Op have types [int32, int64, int32, int32, int32] that don't all match.” 计算的 Numpy 数组问题,int 类型,int32 与 int64 - Numpy Array Problem with Calculation, int type, int32 vs int64 Tensorflow Slim:TypeError:预期为 int32,得到包含“_Message”类型张量的列表 - Tensorflow Slim: TypeError: Expected int32, got list containing Tensors of type '_Message' instead attr&#39;T&#39;的数据类型float32不在允许值列表中:int32,int64 - DataType float32 for attr 'T' not in list of allowed values: int32, int64 类型错误:无法根据 seaborn 中的“安全”规则将数组数据从 dtype(&#39;int64&#39;) 转换为 dtype(&#39;int32&#39;) - TypeError: Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe' in seaborn Seaborn TypeError:无法根据规则“安全”将数组数据从 dtype('int64') 转换为 dtype('int32') - Seaborn TypeError: Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM