Apr-12-2022, 03:03 AM
I am new to Python and machine learning. Trying to learn by working on tested examples. Tried the character recognition program (from Chollet) using MNIST data set, later tried to change the input data set (numbers instead of character images).
I cannot run it with this error:
I cannot run it with this error:
Error: train_images=((1,1,0,0,1)
TypeError: 'tuple' object is not callable
How can I correct this? Maybe it is more complicated than this in changing the input data set. Thanks.# from keras.datasets import mnist # (train_images, train_labels), (test_images, test_labels) = mnist.load_data() train_images=((1,1,0,0,1) (0,0,1,1,1) (1,1,0,1,1)) train_labels=[[10,10,0,0,10] [0,0,10,10,10] [10,10,0,10,10]] test_images=[[0,1,0,1,1] [0,0,1,0,1] [1,1,1,1,1]] test_labels=[[0,10,0,10,10] [0,0,10,0,10] [10,10,10,10,10]] from keras import models from keras import layers network = models.Sequential() network.add(layers.Dense(512, activation='relu', input_shape=(28 * 28,))) network.add(layers.Dense(10, activation='softmax')) network.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy']) train_images = train_images.reshape((60000, 28 * 28)) train_images = train_images.astype('float32') / 255 test_images = test_images.reshape((10000, 28 * 28)) test_images = test_images.astype('float32') / 255 #from keras.utils import to_categorical from tensorflow.keras.utils import to_categorical train_labels = to_categorical(train_labels) test_labels = to_categorical(test_labels) network.fit(train_images, train_labels, epochs=5, batch_size=128)