简体   繁体   中英

CNTK Convolution1d

I am trying to create a simple convolution model in CNTK as shown below

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.

I was able to fix this issue by adding the reduction_rank=0 as a parameter to the Convolution1d layer.

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

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)

I was expecting that CNTK would be able to infer this thing automatically

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM