I am confused about the appropriate loss function to use as i am generating my dataset using image_dataset_from_directory.
Data Generator
Train
train_ds = tf.keras.utils.image_dataset_from_directory(
'/content/dataset/train',
validation_split=0.05,
subset="training",
seed=123,
image_size=(IMAGE_SIZE, IMAGE_SIZE),
batch_size=BATCH_SIZE)
Validation
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
'/content/dataset/val', image_size=(IMAGE_SIZE, IMAGE_SIZE), batch_size=BATCH_SIZE
)
Model
rn50v2_model = Sequential()
pretrained_model = tf.keras.applications.ResNet50V2(
include_top=False,
weights="imagenet",
input_shape=(IMAGE_SIZE, IMAGE_SIZE, 3),
pooling='avg',
classes = 2
)
print(pretrained_model.summary())
rn50v2_model.add(pretrained_model)
rn50v2_model.add(Flatten())
rn50v2_model.add(Dense(512, activation='relu'))
rn50v2_model.add(Dense(2, activation='softmax'))
#print(rn50v2_model.summary())
rn50v2_model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
when i tested my model, i got my result one hot encoded like below:
array([[0.24823777, 0.7517622 ]], dtype=float32)
I would prefer to use categorical_crossentropy but pls explain this behaviour i cant seem to find information on the official documentation