|
楼主 |
发表于 2021-6-24 21:16:39
|
显示全部楼层
方便呀,关键的我都放了,那我再放一点。
下面是我的代码:
- # TensorFlow and tf.keras
- import tensorflow as tf
- import sys
- from tensorflow import keras
- # Helper libraries
- import numpy as np
- import matplotlib.pyplot as plt
- #print(sys.path)
- print(tf.__version__)
- fashion_mnist = keras.datasets.fashion_mnist
- (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
复制代码
下面是
- """Fashion-MNIST dataset."""
- import gzip
- import os
- import numpy as np
- from keras.utils.data_utils import get_file
- from tensorflow.python.util.tf_export import keras_export
- @keras_export('keras.datasets.fashion_mnist.load_data')
- def load_data():
- print('aaaaaaaaaaaaaaaaaaaaaaa')
- dirname = os.path.join('datasets', 'fashion-mnist')
- base = 'https://storage.googleapis.com/tensorflow/tf-keras-datasets/'
- files = [
- 'train-labels-idx1-ubyte.gz', 'train-images-idx3-ubyte.gz',
- 't10k-labels-idx1-ubyte.gz', 't10k-images-idx3-ubyte.gz'
- ]
- paths = []
- for fname in files:
- paths.append(get_file(fname, origin=base + fname, cache_subdir=dirname))
- with gzip.open(paths[0], 'rb') as lbpath:
-
- y_train = np.frombuffer(lbpath.read(), np.uint8, offset=8)
- with gzip.open(paths[1], 'rb') as imgpath:
- x_train = np.frombuffer(
- imgpath.read(), np.uint8, offset=16).reshape(len(y_train), 28, 28)
- with gzip.open(paths[2], 'rb') as lbpath:
- y_test = np.frombuffer(lbpath.read(), np.uint8, offset=8)
- with gzip.open(paths[3], 'rb') as imgpath:
- x_test = np.frombuffer(
- imgpath.read(), np.uint8, offset=16).reshape(len(y_test), 28, 28)
- return (x_train, y_train), (x_test, y_test)
复制代码 |
|