当我使用codelabs.developers.google提供的代码进行测试时,我发现准确性太低并且对任何声音都敏感。
此后,我将以下代码添加到函数buildModel()
中,但问题仍未解决。
function buildModel() {
model = tf.sequential();
model.add(tf.layers.conv2d(
{filters: 8, kernelSize: [2, 8],strides: [1, 1], activation: 'relu', inputShape: INPUT_SHAPE,}));
model.add(tf.layers.maxPooling2d({poolSize: [2, 2], strides: [2, 2]}));
model.add(
tf.layers.conv2d({filters: 32, kernelSize: [2, 4],strides: [1, 1], activation: 'relu'}));
model.add(tf.layers.maxPooling2d({poolSize: [2, 2], strides: [2, 2]}));
model.add(
tf.layers.conv2d({filters: 32, kernelSize: [2, 4], activation: 'relu'}));
model.add(tf.layers.maxPooling2d({poolSize: [2, 2], strides: [2, 2]}));
model.add(
tf.layers.conv2d({filters: 32, kernelSize: [2, 4], activation: 'relu'}));
model.add(tf.layers.maxPooling2d({poolSize: [2, 2], strides: [1, 2]}));
model.add(tf.layers.flatten());
model.add(tf.layers.dropout({rate: 0.25}));
model.add(tf.layers.dense({units: 2000, activation: 'relu'}));
model.add(tf.layers.dropout({rate: 0.5}));
model.add(tf.layers.dense({units: 3, activation: 'softmax'}));
const optimizer = tf.train.adam(0.01);
model.compile({
optimizer,
loss: 'categoricalCrossentropy',
metrics: ['accuracy']
});
}
还是我的想法错了?因此,我可以从这里得到一些建议,我认为这将为我的下一个方向提供很大的启发。