Skip to content

sparse_categorical_crossentropy ignores feature channel (and axis parameter) when checking tensor dimensions [torch backend]) #21097

Open
@enricoschroeder

Description

@enricoschroeder

I have two tensors which I want to apply sparse_categorical_crossentropy to.

I am using the torch backend, so the tensors are of shape (batch, features, x, y).

However, the function ignores the fact that the feature dimension with torch backend is not the last dimension but the first (non-batch) dimension and thus throws ValueError: Arguments "target" and "output" must have the same shape up until the last dimension: target.shape=torch.Size([16, 1, 224, 224]), output.shape=torch.Size([16, 2, 224, 224]).

This happens even when specifying axis=1 (which by the way is not exposed in keras.losses.SparseCategoricalCrossentropy and thus not an option when using the loss with model.fit).

sparse_categorical_crossentropy should respect the feature channel setting or at least the axis parameter.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions