I am building a neural network and at this point, I wish to know what my network looks like. But the model summary function is raising an error
code:
print(model.summary())
Error:
raise ValueError(f"Cannot convert '{shape}' to a shape.")
ValueError: Cannot convert '784' to a shape.
After writing the code below, I expected a some summary of my neural network structure, instead I get an error?
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers, models
from tensorflow.keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train.reshape(-1, 28*28).astype("float32") / 255.0
x_test = x_test.reshape(-1, 28*28).astype("float32") / 255.0
# sequential model for one input to one output
model = keras.Sequential(
[
keras.Input(shape=(28*28)),
layers.Dense(512, activation='relu'),
layers.Dense(256, activation='relu'),
layers.Dense(10),
]
)
print(model.summary()),
import sys
sys.exit()
model.compile(
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
optimizer=keras.optimizers.Adam(learning_rate=0.001),
metrics=["accuracy"],
)
model.fit(x_train, y_train, batch_size=32, epochs=5, verbose=2)
model.evaluate(x_test, y_test, batch_size=32, verbose=2)