Strange behavior in C.contrib.netopt.convert_to_binary_convolution
Hi,
I have been testing the quantization from netopt module and I found a strange behavior when using a pre-trained resnet model. By doing
import cntk as C
C.try_set_default_device(C.device.cpu())
model = C.load_model(model_path)
binz = convert_to_binary_convolution(model)
def visitor(x):
if type(x) == C.Function and 'Convol' in x.op_name and x.is_block:
print('isFunction: {}, {}, {}, isFunction: {}, {}, {}'.format(type(x) == C.Function, x.op_name, x.is_block,
type(x.block_root) == C.Function,
x.block_root.op_name, x.block_root.is_block))
return True
X = C.logging.depth_first_search(binz, visitor, depth=0)
I get that only one convolutional layer is transformed in a binary convolution layer. What am I doing wrong?
Cheers, IMQ
Can you try change your search depth to -1 for a full search?
Yes, I get the following output with depth=-1:
[BinaryConvolution: Output('stage3_layer1_relu1', [#], [512 x 7 x 7]) -> Output('Block37656_Output_0', [#], [512 x 7 x 7]),
Convolution: Output('stage3_downsample_relu1', [#], [512 x 7 x 7]) -> Output('stage3_downsample_conv2', [#], [512 x 7 x 7]),
Convolution: Output('stage2_layer1_relu2', [#], [256 x 14 x 14]) -> Output('stage3_projection_conv', [#], [512 x 7 x 7]),
Convolution: Output('stage3_downsample_relu2', [#], [512 x 7 x 7]) -> Output('stage3_layer1_conv1', [#], [512 x 7 x 7]),
Convolution: Output('stage2_layer1_relu2', [#], [256 x 14 x 14]) -> Output('stage3_downsample_conv1', [#], [512 x 7 x 7]),
Convolution: Output('stage2_layer1_relu1', [#], [256 x 14 x 14]) -> Output('stage2_layer1_conv2', [#], [256 x 14 x 14]),
Convolution: Output('stage2_downsample_relu1', [#], [256 x 14 x 14]) -> Output('stage2_downsample_conv2', [#], [256 x 14 x 14]),
Convolution: Output('stage1_layer1_relu2', [#], [128 x 28 x 28]) -> Output('stage2_projection_conv', [#], [256 x 14 x 14]),
Convolution: Output('stage2_downsample_relu2', [#], [256 x 14 x 14]) -> Output('stage2_layer1_conv1', [#], [256 x 14 x 14]),
Convolution: Output('stage1_layer1_relu2', [#], [128 x 28 x 28]) -> Output('stage2_downsample_conv1', [#], [256 x 14 x 14]),
Convolution: Output('stage1_layer1_relu1', [#], [128 x 28 x 28]) -> Output('stage1_layer1_conv2', [#], [128 x 28 x 28]),
Convolution: Output('stage1_downsample_relu1', [#], [128 x 28 x 28]) -> Output('stage1_downsample_conv2', [#], [128 x 28 x 28]),
Convolution: Output('stage0_layer1_relu2', [#], [64 x 56 x 56]) -> Output('stage1_projection_conv', [#], [128 x 28 x 28]),
Convolution: Output('stage1_downsample_relu2', [#], [128 x 28 x 28]) -> Output('stage1_layer1_conv1', [#], [128 x 28 x 28]),
Convolution: Output('stage0_layer1_relu2', [#], [64 x 56 x 56]) -> Output('stage1_downsample_conv1', [#], [128 x 28 x 28]),
Convolution: Output('stage0_layer1_relu1', [#], [64 x 56 x 56]) -> Output('stage0_layer1_conv2', [#], [64 x 56 x 56]),
Convolution: Output('stage0_layer0_relu1', [#], [64 x 56 x 56]) -> Output('stage0_layer0_conv2', [#], [64 x 56 x 56]),
Convolution: Output('ElementTimes36912_Output_0', [#], [3 x 224 x 224]) -> Output('initial_conv', [#], [64 x 112 x 112]),
Convolution: Output('stage0_layer0_relu2', [#], [64 x 56 x 56]) -> Output('stage0_layer1_conv1', [#], [64 x 56 x 56]),
Convolution: Output('max_pool', [#], [64 x 56 x 56]) -> Output('stage0_layer0_conv1', [#], [64 x 56 x 56])]
As you can see, only one convolution was transformed.
Hey @jaliyae and @KeDengMS , do you have any update on this?
I will look into this and get back to you.
This was due to a bug in the misc.converter.py. It is fixed with this change bd746943fb1afb6af95e593829ab8b73711b0927
Thank you @jaliyae . I will close this issue.