Open Nileshmk opened 3 years ago
as I mentioned in the title so as the model is using softmax you need to convert the y_train and y_test to one hot key.
def dense_to_one_hot(labels_dense, num_classes=10): """Convert class labels from scalars to one-hot vectors.""" num_labels = labels_dense.shape[0] index_offset = numpy.arange(num_labels) * num_classes labels_one_hot = numpy.zeros((num_labels, num_classes)) labels_one_hot.flat[index_offset + labels_dense.ravel()] = 1 return labels_one_hot
I don't know that previously the dataset came with one hot key and now it's coming with simple number 0-9 but while I was running the code i got into trouble of this and got valueError. By using the function the error got solved. Plz update the code if this error is occuring to you as well
Thank you for your support, I will check this out and update the code accordingly.
as I mentioned in the title so as the model is using softmax you need to convert the y_train and y_test to one hot key.
def dense_to_one_hot(labels_dense, num_classes=10): """Convert class labels from scalars to one-hot vectors.""" num_labels = labels_dense.shape[0] index_offset = numpy.arange(num_labels) * num_classes labels_one_hot = numpy.zeros((num_labels, num_classes)) labels_one_hot.flat[index_offset + labels_dense.ravel()] = 1 return labels_one_hot
I don't know that previously the dataset came with one hot key and now it's coming with simple number 0-9 but while I was running the code i got into trouble of this and got valueError. By using the function the error got solved. Plz update the code if this error is occuring to you as well
Hey where do you put this code? I am running into the same valueError.
Edit - If someone is still wondering, you need to do this before defining the model
def dense_to_one_hot(labels_dense, num_classes=10):
"""Convert class labels from scalars to one-hot vectors."""
num_labels = labels_dense.shape[0]
index_offset = numpy.arange(num_labels) * num_classes
labels_one_hot = numpy.zeros((num_labels, num_classes))
labels_one_hot.flat[index_offset + labels_dense.ravel()] = 1
return labels_one_hot
y_train = dense_to_one_hot(y_train)
y_test = dense_to_one_hot(y_test)
as I mentioned in the title so as the model is using softmax you need to convert the y_train and y_test to one hot key.
I don't know that previously the dataset came with one hot key and now it's coming with simple number 0-9 but while I was running the code i got into trouble of this and got valueError. By using the function the error got solved. Plz update the code if this error is occuring to you as well