I want to do a simple test of the SparseCategoricalCrossentropy function, to see what exactly it does to an output. For that I use the output of the last layer of a MobileNetV2.
import keras.backend as K
full_model = tf.keras.applications.MobileNetV2(
input_shape=(224,224,3),
alpha=1.0,
include_top=True,
weights="imagenet",
input_tensor=None,
pooling=None,
classes=1000,
classifier_activation="softmax",)
func = K.function(full_model.layers[1].input, full_model.layers[155].output)
conv_output = func([processed_image])
y_pred = np.single(conv_output)
y_true = np.zeros(1000).reshape(1,1000)
y_true[0][282] = 1
scce = tf.keras.losses.SparseCategoricalCrossentropy()
scce(y_true, y_pred).numpy()
processed_image is a 1x224x224x3 array created previously.
I'm getting the error ValueError: Shape mismatch: The shape of labels (received (1000,)) should equal the shape of logits except for the last dimension (received (1, 1000)).
I tried reshaping the arrays to match the dimensions the error mentioned, but it doesn't seem to work. What shapes does it accept?