def model(self): num_classes = self.config.get("CNN_training_rule", "num_classes") seq_length = self.config.get("CNN_training_rule", "seq_length") conv1_num_filters = self.config.get("CNN_training_rule", "conv1_num_filters") conv1_kernel_size = self.config.get("CNN_training_rule", "conv1_kernel_size") conv2_num_filters = self.config.get("CNN_training_rule", "conv2_num_filters") conv2_kernel_size = self.config.get("CNN_training_rule", "conv2_kernel_size") hidden_dim = self.config.get("CNN_training_rule", "hidden_dim") dropout_keep_prob = self.config.get("CNN_training_rule", "dropout_keep_prob") model_input = keras.layers.Input((seq_length,1), dtype='float64') # conv1形状[batch_size, seq_length, conv1_num_filters] conv_1 = keras.layers.Conv1D(conv1_num_filters, conv1_kernel_size, padding="SAME")(model_input) conv_2 = keras.layers.Conv1D(conv2_num_filters, conv2_kernel_size, padding="SAME")(conv_1) max_poolinged = keras.layers.GlobalMaxPool1D()(conv_2) full_connect = keras.layers.Dense(hidden_dim)(max_poolinged) droped = keras.layers.Dropout(dropout_keep_prob)(full_connect) relued = keras.layers.ReLU()(droped) model_output = keras.layers.Dense(num_classes, activation="softmax")(relued) model = keras.models.Model(inputs=model_input, outputs=model_output) # model.compile(loss="categorical_crossentropy", # optimizer="adam", # metrics=["accuracy"]) model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) print(model.summary()) return model给这段代码每行加上注释
时间: 2024-02-27 11:57:03 浏览: 185
关于tf.nn.dynamic_rnn返回值详解
```
def model(self):
# 获取配置文件中的参数
num_classes = self.config.get("CNN_training_rule", "num_classes") #分类数
seq_length = self.config.get("CNN_training_rule", "seq_length") #序列长度
conv1_num_filters = self.config.get("CNN_training_rule", "conv1_num_filters") #第一层卷积核数量
conv1_kernel_size = self.config.get("CNN_training_rule", "conv1_kernel_size") #第一层卷积核大小
conv2_num_filters = self.config.get("CNN_training_rule", "conv2_num_filters") #第二层卷积核数量
conv2_kernel_size = self.config.get("CNN_training_rule", "conv2_kernel_size") #第二层卷积核大小
hidden_dim = self.config.get("CNN_training_rule", "hidden_dim") #全连接层隐藏层大小
dropout_keep_prob = self.config.get("CNN_training_rule", "dropout_keep_prob") #dropout保留率
# 定义模型输入
model_input = keras.layers.Input((seq_length,1), dtype='float64')
# 第一层卷积
conv_1 = keras.layers.Conv1D(conv1_num_filters, conv1_kernel_size, padding="SAME")(model_input)
# 第二层卷积
conv_2 = keras.layers.Conv1D(conv2_num_filters, conv2_kernel_size, padding="SAME")(conv_1)
# 全局最大池化
max_poolinged = keras.layers.GlobalMaxPool1D()(conv_2)
# 全连接层
full_connect = keras.layers.Dense(hidden_dim)(max_poolinged)
# dropout层
droped = keras.layers.Dropout(dropout_keep_prob)(full_connect)
# relu激活层
relued = keras.layers.ReLU()(droped)
# 输出层
model_output = keras.layers.Dense(num_classes, activation="softmax")(relued)
# 定义模型
model = keras.models.Model(inputs=model_input, outputs=model_output)
# 编译模型
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
# 打印模型结构
print(model.summary())
return model
```
阅读全文