Keras_tutorial-NeuralNetwork

import numpy as np
from keras import layers
from keras.layers import Input, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D
from keras.layers import AveragePooling2D, MaxPooling2D, Dropout, GlobalMaxPooling2D, GlobalAveragePooling2D
from keras.models import Model
from keras.preprocessing import image
from keras.utils import layer_utils
from keras.utils.data_utils import get_file
from keras.applications.imagenet_utils import preprocess_input
import pydotplus
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot
from keras.utils import plot_model
from kt_utils import *

import keras.backend as K
K.set_image_data_format('channels_last')
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow

%matplotlib inline
X_train_orig, Y_train_orig, X_test_orig, Y_test_orig, classes = load_dataset()

# Normalize image vectors
X_train = X_train_orig/255.
X_test = X_test_orig/255.

# Reshape
Y_train = Y_train_orig.T
Y_test = Y_test_orig.T

print ("number of training examples = " + str(X_train.shape[0]))
print ("number of test examples = " + str(X_test.shape[0]))
print ("X_train shape: " + str(X_train.shape))
print ("Y_train shape: " + str(Y_train.shape))
print ("X_test shape: " + str(X_test.shape))
print ("Y_test shape: " + str(Y_test.shape))

結果:
number of training examples = 600
number of test examples = 150
X_train shape: (600, 64, 64, 3)
Y_train shape: (600, 1)
X_test shape: (150, 64, 64, 3)
Y_test shape: (150, 1)
def HappyModel(input_shape):
    X_input = Input(input_shape)
    X =ZeroPadding2D((3,3))(X_input)
    X = Conv2D(32,(7,7), strides=(1, 1),name='conv0')(X)
    X = BatchNormalization(axis=3,name='bn0')(X)
    X = Activation('relu')(X)
    X = MaxPooling2D((2, 2), name='max_pool')(X)
    X = Flatten()(X)
    X = Dense(1, activation='sigmoid', name='fc')(X)
    model = Model(inputs = X_input, outputs = X, name='HappyModel')
    
    return model

model = HappyModel(X_train.shape[1:])
model.compile(optimizer = 'Adam', loss = "binary_crossentropy", metrics = ["accuracy"])
model.fit(X_train,Y_train,epochs=10,batch_size=32)
train_loss,train_accuracy = model.evaluate(X_train,Y_train)
test_loss,test_accuracy = model.evaluate(X_test,Y_test)
print('train_loss:',train_loss)
print('train_accuracy:',train_accuracy)
print('test_loss:',test_loss)
print('test_accuracy:',test_accuracy)

结果:
Epoch 1/10
600/600 [==============================] - 2s 4ms/step - loss: 2.1304 - acc: 0.5933
Epoch 2/10
600/600 [==============================] - 1s 1ms/step - loss: 0.3878 - acc: 0.8350
Epoch 3/10
600/600 [==============================] - 1s 1ms/step - loss: 0.1810 - acc: 0.9283
Epoch 4/10
600/600 [==============================] - 1s 1ms/step - loss: 0.1202 - acc: 0.9583
Epoch 5/10
600/600 [==============================] - 1s 1ms/step - loss: 0.1020 - acc: 0.9633
Epoch 6/10
600/600 [==============================] - 1s 1ms/step - loss: 0.0737 - acc: 0.9817
Epoch 7/10
600/600 [==============================] - 1s 1ms/step - loss: 0.0728 - acc: 0.9783
Epoch 8/10
600/600 [==============================] - 1s 1ms/step - loss: 0.0700 - acc: 0.9800
Epoch 9/10
600/600 [==============================] - 1s 1ms/step - loss: 0.0620 - acc: 0.9783
Epoch 10/10
600/600 [==============================] - 1s 1ms/step - loss: 0.0682 - acc: 0.9750
600/600 [==============================] - 1s 1ms/step
150/150 [==============================] - 0s 853us/step
train_loss: 0.06977755357821783
train_accuracy: 0.99
test_loss: 0.11974947273731232
test_accuracy: 0.9600000039736429

Keras练习,对,我就想展示下时间,就想展示下时间(以后一定要换1060)
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值