[英]CNTK Convolution1d
I am trying to create a simple convolution model in CNTK as shown below 我试图在CNTK中创建一个简单的卷积模型,如下所示
def create_model(hidden_dim, output_dim):
nn=C.layers.Sequential([ C.layers.Embedding(shape=50,name='embedding'),
C.layers.Convolution1D((40,),num_filters=5, activation=C.ops.relu),
C.layers.GlobalMaxPooling(),
C.layers.Dense(shape=40, activation=C.ops.tanh, init_bias=0.1),
C.layers.Dense(shape=2, activation=None, init_bias=0.1)
])
return nn
but I keep on getting the following error ValueError: Convolution map tensor must have rank 1 or the same as the input tensor. 但我继续得到以下错误ValueError:卷积映射张量必须具有等级1或与输入张量相同。
I was able to fix this issue by adding the reduction_rank=0 as a parameter to the Convolution1d layer. 我能够通过将reduction_rank = 0作为参数添加到Convolution1d层来解决此问题。
def create_model(hidden_dim, output_dim):
nn=C.layers.Sequential([ C.layers.Embedding(shape=50,name='embedding', **reduction_rank=0**),
C.layers.Convolution1D((40,),num_filters=5, activation=C.ops.relu),
C.layers.GlobalMaxPooling(),
C.layers.Dense(shape=40, activation=C.ops.tanh, init_bias=0.1),
C.layers.Dense(shape=2, activation=None, init_bias=0.1)
])
return nn
Quoting from the CNTK Layers Documentation 引自CNTK图层文档
reduction_rank (int, defaults to 1) – set to 0 if input items are scalars (input has no depth axis), eg an audio signal or a black-and-white image that is stored with tensor shape (H,W) instead of (1,H,W) reduction_rank(int,默认为1) - 如果输入项是标量(输入没有深度轴),则设置为0,例如音频信号或以张量形状(H,W)存储的黑白图像,而不是(1,H,W)
I was expecting that CNTK would be able to infer this thing automatically 我原以为CNTK能够自动推断出这件事
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.