当前位置:网站首页>MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.

MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.

2022-07-06 21:01:00 wx5d786476cd8b2


MLP( Multilayer perceptron neural network ) That is, multi-layer fully connected neural network model .

       
from keras.datasets import mnist
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers import Dense,Dropout,Activation

batch_size=128
nb_classes=10
nb_epoch=10
img_size=28*28

(x_train,y_train),(x_test,y_test)=mnist.load_data("E:\Code\PycharmProjects\KerasStudying\data\mnist.npz")

x_train=x_train.reshape(-1,img_size).astype('float32')/255
x_test=x_test.reshape(-1,img_size).astype('float32')/255
y_train=np_utils.to_categorical(y_train,nb_classes)
y_test=np_utils.to_categorical(y_test,nb_classes)


model=Sequential([
Dense(512,input_shape=(img_size,),activation='relu',),
Dropout(0.2),
Dense(512,input_shape=(512,),activation='relu'),
Dropout(0.2),
Dense(10,input_shape=(512,),activation='softmax'),
])

model.summary()

model.compile(optimizer='rmsprop',loss='categorical_crossentropy',metrics=['accuracy'])


model.fit(x_train,y_train,batch_size=batch_size,epochs=10,verbose=0,validation_data=(x_test,y_test))

score=model.evaluate(x_test,y_test,verbose=0)
print('accuracy:'+str(score[1]))
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.

MLP( Multilayer perceptron neural network ) That is, multi-layer fully connected neural network model ._lua


原网站

版权声明
本文为[wx5d786476cd8b2]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131134238801.html