gpt4 book ai didi

python - 类型错误 : categorical_crossentropy() missing 2 required positional arguments: 'y_true' and 'y_pred'

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

导入库和模型,

from __future__ import print_function
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
import keras.backend as k

batch_size = 128
num_classes = 10
epochs = 12
在写好的代码下面,
#Loss and Optimizer
optimizer = keras.optimizers.Adam()
loss = keras.losses.categorical_crossentropy()
在类型错误下方,我遇到了严重的问题,我无法解决,
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-f3fea941b382> in <module>()
1 #Loss and Optimizer
2 optimizer = keras.optimizers.Adam()
----> 3 loss = keras.losses.categorical_crossentropy()

/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a

TypeError: categorical_crossentropy() missing 2 required positional arguments: 'y_true' and 'y_pred'
需要帮助来解决这个问题,请帮助我。先进谢谢。

最佳答案

这是获取 Categorical Crossentropy 类对象的正确实现。

loss = keras.losses.CategoricalCrossentropy()
keras.losses.categorical_crossentropy这是一个需要 2 个参数的函数。

关于python - 类型错误 : categorical_crossentropy() missing 2 required positional arguments: 'y_true' and 'y_pred' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63779927/

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