pool = self._get_pool_layer_func()
conv = get_conv_layer_func(len(filter_shape))
model = Sequential()
for i in range(conv_num):
kernel_num = randint(10, 30)
if i == 0:
model.add(conv(kernel_num,
input_shape=self.input_shape,
kernel_size=filter_shape,
activation="relu",
padding="same"))
else:
model.add(conv(kernel_num,
kernel_size=filter_shape,
activation="relu",
padding="same"))
if random() > 0.5:
model.add(pool(pool_size=pool_shape, padding="same"))
if random() > 0.5:
model.add(Dropout(dropout_rate))
model.add(Flatten())
for i in range(dense_num):
node_num = randint(128, 1024)
model.add(Dense(node_num, activation="relu"))
if random() > 0.5:
model.add(Dropout(dropout_rate))model.add(Dense(self.n_classes, activation="softmax"))
model.compile(loss="categorical_crossentropy",
optimizer=Adam(),
metrics=["accuracy"])
return model