赞
踩
inputs = keras.layers.Input(shape=(784,)) # 同 keras.Input()
x = keras.layers.Dense(64)(x)
x = keras.layers.Flatten()(x)
x = keras.layers.average([y1, y2, y3])
x = keras.layers.concatenate([title_features, body_features, tags_input])
x = keras.layers.Embedding(input_dim=10, output_dim=32)(title_input)
Conv1D
, Conv2D
, Conv3D
, Conv2DTranspose
MaxPooling1D
, MaxPooling2D
, MaxPooling3D
, AveragePooling1D
, GlobalAveragePooling2D
GRU
, LSTM,
ConvLSTM2D
BatchNormalization
, Dropout
, Embedding
activation="relu"
activation="softmax"
keras.utils.to_categorical(y_train, 10)
keras.Sequenctial
只适合简单的情况,复杂的情况需要keras.Model
。下面是复杂的情况:
inputs = keras.layers.Input(shape=(784,))
x = keras.layers.Dense(64, activation="relu")(inputs)
outputs = keras.layers.Dense(10)(x)
model = keras.Model(inputs=inputs, outputs=outputs)
inputs = keras.layers.Input(shape=(784,))
The shape of the data is set as a 784-dimensional vector. The batch size is always omitted since only the shape of each sample is specified.
body_input = keras.layers.Input(shape=(None,))
# 输入200x200 RGB图像将具有形状(200,200,3),但输入任何大小的RGB图像将具有形状(None, None, 3)。
inputs = keras.Input(shape=(None, None, 3))
print(inputs.shape)
# TensorShape([None, 784]),表示784 dimensional vector
# 这是inputs 的输出的形状,而不是输入
print(inputs.dtype)
# tf.float32
model.summary() ''' Model: "mnist_model" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= input_1 (InputLayer) [(None, 784)] 0 _________________________________________________________________ dense (Dense) (None, 64) 50240 _________________________________________________________________ dense_1 (Dense) (None, 64) 4160 _________________________________________________________________ dense_2 (Dense) (None, 10) 650 ================================================================= Total params: 55,050 Trainable params: 55,050 Non-trainable params: 0 _________________________________________________________________ '''
第一个None
表示的是batch_size
(Here the batch size is None, which indicates our model can process batches of any size),input_1
就是名字,[(None, 784)]
就是输出的形状。
keras.utils.plot_model(model, "my_first_model.png")
keras.utils.plot_model(model, "my_first_model_with_shape_info.png", show_shapes=True)
This saved file includes the:
model.save("path_to_my_model")
model = keras.models.load_model("path_to_my_model")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。