gpt4 book ai didi

python - 发生此错误。 "TypeError: Expected int64, got 1e-07 of type ' float' instead."。我该怎么办?

转载 作者:行者123 更新时间:2023-12-04 17:37:07 25 4
gpt4 key购买 nike

我有一个问题。出现类型错误。但我无法解决它。起初,我认为这是一个类型问题。但我注意到问题并不简单。原因是我技术差。但我找不到解决方案。所以,请帮助我。

我更改了我的 tensorflow 和 keras 版本。

keras : 2.2.4
tensorflow : 1.13.1

代码:

x = Dozat(21)(x) # custom Lambda layer

print('x : ', x, '\n\n\n')

network = Model([w, p], x)
q = network.layers[8].output
print(q)

network.summary()

network.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

总结:

__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
words (InputLayer) (None, 21, 2) 0
__________________________________________________________________________________________________
pos (InputLayer) (None, 21, 2) 0
__________________________________________________________________________________________________
embedding_1 (Embedding) (None, 21, 2, 128) 14541184 words[0][0]
__________________________________________________________________________________________________
embedding_2 (Embedding) (None, 21, 2, 128) 9344 pos[0][0]
__________________________________________________________________________________________________
reshape_1 (Reshape) (None, 21, 256) 0 embedding_1[0][0]
__________________________________________________________________________________________________
reshape_2 (Reshape) (None, 21, 256) 0 embedding_2[0][0]
__________________________________________________________________________________________________
concatenate_1 (Concatenate) (None, 21, 512) 0 reshape_1[0][0]
reshape_2[0][0]
__________________________________________________________________________________________________
bidirectional_1 (Bidirectional) (None, 21, 256) 656384 concatenate_1[0][0]
__________________________________________________________________________________________________
dozat_1 (Dozat) (1, 21) 0 bidirectional_1[0][0]
==================================================================================================
Total params: 15,206,912
Trainable params: 15,206,912
Non-trainable params: 0
__________________________________________________________________________________________________

错误:

Traceback (most recent call last):
File "C:\Users\jkdsp\OneDrive\Desktop\github\git_from_the_hell\Keras_parsing\keras_11_biLSTM_prac_one_example_2.py", line 105, in <module>
network.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\training.py", line 342, in compile
sample_weight, mask)
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\training_utils.py", line 414, in weighted
score_array = fn(y_true, y_pred)
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\losses.py", line 91, in binary_crossentropy
return K.mean(K.binary_crossentropy(y_true, y_pred), axis=-1)
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 3374, in binary_crossentropy
_epsilon = _to_tensor(epsilon(), output.dtype.base_dtype)
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 308, in _to_tensor
return tf.convert_to_tensor(x, dtype=dtype)
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1039, in convert_to_tensor
return convert_to_tensor_v2(value, dtype, preferred_dtype, name)
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1097, in convert_to_tensor_v2
as_ref=False)
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1175, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\constant_op.py", line 304, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\constant_op.py", line 245, in constant
allow_broadcast=True)
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\constant_op.py", line 283, in _constant_impl
allow_broadcast=allow_broadcast))
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 466, in make_tensor_proto
_AssertCompatible(values, dtype)
File "C:\Users\jkdsp\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 371, in _AssertCompatible
(dtype.name, repr(mismatch), type(mismatch).__name__))
TypeError: Expected int64, got 1e-07 of type 'float' instead.

最佳答案

尝试将数据类型从 int 更改为 float。也许这会解决问题。

可以找到类似的讨论here .

关于python - 发生此错误。 "TypeError: Expected int64, got 1e-07 of type ' float' instead."。我该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56212951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com