(
target: Tensor, output: Tensor, fromLogits = false)
| 134 | * a tensor of logits. |
| 135 | */ |
| 136 | export function sparseCategoricalCrossentropy( |
| 137 | target: Tensor, output: Tensor, fromLogits = false): Tensor { |
| 138 | return tidy(() => { |
| 139 | const flatTarget = |
| 140 | tfc.cast(tfc.floor(K.flatten(target)), 'int32') as Tensor1D; |
| 141 | output = tfc.clipByValue(output, epsilon(), 1 - epsilon()); |
| 142 | const outputShape = output.shape; |
| 143 | const oneHotTarget = tfc.reshape( |
| 144 | tfc.oneHot(flatTarget, outputShape[outputShape.length - 1]), |
| 145 | outputShape); |
| 146 | return categoricalCrossentropy(oneHotTarget, output, fromLogits); |
| 147 | }); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * From TensorFlow's implementation in nn_impl.py: |
nothing calls this directly
no test coverage detected
searching dependent graphs…