- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想为音频文件创建机器学习模型。我将音频文件转换为(频谱图)张量。我的特征张量(音频文件)具有以下形状 [119, 241, 125]
(119 个文件,241 个样本/文件,125 个频率/样本)。通过样本,我定义了我在一段时间内采集的样本,例如16 毫秒。我的输出形状将是 [119, numOptions]
。
我关注了这个tutorial from Tensorflow.js关于音频识别。他们构建了这个模型:
我将特征张量 reshape 为 4D:this.features = this.features.reshape([this.features.shape[0],this.features.shape[1],this.features.shape[2],1])
2D 转换。
buildModel() {
const inputShape1 = [this.features.shape[1], this.features.shape[2],this.features.shape[3]];
this.model = tfNode.sequential();
// filter to the image => feature extractor, edge detector, sharpener (depends on the models understanding)
this.model.add(tfNode.layers.conv2d(
{filters: 8, kernelSize: [4, 2], activation: 'relu', inputShape: inputShape1}
));
// see the image at a higher level, generalize it more, prevent overfit
this.model.add(tfNode.layers.maxPooling2d(
{poolSize: [2, 2], strides: [2, 2]}
));
// filter to the image => feature extractor, edge detector, sharpener (depends on the models understanding)
const inputShape2 = [119,62,8];
this.model.add(tfNode.layers.conv2d(
{filters: 32, kernelSize: [4, 2], activation: 'relu', inputShape: inputShape2}
));
// see the image at a higher level, generalize it more, prevent overfit
this.model.add(tfNode.layers.maxPooling2d(
{poolSize: [2, 2], strides: [2, 2]}
));
// filter to the image => feature extractor, edge detector, sharpener (depends on the models understanding)
const inputShape3 = [58,30,32];
this.model.add(tfNode.layers.conv2d(
{filters: 32, kernelSize: [4, 2], activation: 'relu', inputShape: inputShape3}
));
// see the image at a higher level, generalize it more, prevent overfit
this.model.add(tfNode.layers.maxPooling2d(
{poolSize: [2, 2], strides: [2, 2]}
));
// 1D output, => final output score of labels
this.model.add(tfNode.layers.flatten({}));
// prevents overfitting, randomly set 0
this.model.add(tfNode.layers.dropout({rate: 0.25}));
// learn anything linear, non linear comb. from conv. and soft pool
this.model.add(tfNode.layers.dense({units: 2000, activation: 'relu'}));
this.model.add(tfNode.layers.dropout({rate: 0.25}));
// give probability for each label
this.model.add(tfNode.layers.dense({units: this.labels.shape[1], activation: 'softmax'}));
this.model.summary();
// compile the model
this.model.compile({loss: 'meanSquaredError', optimizer: 'adam'});
this.model.summary()
};
_________________________________________________________________
Layer (type) Output shape Param #
=================================================================
conv2d_Conv2D1 (Conv2D) [null,238,124,8] 72
_________________________________________________________________
max_pooling2d_MaxPooling2D1 [null,119,62,8] 0
_________________________________________________________________
conv2d_Conv2D2 (Conv2D) [null,116,61,32] 2080
_________________________________________________________________
max_pooling2d_MaxPooling2D2 [null,58,30,32] 0
_________________________________________________________________
conv2d_Conv2D3 (Conv2D) [null,55,29,32] 8224
_________________________________________________________________
max_pooling2d_MaxPooling2D3 [null,27,14,32] 0
_________________________________________________________________
flatten_Flatten1 (Flatten) [null,12096] 0
_________________________________________________________________
dropout_Dropout1 (Dropout) [null,12096] 0
_________________________________________________________________
dense_Dense1 (Dense) [null,2000] 24194000
_________________________________________________________________
dropout_Dropout2 (Dropout) [null,2000] 0
_________________________________________________________________
dense_Dense2 (Dense) [null,2] 4002
=================================================================
Total params: 24208378
Trainable params: 24208378
Non-trainable params: 0
_________________________________________________________________
Epoch 1 / 10
eta=0.0 ======================================>----------------------------------------------------------------------------- loss=0.515 0.51476
eta=0.8 ============================================================================>--------------------------------------- loss=0.442 0.44186
eta=0.0 ===================================================================================================================>
3449ms 32236us/step - loss=0.485 val_loss=0.958
Epoch 2 / 10
eta=0.0 ======================================>----------------------------------------------------------------------------- loss=0.422 0.42188
eta=0.9 ============================================================================>--------------------------------------- loss=0.395 0.39535
eta=0.0 ===================================================================================================================>
3643ms 34043us/step - loss=0.411 val_loss=0.958
Epoch 3 / 10
1)第一个输入大小是我的特征张量形状。另外两个 inputShapes (inputShape2, inputShape3)
由我收到的错误消息定义。如何提前确定以下两个输入大小?
最佳答案
inputShape是如何计算的?
计算的不是 inputShape。传递给模型的数据集必须与 inputShape
相匹配。定义模型时,inputShape 是 3D 的。但查看模型摘要,有一个值为 null
的第四个维度,即批量形状。因此,训练数据应该是 4D 的。第一个维度或批处理形状可以是任何东西 - 重要的是特征和标签具有相同的批处理形状。有更详细的答案here
图层形状是如何计算的?
这取决于所使用的层。 dropout
、activation
等图层不会更改输入形状。
根据步幅内核,卷积层将改变输入形状。这个answer详细说明了如何计算。
展平层只会将 inputShape reshape 为一维。在模型摘要中,输入形状为 [null,27,14,32]
,展平层的形状为 [null, 12096] (12096 = 27 * 14 *32)
密集层也会改变输入形状。致密层的形状取决于该层的单元数量。
关于TensorflowJs conv2d - 张量形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58075896/
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我试图用这种形式简单地获取数字 28 integer+space+integer+integer+space+integer我试过这个正则表达式 \\s\\d\\d\\s 但我得到了两个数字11 和
最近一直在学习D语言。我一直对运行时感到困惑。 从我能收集到的关于它的信息中,(这不是很多)我知道它是一种有助于 D 的一些特性的运行时。像垃圾收集一样,它与您自己的程序一起运行。但是既然 D 是编译
想问一下这两个正则表达式有区别吗? \d\d\d 与 \d{3} 我已经在我的本地机器上使用 Java 和 Windows 操作系统对此进行了测试,两者都工作正常并且结果相同。但是,当在 linux
我正在学习 Go,而且我坚持使用 Go 之旅(exercise-stringer.go:https://tour.golang.org/methods/7)。 这是一些代码: type IPAddr
我在Java正则表达式中发现了一段令我困惑的代码: Pattern.compile( "J.*\\d[0-35-9]-\\d\\d-\\d\\d" ); 要编译的字符串是: String string
我在 ruby 代码上偶然发现了这个。我知道\d{4})\/(\d\d)\/(\d\d)\/(.*)/是什么意思,但是\1-\2-\3-\4 是什么意思? 最佳答案 \1-\2-\3-\4 是 b
我一直在努力解决这个问题,这让我很恼火。我了解 D 运行时库。它是什么,它做什么。我也明白你可以在没有它的情况下编译 D 应用程序。就像 XoMB 所做的那样。好吧,XoMB 定义了自己的运行时,但是
我有两个列表列表,子列表代表路径。我想找到所有路径。 List> pathList1 List> pathList2 当然是天真的解决方案: List> result = new ArrayList>
我需要使用 Regex 格式化一个字符串,该字符串包含数字、字母 a-z 和 A-Z,同时还包含破折号和空格。 从用户输入我有02-219 8 53 24 输出应该是022 198 53 24 我正在
目标是达到与this C++ example相同的效果: 避免创建临时文件。我曾尝试将 C++ 示例翻译为 D,但没有成功。我也尝试过不同的方法。 import std.datetime : benc
tl;dr:你好吗perfect forwarding在 D? 该链接有一个很好的解释,但例如,假设我有这个方法: void foo(T)(in int a, out int b, ref int c
有什么方法可以在 D 中使用abstract auto 函数吗? 如果我声明一个类如下: class MyClass { abstract auto foo(); } 我收到以下错误: mai
有没有人为内存中重叠的数组切片实现交集?算法在没有重叠时返回 []。 当 pretty-print (使用重叠缩进)内存中重叠的数组切片时,我想要这个。 最佳答案 如果您确定它们是数组,那么只需取 p
我已经开始学习 D,但我在使用 Andrei Alexandrescu 所著的 The D Programming Language 一书中提供的示例时遇到了一些麻烦。由于 int 和 ulong 类
如何创建一个不可变的类? 我的目标是创建一个实例始终不可变的类。现在我只是用不可变的方法和构造函数创建了一个“可变”类。我将其称为 mData,m 表示可变。然后我创建一个别名 alias immut
不久前我买了《The D Programming Language》。好书,很有教育意义。但是,我在尝试编译书中列出的语言功能时遇到了麻烦:扩展函数。 在这本书中,Andrei 写了任何可以像这样调用
我在 D http://www.digitalmars.com/d/2.0/lazy-evaluation.html 中找到了函数参数的惰性求值示例 我想知道如何在 D 中实现可能的无限数据结构,就像
这个问题在这里已经有了答案: 12 年前关闭。 Possible Duplicate: Could anyone explain these undefined behaviors (i = i++
当前是否可以跨模块扫描/查询/迭代具有某些属性的所有函数(或类)? 例如: source/packageA/something.d: @sillyWalk(10) void doSomething()
我是一名优秀的程序员,十分优秀!