Keras資料集匯入問題

2021-10-10 11:35:25 字數 2315 閱讀 4402

keras 中文文件

當採用文件推薦方法即如下**匯入資料集時

from keras.datasets import fashion_mnist

(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()

如本例的fashion-mnist 時尚物品資料集:

import matplotlib.pyplot as plt

def load_data(path, files):

import gzip

import numpy as np

path = [path + each for each in files]

print(path)

with gzip.open(path[0], 'rb') as lbpath:

train_labels = np.frombuffer(lbpath.read(), np.uint8, offset=8)

with gzip.open(path[1], 'rb') as imgpath:

train_images = np.frombuffer(imgpath.read(), np.uint8, offset=16).reshape(len(train_labels), 28, 28)

with gzip.open(path[2], 'rb') as lbpath:

test_labels = np.frombuffer(lbpath.read(), np.uint8, offset=8)

with gzip.open(path[3], 'rb') as imgpath:

test_images = np.frombuffer(imgpath.read(), np.uint8, offset=16).reshape(len(test_labels), 28, 28)

return (train_images, train_labels), (test_images, test_labels)

path = './resource_files/fashion_mnist/'

files = ['train-labels-idx1-ubyte.gz', 'train-images-idx3-ubyte.gz',

't10k-labels-idx1-ubyte.gz', 't10k-images-idx3-ubyte.gz']

(train_images, train_labels), (test_images, test_labels) = load_data(path, files)

# 測試

執行結果

出現:using tensorflow backend.不需要理會

上述兩種方法可對其他資料集同理操作

ubuntu 絕對路徑:例如在目錄/home/local/temp下有乙個檔案filename.txt那麼filename.txt檔案的絕對路徑就是/home/local/tempubuntu 相對路徑:如果你當前路徑是在/home/temp下,那麼filename.txt檔案的相對路徑就是 ./temp注:ubuntu 中根目錄" / ";當前目錄" ./ ";當前目錄的上一級目錄(如果有上一級目錄的話)" ../ ";

參考:常用資料集datasets-keras資料的匯入

ubuntu相對路徑和絕對路徑

Keras匯入Mnist資料集出錯解決方案

exception url fetch failure on none winerror 10060 由於連線方在一段時間後沒有正確答覆或連線的主機沒有反應,連線嘗試失敗。def load data loads the mnist dataset.arguments path path where ...

Keras 資料集介紹

基本的使用情況差不多介紹的差不多了,我也是邊學習邊寫部落格,其中難免有很多理解錯誤的地方或者理解不到位的地方,還請各位博友多多指點。python view plain copy print?keras.datasets.cifar10 keras.datasets.cifar10cifar10資料集...

Keras打亂輸入資料集

實驗資料集 2096 351,第一列為y,餘下350列為特徵x 分割輸入x和輸出y x dataset 1 351 y dataset 0 打亂訓練集 index i for i in range len dataset 下面這種寫法也可以 index np.arange len dataset n...