官术网_书友最值得收藏!

Layers in the Keras model

A Keras layer is just like a neural network layer. There are fully connected layers, max pool layers, and activation layers. A layer can be added to the model using the model's add() function. For example, a simple model can be represented by the following:

from keras.models import Sequential
from keras.layers.core import Dense, Activation, Flatten

#Creating the Sequential model
model = Sequential()

#Layer 1 - Adding a flatten layer
model.add(Flatten(input_shape=(32, 32, 3)))

#Layer 2 - Adding a fully connected layer
model.add(Dense(100))

#Layer 3 - Adding a ReLU activation layer
model.add(Activation('relu'))

#Layer 4- Adding a fully connected layer
model.add(Dense(60))

#Layer 5 - Adding an ReLU activation layer
model.add(Activation('relu'))

Keras will automatically infer the shape of all layers after the first layer. This means you only have to set the input dimensions for the first layer. The first layer from the preceding code snippet, model.add(Flatten(input_shape=(32, 32, 3))), sets the input dimension to (32, 32, 3) and the output dimension to (3072=32 x 32 x 3). The second layer takes in the output of the first layer and sets the output dimensions to (100). This chain of passing the output to the next layer continues until the last layer, which is the output of the model.

主站蜘蛛池模板: 洪洞县| 永善县| 四子王旗| 舞阳县| 桃园市| 梅州市| 建德市| 屏边| 毕节市| 海伦市| 浠水县| 乃东县| 本溪市| 奉新县| 边坝县| 文水县| 哈尔滨市| 山东省| 三穗县| 屯昌县| 清涧县| 额敏县| 隆化县| 江山市| 泰顺县| 葫芦岛市| 靖宇县| 利辛县| 尉氏县| 抚远县| 滦南县| 夹江县| 德江县| 清丰县| 尖扎县| 乡城县| 红桥区| 府谷县| 吉安县| 习水县| 怀集县|