tvm icon indicating copy to clipboard operation
tvm copied to clipboard

broadcast_add not support the NCHW format

Open liuchangready opened this issue 8 years ago • 4 comments

hi,when i transform my NCHW format tensorflow model,I met the problem Check failed: l == 1 || r == 1 operands could not be broadcast together with shapes [1,256,16,16] [256], l=16, r=256,when i check the code ,I find the broadcast_add is only support the NHWC format.Is threre a plan to support it?

liuchangready avatar Nov 27 '18 01:11 liuchangready

Thanks for posting this issue. Let me check .

srkreddy1238 avatar Nov 27 '18 01:11 srkreddy1238

thank you very much, I make a quick temporary fix to the problem,hope this can help someone. change code in nnvm/frontend/tensorflow.py line 417: change def _bias_add(): def _impl(inputs, attr, params): return _sym.broadcast_add(inputs[0], inputs[1]) return _impl to def _bias_add(): def _impl(inputs, attr, params): #print("inputs[1].shape is "+str(inputs[1].debug_str())) if 'data_format' in attr: attr['data_format'] = attr['data_format'].decode("utf-8") if attr['data_format'] == 'NCHW': data_shape_1 = attr['_input_shapes'][inputs[1]] data_shape_0 = attr['_input_shapes'][inputs[0]] inputs[1] = _sym.expand_dims(inputs[1], axis=0, num_newaxis=1) inputs[1] = _sym.expand_dims(inputs[1], axis=2, num_newaxis=2)

    return _sym.broadcast_add(inputs[0], inputs[1])
return _impl

liuchangready avatar Nov 27 '18 02:11 liuchangready

@liuchangready above changes looks good. feel free to push a PR for this along with a test case for this situation.

srkreddy1238 avatar Nov 27 '18 03:11 srkreddy1238

close due to inactive status, contribution is still welcomed

tqchen avatar Jan 08 '19 17:01 tqchen