I am running the code mentioned at link of the code
Here is the code:
import numpy as np
from keras.models import Model
from keras.layers import Input, Dense, Dropout
#from keras.utils import to_categorical # not working in google colab
from tensorflow.keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from keras.callbacks import EarlyStopping
import tensorflow as tf
# Create an input array of 50,000 samples of 20 random numbers each
x = np.random.randint(0, 100, size=(50000, 20))
print(x)
# And a one-hot encoded target denoting the index of the maximum of the inputs
y = to_categorical(np.argmax(x, axis=1), num_classes=20)
print(y)
# Split into training and testing datasets
x_train, x_test, y_train, y_test = train_test_split(x, y)
# Build a network, probaly needlessly complicated since it needs a lot of dropout to
# perform even reasonably well.
i = Input(shape=(20, ))
a = Dense(1024, activation='relu')(i)
b = Dense(512, activation='relu')(a)
ba = Dropout(0.3)(b)
c = Dense(256, activation='relu')(ba)
d = Dense(128, activation='relu')(c)
o = Dense(20, activation='softmax')(d)
model = Model(inputs=i, outputs=o)
es = EarlyStopping(monitor='val_loss', patience=3)
model.compile(optimizer='adam', loss='categorical_crossentropy')
#model.fit= tf.convert_to_tesnsor(model.fit)
model.fit(x_train, y_train, epochs=8, batch_size=8, validation_data=[x_test, y_test], callbacks=[es])
print(np.where(np.argmax(model.predict(x_test), axis=1) == np.argmax(y_test, axis=1), 1, 0).mean())
Error:
ValueError: in user code:
/usr/local/lib/python3.7/dist-packages/keras/engine/training.py:1298 test_function *
return step_function(self, iterator)
/usr/local/lib/python3.7/dist-packages/keras/engine/training.py:1282 run_step *
outputs = model.test_step(data)
/usr/local/lib/python3.7/dist-packages/keras/engine/training.py:1241 test_step *
y_pred = self(x, training=False)
/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py:989 __call__ *
input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
/usr/local/lib/python3.7/dist-packages/keras/engine/input_spec.py:197 assert_input_compatibility *
raise ValueError('Layer ' + layer_name + ' expects ' +
ValueError: Layer model_11 expects 1 input(s), but it received 2 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, 20) dtype=int64>, <tf.Tensor 'IteratorGetNext:1' shape=(None, 20) dtype=float32>]
Kindly help in solving this issue, I am not able to run it on Goolge Colab. Here is the Google Colab link: google colab link