日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

TensorFlow——本地加载fashion-mnist数据集

發布時間:2024/10/5 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TensorFlow——本地加载fashion-mnist数据集 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

基本概念

Fashion MNIST:Fashion MNIST 旨在臨時替代經典?MNIST?數據集,后者常被用作計算機視覺機器學習程序的“Hello, World”。MNIST 數據集包含手寫數字(0、1、2 等)的圖像,其格式與您將使用的衣物圖像的格式相同。

問題描述

在動手寫深度學習的TensorFlow實現版本中,需要用到數據集Fashion MNIST,如果直接用TensorFlow導入數據集:

from tensorflow.keras.datasets import fashion_mnist (x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()

就會報錯,下載數據集時會顯示服務器連接超時,可能因為服務器在國內被墻了。

解決方案

1、下載

https://github.com/zalandoresearch/fashion-mnist?

?

下載完成后解壓放在./data/fashion/文件夾下

?

2、導入?

接下導入數據集:

import mnist_readerx_train, y_train = mnist_reader.load_mnist('data/fashion', kind='train') x_test, y_test = mnist_reader.load_mnist('data/fashion', kind='t10k')

注意:

mnist_reader是GitHub上該項目里面的一個文件,不要以為是某個庫

?

代碼:?

def load_mnist(path, kind='train'):import osimport gzipimport numpy as np"""Load MNIST data from `path`"""labels_path = os.path.join(path,'%s-labels-idx1-ubyte.gz'% kind)images_path = os.path.join(path,'%s-images-idx3-ubyte.gz'% kind)with gzip.open(labels_path, 'rb') as lbpath:labels = np.frombuffer(lbpath.read(), dtype=np.uint8,offset=8)with gzip.open(images_path, 'rb') as imgpath:images = np.frombuffer(imgpath.read(), dtype=np.uint8,offset=16).reshape(len(labels), 784)return images, labels

?3、測試

注意:

mnist_reader.pyfashion_mnist.load_data的結果并不相同,會影響后續操作

修改版本

def load_mnist(path, kind='train'):import osimport gzipimport numpy as np"""Load MNIST data from `path`"""labels_path = os.path.join(path,'%s-labels-idx1-ubyte.gz'% kind)images_path = os.path.join(path,'%s-images-idx3-ubyte.gz'% kind)with gzip.open(labels_path, 'rb') as lbpath:labels = np.frombuffer(lbpath.read(), dtype=np.uint8,offset=8)with gzip.open(images_path, 'rb') as imgpath:images = np.frombuffer(imgpath.read(), dtype=np.uint8,offset=16).reshape(len(labels), 28, 28) # 關鍵點return images, labelsdef load_data(path):train_images, train_labels = load_mnist(path, kind='train')test_images, test_labels = load_mnist(path, kind='t10k')return (train_images, train_labels), (test_images, test_labels)def load_data():return load_data('data/fashion')

參考文章

使用matplotlib.pyplot.imshow() 顯示圖像時出現“TypeError: Invalid dimensions for image data”的問題

如何加載mnist和fashion-mnist數據集

Fashion MNIST的下載與導入

Tensorflow學習第1課——從本地加載MNIST以及FashionMNIST數據

TensorFlow——[基本圖像分類]fashion-mnist及mnist_reader.py運行錯誤[TypeError: Invalid dimensions for image data]

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的TensorFlow——本地加载fashion-mnist数据集的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。