My device need the weights and input layout NHWC,but the pytorch model layout is NCHW.
I want to change weights layout from NCHW to NHWC , and I came up with two ways:
-
In the TVM Relay,add transform layout before convolution.But this operation is too time consuming, and every time you run the network, you need to transform it again.
-
A better way is,the parameter layout is converted to NHWC format in advance.But when I artificially transformed the layout in Pytorch model, here were some mistakes:
-
transform layout before jit.trance()
model = weights_layout_NCHW2NHWnC(model) model= torch.jit.trace(model, input_data).eval()
The error is :
Given groups=1, weight of size [64, 7, 7, 3], expected input[1, 224, 224, 3] to have 7 channels, but got 224 channels instead
-
transform layout after jit.trance() before relay.frontend.from_pytorch()
model= torch.jit.trace(model, input_data).eval() model = weights_layout_NCHW2NHWnC(model) mod, params = relay.frontend.from_pytorch(model, shape_list)
The error is :
Shapes of input list and information in the graph do not match
-
This means that I can鈥檛 modify Pytorch model weights layout directly, Otherwise, there will be an error in the conversion TVM Relay.
Can you give me some suggestions to achieve my goal?
Thank you very much.