class CNN(Model): def __init__(self): super(CNN, self).__init__() ## self.x1 = Input(shape =(1024,1,1)) self.inputshape = tf.keras.layers.InputLayer(input_shape=(1024,1,1)) self.c1 = Conv2D(filters=64, kernel_size=(2, 1), activation='relu',input_shape=(1024,1,1)) self.c2 = Conv2D(filters=64, kernel_size=(2, 1), activation='relu') self.c3 = Conv2D(filters=64, kernel_size=(2, 1), activation='relu') self.flatten = Flatten() self.f1 = Dense(360, activation='relu') self.f2 = Dense(184, activation='relu') self.f3 = Dense(4, activation='softmax') def zx(self, input): x = self.inputshape(input.astype(np.float32)) return self.c1(x) def zx1(self, input): x = self.inputshape(input.astype(np.float32)) x = self.c1(x) x = self.c2(x) x = self.c3(x) x = self.flatten(x) print(x.shape) x = self.f1(x) return self.f2(x) def call(self, input): x = self.inputshape(input) x = self.c1(x) x = self.c2(x) x = self.c3(x) x = self.flatten(x) print(x.shape) x = self.f1(x) self.x2 = self.f2(x) y = self.f3(self.x2) return y model = CNN() model.build(input_shape=(None,1024,1,1)) model.compile(optimizer='adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False), metrics=['sparse_categorical_accuracy']) 该CNN模型每层网络的参数如何
时间: 2023-06-26 22:06:34 浏览: 108
CNN训练实例(基于keras)
这个CNN模型共有5个卷积层和3个全连接层,每个卷积层都使用ReLU激活函数。具体参数如下:
- 输入层:输入形状为(1024,1,1)的张量
- 卷积层c1:使用64个大小为(2,1)的卷积核,步长为(1,1),padding方式为"valid",输出张量形状为(1023,1,64)
- 卷积层c2:使用64个大小为(2,1)的卷积核,步长为(1,1),padding方式为"valid",输出张量形状为(1022,1,64)
- 卷积层c3:使用64个大小为(2,1)的卷积核,步长为(1,1),padding方式为"valid",输出张量形状为(1021,1,64)
- 将输出张量展平为形状为(65504,)的向量
- 全连接层f1:输出向量形状为(360,),使用ReLU激活函数
- 全连接层f2:输出向量形状为(184,),使用ReLU激活函数
- 输出层:输出向量形状为(4,),使用softmax激活函数
阅读全文