Note that the function assumes that predictions and labels are already
unit-normalized.
Args
labels
Tensor whose shape matches 'predictions'
predictions
An arbitrary matrix.
axis
The dimension along which the cosine distance is computed.
weights
Optional Tensor whose rank is either 0, or the same rank as
labels, and must be broadcastable to labels (i.e., all dimensions must
be either 1, or the same as the corresponding losses dimension).
scope
The scope for the operations performed in computing the loss.
loss_collection
collection to which this loss will be added.
reduction
Type of reduction to apply to loss.
dim
The old (deprecated) name for axis.
Returns
Weighted loss float Tensor. If reduction is NONE, this has the same
shape as labels; otherwise, it is scalar.
Raises
ValueError
If predictions shape doesn't match labels shape, or
axis, labels, predictions or weights is None.
eager compatibility
The loss_collection argument is ignored when executing eagerly. Consider
holding on to the return value or collecting losses via a tf.keras.Model.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.compat.v1.losses.cosine_distance\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/losses/losses_impl.py#L270-L324) |\n\nAdds a cosine-distance loss to the training procedure. (deprecated arguments) \n\n tf.compat.v1.losses.cosine_distance(\n labels,\n predictions,\n axis=None,\n weights=1.0,\n scope=None,\n loss_collection=ops.GraphKeys.LOSSES,\n reduction=Reduction.SUM_BY_NONZERO_WEIGHTS,\n dim=None\n )\n\n| **Deprecated:** SOME ARGUMENTS ARE DEPRECATED: `(dim)`. They will be removed in a future version. Instructions for updating: dim is deprecated, use axis instead\n\nNote that the function assumes that `predictions` and `labels` are already\nunit-normalized.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `labels` | `Tensor` whose shape matches 'predictions' |\n| `predictions` | An arbitrary matrix. |\n| `axis` | The dimension along which the cosine distance is computed. |\n| `weights` | Optional `Tensor` whose rank is either 0, or the same rank as `labels`, and must be broadcastable to `labels` (i.e., all dimensions must be either `1`, or the same as the corresponding `losses` dimension). |\n| `scope` | The scope for the operations performed in computing the loss. |\n| `loss_collection` | collection to which this loss will be added. |\n| `reduction` | Type of reduction to apply to loss. |\n| `dim` | The old (deprecated) name for `axis`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| Weighted loss float `Tensor`. If `reduction` is `NONE`, this has the same shape as `labels`; otherwise, it is scalar. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-----------------------------------------------------------------------------------------------------------------|\n| `ValueError` | If `predictions` shape doesn't match `labels` shape, or `axis`, `labels`, `predictions` or `weights` is `None`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\neager compatibility\n-------------------\n\n\u003cbr /\u003e\n\nThe `loss_collection` argument is ignored when executing eagerly. Consider\nholding on to the return value or collecting losses via a [`tf.keras.Model`](../../../../tf/keras/Model).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]