Search code examples
cntk

How to get the shape / dimension of the layers?


When I have defined a model like this:

def create_basic_model_terse(input, out_dims):

    with default_options(activation=relu):
        model = Sequential([
            LayerStack(3, lambda i: [
                Convolution((5,5), [32,32,64][i], init=glorot_uniform(), pad=True),
                MaxPooling((3,3), strides=(2,2))
            ]),
            Dense(64, init=glorot_uniform()),
            Dense(out_dims, init=glorot_uniform(), activation=None)
        ])

    return model(input)

How can I get some kind of information about each layer in the network like output shape / dimensions?


Solution

  • You can look at CNTK 202 tutorials. There are other tutorials such as CNTK 105 that also shows how to get different attributes of models.

    For a model
    def create_model():
    with default_options(initial_state=0.1):
        return Sequential([
            Embedding(emb_dim),
            Recurrence(LSTM(hidden_dim), go_backwards=False),
            Dense(num_labels)
        ])
    
    
    
    model = create_model()
    print(len(model.layers))
    print(model.layers[0].E.shape)
    print(model.layers[2].b.value)