tensorflow / tensorflow/tensorboard

Malfomed Graphdef error.

Open
#7,006 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.2k
Forks
1.7k
Avg merge
4d 22h
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied TensorFlow MNIST script with the listed macOS, Python, TensorBoard, and TensorFlow versions, then inspect the full traceback behind the “Malformed GraphDef” error rather than relying on the screenshot. Trace the failure from the TensorBoard callback used during model.fit; done means the cause and affected behavior are confirmed and the issue has a reproducible resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
devtools, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.