Skip to content

Malfomed Graphdef error. #7006

Open
Open
@GOGOYAO

Description

@GOGOYAO

I create a MLP model as follows but get error.

Image
import tensorflow as tf
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten
from tensorflow.keras.callbacks import TensorBoard
import datetime

(x_train, y_train), (x_test, y_test) = mnist.load_data()

x_train, x_test = x_train / 255.0, x_test / 255.0

model = Sequential([
    Flatten(input_shape=(28, 28)),      
    Dense(128, activation='relu'),      
    Dense(64, activation='relu'),       
    Dense(10, activation='softmax')     
])

model.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)

log_dir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = TensorBoard(
    log_dir=log_dir,
    histogram_freq=1,       
    write_graph=True,       
    write_images=True,      
    update_freq='epoch'     
)

try:
    model.fit(
        x_train, y_train,
        epochs=5,
        validation_data=(x_test, y_test),
        callbacks=[tensorboard_callback],
        verbose=1
    )
except Exception as e:
    print(f"error when train: {str(e)}")
    raise

try:
    model.save('mnist_mlp_model.keras')
except Exception as e:
    print(f"error when save: {str(e)}")
    raise

print(model.summary())

My environment info is as follows.
macos 15.5 (24F74)
python 3.9.6
tensorboard 2.19.0
tensorboard-data-server 0.7.2
tensorflow 2.19.0
tensorflow-io-gcs-filesystem 0.37.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions