1. 程式人生 > >使用keras下載cifar 10

使用keras下載cifar 10

from keras.utils import to_categorical
from keras.layers import *
from keras.models import Sequential
from keras.datasets import cifar10

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

# 轉變資料格式
y_train = y_train.reshape(y_train.shape[0])
y_test = y_test.reshape(y_test.shape[0])

# 對資料做歸一化處理
x_train = x_train.astype("float32")
x_test = x_test.astype("float32")
x_train /= 255
x_test /= 255
# 將標籤轉變成適合網路輸入的值, 想當於one_hot
y_train = to_categorical(y_train, 10)
y_test = to_categorical(y_test, 10)