ValueError on first run
See original GitHub issueHey there,
I was following the README code snippet and ran into a bit of trouble. My code is word-for-word is being run on MNIST.
import tensorflow as tf
from tensorflow.keras.datasets import mnist
from tensorflow.keras.layers import Dense, Input
from tensorflow.keras.optimizers import Adam
from kerastuner.tuners import RandomSearch
(xtrain, ytrain), (xtest, ytest) = mnist.load_data()
xtrain = xtrain.reshape([-1, 784, 1]) / 255
xtest = xtest.reshape([-1, 784, 1]) / 255
ytrain = tf.keras.utils.to_categorical(ytrain, 10)
ytest = tf.keras.utils.to_categorical(ytest, 10)
print (xtrain.shape, ytrain.shape)
def build(hp):
model = tf.keras.models.Sequential()
model.add(Dense(units=hp.Int('units', min_value=32, max_value=512, step=32), activation="relu"))
model.add(Dense(10, activation="softmax"))
model.compile(loss="sparse_categorical_crossentropy", optimizer=Adam(hp.Choice("learning_rate", values=[1e-2, 1e-3, 1e-4])), metrics=["accuracy"])
return model
tuner = RandomSearch(build, objective='val_accuracy', max_trials=5, executions_per_trial=3, directory="bin", project_name="tuner_test")
tuner.search_space_summary()
tuner.search(xtrain, ytrain, epochs=10, validation_data=(xtest, ytest))
model = tuner.get_best_models(num_models=5)
tuner.results_summary()
I keep getting this error, causing my build to fail.
ValueError: Shape mismatch: The shape of labels (received (32, 10)) should equal the shape of logits except for the last dimension (received (32, 784, 10)).
Any help would be greatly appreciated 😃
Cheers!
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
ValueError: need more than 1 value to unpack - Stack Overflow
I have tried running the program through the Windows command prompt, to no avail. I have also run the program by typing: "python...
Read more >Python ValueError Exception Handling Examples - DigitalOcean
Python ValueError is raised when a function receives an argument of the correct type but an inappropriate value. Also, the situation should not ......
Read more >compressai.entropy_models.entropy_models - CompressAI
Run update() first") if len(self._cdf_length.size()) != 1: raise ValueError(f"Invalid offsets size {self._cdf_length.size()}") def compress(self, inputs, ...
Read more >Better performance with tf.function | TensorFlow Core
You may encounter ValueError: tf.function only supports singleton tf.Variables created on the first call. when using more than one Keras optimizer with a...
Read more >Beginning Python 3 By Doing #9 - ValueError, try, except, finally
Docker Tutorial for Beginners - A Full DevOps Course on How to Run Applications in Containers. freeCodeCamp.org. freeCodeCamp.org.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
just found the issue of mismatch change loss=“sparse_categorical_crossentropy” to loss=“categorical_crossentropy” will work. since the label had called to_categorica()
I’ll go take a look. Appreciate your help!