My keras version is 2.2.4 and tf is 1.15.3.
Code to create the model:
import numpy as np
import pandas as pd
%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow import keras
keras.__version__
tf.__version__
fashion_mnist = keras.datasets.fashion_mnist
(X_train_full, y_train_full), (X_test, y_test) = fashion_mnist.load_data()
plt.imshow(X_train_full[10])
class_names = ["T-shirt/top", "Trouser", "Pullover", "Dress", "Coat",
"Sandal", "Shirt", "Sneaker", "Bag", "Ankle boot"]
class_names[y_train_full[10]]
X_train_full[10]
X_train_n = X_train_full / 255.
X_test_n = X_test / 255.
X_valid, X_train = X_train_n[:5000], X_train_n[5000:]
y_valid, y_train = y_train_full[:5000], y_train_full[5000:]
X_test = X_test_n
X_valid[0]
np.random.seed(42)
tf.random.set_random_seed(42)
model = keras.models.Sequential()
model.add(keras.layers.Flatten(input_shape=[28, 28]))
model.add(keras.layers.Dense(300, activation="relu"))
model.add(keras.layers.Dense(100, activation="relu"))
model.add(keras.layers.Dense(10, activation="softmax"))
model.summary()
Output summary:
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
flatten (Flatten) (None, 784) 0
_________________________________________________________________
dense (Dense) (None, 300) 235500
_________________________________________________________________
dense_1 (Dense) (None, 100) 30100
_________________________________________________________________
dense_2 (Dense) (None, 10) 1010
=================================================================
Total params: 266,610
Trainable params: 266,610
Non-trainable params: 0
_________________________________________________________________
Code that is generating the error:
pip install pydot
pip install graphviz
import pydot
from keras.utils.vis_utils import plot_model
plot_model(model, to_file= 'model.png' , show_shapes=True)
Error:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_14952\4050438567.py in <module>
----> 1 plot_model(model, to_file= 'model.png' , show_shapes=True)
NameError: name 'model' is not defined
weights, biases = model.layers[1].get_weights()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_14952\2052231455.py in <module>
----> 1 model.layers[1].get_weights()
NameError: name 'model' is not defined
I expected to proceed and get the weights and biases of the model. The cell however shows the error that: name 'model' is not defined
like this: