Из исходного кода тензорного потока sparse_categorical_crossentropy определяется как categorical crossentropy with integer targets
:
def sparse_categorical_crossentropy(target, output, from_logits=False, axis=-1):
"""Categorical crossentropy with integer targets.
Arguments:
target: An integer tensor.
output: A tensor resulting from a softmax
(unless `from_logits` is True, in which
case `output` is expected to be the logits).
from_logits: Boolean, whether `output` is the
result of a softmax, or is a tensor of logits.
axis: Int specifying the channels axis. `axis=-1` corresponds to data
format `channels_last', and `axis=1` corresponds to data format
`channels_first`.
Returns:
Output tensor.
Raises:
ValueError: if `axis` is neither -1 nor one of the axes of `output`.
"""
Из исходного кода тензорного потока категориальная_кросцентропия определяется как Categorical crossentropy between an output tensor and a target tensor
.
def categorical_crossentropy(target, output, from_logits=False, axis=-1):
"""Categorical crossentropy between an output tensor and a target tensor.
Arguments:
target: A tensor of the same shape as `output`.
output: A tensor resulting from a softmax
(unless `from_logits` is True, in which
case `output` is expected to be the logits).
from_logits: Boolean, whether `output` is the
result of a softmax, or is a tensor of logits.
axis: Int specifying the channels axis. `axis=-1` corresponds to data
format `channels_last', and `axis=1` corresponds to data format
`channels_first`.
Returns:
Output tensor.
Raises:
ValueError: if `axis` is neither -1 nor one of the axes of `output`.
"""
Смысл целочисленных целей состоит в том, что метки целей должны быть в форме целочисленного списка, который показывает индекс класса, например:
Для sparse_categorical_crossentropy, Для целей класса 1 и класса 2 в задаче классификации с 5 классами список должен быть [1,2]. По сути, цели должны быть в целочисленной форме для вызова sparse_categorical_crossentropy. Это называется разреженным, так как целевое представление требует гораздо меньше места, чем горячее кодирование. Например: Пакет с b целевыми объектами и k классами должен (b * k) иметь пространство, которое должно быть представлено в одноразовом режиме, тогда как пакет с b целевыми и k классами должен (b) пространство, которое должно быть представлено в целочисленной форме.
Для категории_кросентропии, Для целей класса 1 и класса 2 в задаче классификации 5-класса список должен быть [[0,1,0,0,0], [0,0,1,0,0]], в основном, цели должны быть в одной горячей форме, чтобы вызывать categoryorical_crossentropy.
Представление целей - единственное отличие,результаты должны быть одинаковыми, так как они оба вычисляют категориальную кроссентропию.