-
大小: 29.46MB文件类型: .zip金币: 1下载: 0 次发布日期: 2023-07-11
- 语言: 其他
- 标签: python tensorflow keras
资源简介
服装识别项目数据集与代码
代码片段和文件信息
import tensorflow as tf
from tensorflow import keras
import osgzip
import numpy as np
import matplotlib.pyplot as plt
fashion_mnist=keras.datasets.fashion_mnist
path=‘./data‘
files=[‘train-labels-idx1-ubyte.gz‘
‘train-images-idx3-ubyte.gz‘
‘t10k-labels-idx1-ubyte.gz‘
‘t10k-images-idx3-ubyte.gz‘]
def load_data(data_folderfiles):
paths=[]
for fname in files:
paths.append(os.path.join(data_folderfname))
##frombuffer将data以流的形式读入转化成ndarray对象
#第一参数为stream第二参数为返回值的数据类型,第三参数指定从stream的第几位开始读入
with gzip.open(paths[0]‘rb‘) as lbpath:
y_train = np.frombuffer(lbpath.read()np.uint8offset=8)
with gzip.open(paths[1]‘rb‘) as imgpath:
x_train = np.frombuffer(imgpath.read()np.uint8offset=16).reshape(len(y_train)2828)
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.uint8offset=16).reshape(len(y_test)2828)
return (x_trainy_train)(x_testy_test)
(train_imagestrain_labels)(test_imagestest_labels)=load_data(pathfiles)
class_names = [‘T-shirt/top‘‘Trouser‘‘Pullover‘‘Dress‘‘Coat‘‘Sandal‘‘Shirt‘‘Sneaker‘‘Shirt‘‘Sneaker‘‘Bag‘‘Ankle boot‘]
train_images=train_images/255.0
test_images=test_images/255.0
plt.figure(figsize=(1010))
for i in range(25):
plt.subplot(55i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(train_images[i]cmap=plt.cm.binary)
plt.xlabel(class_names[train_labels[i]])
# plt.show()
#建模
model=keras.Sequential([
keras.layers.Flatten(input_shape=(2828))
keras.layers.Dense(128activation=‘relu‘)
keras.layers.Dense(10activation=‘softmax‘)])
#编译训练模型
model.compile(optimizer=‘adam‘
loss=‘sparse_categorical_crossentropy‘
metrics=[‘accuracy‘])
model.fit(train_imagestrain_labelsepochs=10)
#评估模型及预测
test_losstest_acc = model.evaluate(test_imagestest_labelsverbose=2)
print(‘\nTest accuracy:‘test_acc)
predictions = model.predict(test_images)
print(predictions[1])
print(np.argmax(predictions[1]))
print(test_labels[1])
def plot_image(ipredictions_arraytrue_labelimg):
predictions_arraytrue_labelimg=predictions_arraytrue_label[i]img[i]
plt.grid(False)
plt.xticks([])
plt.yticks([])
plt.imshow(imgcmap=plt.cm.binary)
predicted_label=np.argmax(predictions_array)
if predicted_label == true_label:
color = ‘blue‘
else:
color=‘red‘
plt.xlabel(‘{}{:2.0f}%({})‘.format(class_names[predicted_label]
100*np.max(predictions_array)
class_names[true_label])
color=color)
def plot_value_array(ipredictions_arraytrue_label):
predictions_arraytrue_label=predictions_arraytrue_label[i]
plt.grid(False)
plt.xt
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 0 2020-01-15 09:17 yi_shibie\__init__.py
目录 0 2020-01-15 09:22 yi_shibie\data\
文件 4422102 2020-01-15 09:20 yi_shibie\data\t10k-images-idx3-ubyte.gz
文件 5148 2020-01-15 09:20 yi_shibie\data\t10k-labels-idx1-ubyte.gz
文件 26421880 2020-01-15 09:21 yi_shibie\data\train-images-idx3-ubyte.gz
文件 29515 2020-01-15 09:20 yi_shibie\data\train-labels-idx1-ubyte.gz
文件 3994 2020-01-15 14:20 yi_shibie\yi_shibie.py
相关资源
- 手写数字识别程序,模型和测试图片
- github上tensorflow-master源码
- tensorflow-1.2.1-cp35-cp35m-linux_x86_64.whl
- tensorflow-master.zip 2018.10.29最新版
- Hands-On Machine Learning with Scikit-Learn an
- Hands-On Machine Learning with Scikit-Learn an
- 数据挖掘概念与技术 第三版(中文版
- MNIST手写字体识别结果模板3万轮训练
- tensorflow-1.3.0
- 精通Scrapy网络爬虫完整版
- 深度学习:智能时代的核心驱动力量
- Keras英译中seq2seq简洁
- Windows系统下tensorflow版本的YOLO v3
- 使用tensorflow实现CNN-RNN-GAN代码
- 《最全Pycharm教程 - 精编版》收集自山
- Visual Studio 2015 VCRedist package(64and32)
- Hands-On Machine Learning with Scikit-Learn Ke
- mnist数据集162914
- TensorFlow For Machine Intelligence(非扫描版
- 左手MongoDB,右手Redis:从入门到商业
- 基于RNN的Tensorflow实现文本分类任务的
- Django for Beginners_ Learn web - William S. V
- 最全Pycharm教程 - 精编版.pdf
- 深度学习资料+官方文档
- 深度学习/图像识别/TensorFlow
- Advanced Deep Learning with Keras
- Machine Learning for OpenCV 原版PDF by Beye
- imdb.npz数据集
- tensorflow实战+实战Google深度学习框架
- 基于深度学习的目标检测程序
评论
共有 条评论