iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 25
0
自我挑戰組

Tensorflow學習日記系列 第 25

tensorflow學習日記Day24 Cifar-10模型建立

  • 分享至 

  • xImage
  •  

#載入cifar10,預處理資料
from keras.datasets import cifar10
import numpy as np
np.random.seed(10)
(x_img_train,y_label_train),(x_img_test,y_label_test)=cifar10.load_data()
print("train data:",'images:',x_img_train.shape,"labels",y_label_train.shape)
print("test data:",'images:',x_img_test.shape,"labels",y_label_test.shape)
x_img_train_normalize=x_img_train.astype('float32')/255.0
x_img_test_normalize=x_img_test.astype('float32')/255.0
from keras.utils import np_utils
y_label_train_OneHot=np_utils.to_categorical(y_label_train)
y_label_test_OneHot=np_utils.to_categorical(y_label_test)
#建立模型
from keras.models import Sequential
from keras.layers import Dense,Dropout,Activation,Flatten
from keras.layers import Conv2D,MaxPooling2D,ZeroPadding2D
model=Sequential()
#convolution
model.add(Conv2D(filters=32,kernel_size=(3,3),input_shape=(32,32,3),activation='relu',padding='same'))
#dropout
model.add(Dropout(rate=0.25))
#pooling
model.add(MaxPooling2D(pool_size=(2,2)))
#convolution
model.add(Conv2D(filters=64,kernel_size=(3,3),activation='relu',padding='same
model.add(Dropout(0.25))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(filters=64,kernel_size=(3,3),activation='relu',padding='same'))
model.add(Dropout(0.25))
model.add(MaxPooling2D(pool_size=(2,2)))
#平坦層
model.add(Flatten())
model.add(Dropout(rate=0.25))
#隱藏層
model.add(Dense(1024,activation='relu'))
model.add(Dropout(rate=0.25))
#輸出層
model.add(Dense(10,activation='softmax'))
print(model.summary())

模型摘要
Model: "sequential_1"


Layer (type) Output Shape Param #

conv2d_1 (Conv2D) (None, 32, 32, 32) 896


dropout_1 (Dropout) (None, 32, 32, 32) 0


max_pooling2d_1 (MaxPooling2 (None, 16, 16, 32) 0


conv2d_2 (Conv2D) (None, 16, 16, 64) 18496


dropout_2 (Dropout) (None, 16, 16, 64) 0


max_pooling2d_2 (MaxPooling2 (None, 8, 8, 64) 0


conv2d_3 (Conv2D) (None, 8, 8, 64) 36928


dropout_3 (Dropout) (None, 8, 8, 64) 0


max_pooling2d_3 (MaxPooling2 (None, 4, 4, 64) 0


flatten_1 (Flatten) (None, 1024) 0


dropout_4 (Dropout) (None, 1024) 0


dense_1 (Dense) (None, 1024) 1049600


dropout_5 (Dropout) (None, 1024) 0


dense_2 (Dense) (None, 10) 10250

Total params: 1,116,170
Trainable params: 1,116,170
Non-trainable params: 0


None


上一篇
tensorflow學習日記Day24 Cifar-10影像辨識資料集
下一篇
Tensorflow學習日記Day26 Cifar-10 CNN 訓練
系列文
Tensorflow學習日記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言