- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Tensorflow2 中,我可以使用类 tf.keras.losses.CategoricalCrossentropy
( defined here ) 或函数 categorical_crossentropy
( defined here ) 计算标签和预测之间的交叉熵损失:
第一个代码是:
loss_object = tf.keras.losses.SparseCategoricalCrossentropy()
# ...
@tf.function
def train_step(samples, labels):
with tf.GradientTape() as tape:
predictions = model(samples)
loss = loss_object(labels, predictions)
#...
@tf.function
def forward(features, training=False):
predictions = model.call(...)
loss = tf.losses.categorical_crossentropy(
y_true=features['label'],
y_pred=predictions)
return loss, predictions
最佳答案
来自 Keras documentation :
Note that all losses are available both via a class handle and via a function handle. The class handles enable you to pass configuration arguments to the constructor (e.g. loss_fn = CategoricalCrossentropy(from_logits=True)), and they perform reduction by default when used in a standalone way (see details below).
关于tensorflow - 类别 CategoricalCrossentropy 与函数 categorical_crossentropy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59741879/
在 Tensorflow2 中,我可以使用类 tf.keras.losses.CategoricalCrossentropy ( defined here ) 或函数 categorical_cros
我正在将 keras 模型移植到 torch并且我无法复制 keras/tensorflow 的确切行为 'categorical_crossentropy'在 softmax 层之后。我对这个问题有
我正在用 unet 做图像语义分割工作,如果我像这样为最后一层设置 Softmax Activation: ... conv9 = Conv2D(n_classes, (3,3), padding =
我是一名优秀的程序员,十分优秀!