Categories
Misc

I am stuck in defining the variables.

The code runs like this:

import tensorflow as tf import pandas as pd import numpy as np import matplotlib.pyplot as plt %matplotlib inline from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D mnist_data = tf.keras.datasets.mnist (train_images, train_labels), (test_images, test_labels) = mnist_data.load_data() def scale_mnist_data(train_images, test_images): return (train_images / 255, test_images / 255) def train_model(model, scaled_train_images, train_labels): scaled_train_images, scaled_test_images = scale_mnist_data(train_images, test_images) 

THE CODE RUNS PERFECTLY WELL AT THIS POINT,BUT HERE….

scaled_train_images = scaled_train_images[..., np.newaxis] scaled_test_images = scaled_test_images[..., np.newaxis] 

I GET THE ERROR- NameError: name ‘scaled_train_images’ is not
defined

NameError Traceback (most recent call last) <ipython-input-5-7e4c845d2449> in <module> 1 # Add a dummy channel dimension 2 ----> 3 scaled_train_images = scaled_train_images[..., np.newaxis] 4 scaled_test_images = scaled_test_images[..., np.newaxis] 

I wonder if inserting this code ” def train_model(model,
scaled_train_images, train_labels):” is fine. But here again, I
bumped into similar issues like history, frame and some other
variables being not able to be defined.

submitted by /u/edmondoh001

[visit reddit]

[comments]

Leave a Reply

Your email address will not be published.