(x, y), (x_val, y_val) = datasets.mnist.load_data() x = tf.convert_to_tensor(x, dtype=tf.float32) / 255.
时间: 2023-05-25 22:05:03 浏览: 112
tensor的数学运算.pptx
This code loads the popular MNIST dataset, which contains a large number of hand-written digit images. The first line assigns two tuples of data to the variables `(x, y)` and `(x_val, y_val)`. `x` and `y` contain the training data - `x` being images of hand-written digits and `y` being their corresponding labels (0-9). `x_val` and `y_val` contain the validation data, which is a subset of the training data used to evaluate and tune the model during training.
The second line of code converts the `x` tensor into a TensorFlow tensor with a `float32` data-type and scales its pixel values by dividing them by 255. This is known as normalization, which is a common pre-processing step in machine learning. Normalization ensures that all features have a similar scale and prevents one feature from dominating over the others during training. Scaling by 255 transforms the pixel values from the range 0-255 to the range 0-1.
阅读全文