I’m using tensorflow to test the accuracy of a dataset. You can find my full code as well as the dataset here
I’m still learning Machine Learning and there are a lot of things that are giving me a headache. For example why in this scenario when I compile model using “sparse_categorical_crossentropy”,
# Since the labels are not one-hot encoded, we use the Sparse Categorical Crossentropy Loss
model.compile(loss="sparse_categorical_crossentropy",
optimizer="sgd",
metrics=["accuracy"])
there is an error:
INVALID_ARGUMENT: logits and labels must have the same first dimension, got logits shape [32,2] and labels shape [64]
However, after spending hours looking at the codes and fixing each line hopelessly. Finally it works! By changing loss=”categorical_crossentropy”
# Since the labels are not one-hot encoded, we use the Sparse Categorical Crossentropy Loss
model.compile(loss="categorical_crossentropy",
optimizer="sgd",
metrics=["accuracy"])
I could really use an explanation right now and I’ll be much in appreciation!
Anthony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.