编写本地导入FASHION MNIST文件工具
文件下载请使用FASHION MNIST
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9dhOrPC0-1588650999474)(https://github.com/zalandoresearch/fashion-mnist/raw/master/doc/img/embedding.gif)]
import gzip
import numpy as np
from tensorflow.python.keras.utils import get_file
def load_data():
base = 'file://./data/'
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))
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)
使用工具进行数据加载
# TensorFlow and tf.keras
import matplotlib.pyplot as plt
# Helper libraries
from tensorflow import keras
import fashion as fashion
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion.load_data()
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
plt.figure()
plt.imshow(train_images[0])
plt.colorbar()
plt.grid(False)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-19bx6Hw1-1588650999482)(https://tensorflow.google.cn/tutorials/keras/basic_classification_files/output_25_0.png)]
项目推荐
DC3是基于Spring Cloud的开源可分布式物联网(IOT)平台,用于快速开发、部署物联设备接入项目,是一整套物联系统解决方案。