fork download
  1. import tensorflow astf
  2. from tensorflow import keras
  3. # Load the MNIST dataset
  4. (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
  5. # Normalize the input data
  6. x_train = x_train / 255.0
  7. x_test = x_test / 255.0
  8. # Define the model architecture
  9. model = keras.Sequential([
  10. keras.layers.Flatten(input_shape=(28, 28)),
  11. keras.layers.Dense(128, activation='relu'),
  12. keras.layers.Dropout(0.2),
  13. keras.layers.Dense(10)])
  14.  
  15. lO MoARcPSD| 1682789
  16.  
  17. Dept. of CSE., CNCET Page 40
  18. # Compile the model
  19. model.compile(optimizer='adam',
  20. loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
  21. metrics=['accuracy'])
  22. # Train the model
  23. model.fit(x_train, y_train, epochs=10, validation_data=(x_test, y_test))
  24. # Evaluate the model
  25. test_loss, test_acc = model.evaluate(x_test, y_test, verbose=2)
  26. print('Test accuracy:', test_acc)
Success #stdin #stdout #stderr 0.33s 39176KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "import tensorflow"
Execution halted