When I was modifing a complex net, such as inception-v3, sometimes the net structure is incorrect due to careless wrong computation, such as forgetting padding. The running error message is not so easily understood, so I want to simply print the shape of the input and the output.
For example:
print in3c.shape
in3d = Inception7B(in3c, 384, 64, 96, 96,"max", "mixed_3")
print in3d.shape
Is this possible?
You will need to call infer_shape to get the shape of an output.
I will make a PR to print out the shape when binding. It is quite inconvenient for debug.
@winstywang I think executor.debug_str() does that
Unfortunately, debug_str only prints the execution plan.
Outputs:
output[0]=softmax(0)
Variable:data
Variable:stem_conv_1_1_conv2d_weight
Name: stem_conv_1_1_conv2d Type:Convolution
Inputs:
arg[0]=data(0)
arg[1]=stem_conv_1_1_conv2d_weight(0)
Variable:stem_conv_1_1_batchnorm_gamma
Variable:stem_conv_1_1_batchnorm_beta
Name: stem_conv_1_1_batchnorm Type:BatchNorm
Inputs:
arg[0]=stem_conv_1_1_conv2d(0)
arg[1]=stem_conv_1_1_batchnorm_gamma(0)
arg[2]=stem_conv_1_1_batchnorm_beta(0)
Name: stem_conv_1_1_relu Type:Activation
Inputs:
arg[0]=stem_conv_1_1_batchnorm(0)
......
The output of infer_shape does not contain the symbols names. We need something like symbol.get_name() and symbol.get_output_shape(symbol_name). More generally, how to directly get the information of a non-terminal symbol?
([(1L, 3L, 299L, 299L), (32L, 3L, 3L, 3L), (32L,), (32L,), (32L, 32L, 3L, 3L), (32L,), (32L,), (64L, 32L, 3L, 3L), (64L,), (64L,), (96L, 64L, 3L, 3L), (96L,), (96L,), (64L, 160L, 1L, 1L), (64L,), (64L,), (64L, 64L, 7L, 1L), (64L,), (64L,), (64L, 64L, 1L, 7L), (64L,), (64L,), (96L, 64L, 3L, 3L), (96L,), (96L,)], [(1L, 96L, 65L, 65L)], [(32L,), (32L,), (32L,), (32L,), (64L,), (64L,), (96L,), (96L,), (64L,), (64L,), (64L,), (64L,), (64L,), (64L,), (96L,), (96L,)])
pprint.pprint the above output shows that the second element is the symbol's output shape.
you can see visualization.py
def print_summary(symbol, shape=None, line_length=120, positions=[.44, .64, .74, 1.]):
...
interals = symbol.get_internals()
_, out_shapes, _ = interals.infer_shape(**shape)
shape_dict = dict(zip(interals.list_outputs(), out_shapes))
Most helpful comment
you can see visualization.py