Question
Error when exporting PyTorch model "NOT IMPLEMENTED: Order of dimensions of input cannot be interpreted"
I am using the STM32Cube.AI Developer Cloud to convert my ONNX model that I built using PyTorch.
Here is my export code:
input_size = [1, 8, 1000]
x = torch.randn(input_size)
onnx_folder_path = 'onnx_models/'
if not os.path.isdir(onnx_folder_path):
os.mkdir(onnx_folder_path)
onnx_filename = "{}{}.onnx".format(onnx_folder_path, filename)
torch.onnx.export(model, # model being run
x, # model input (or a tuple for multiple inputs)
onnx_filename, # where to save the model (can be a file or file-like object)
# export_params=True, # store the trained parameter weights inside the model file
opset_version=11, # the ONNX version to export the model to
# do_constant_folding=True, # whether to execute constant folding for optimization
input_names=['input_1'], # the model's input names
output_names=['output_1'], # the model's output names
)And my model code:
class Custom1DCNN(nn.Module):
def __init__(self, n_input=128, n_output=7, n_channel=8, pretrained=None):
super().__init__()
input_0 = n_channel
input_1 = n_input
input_2 = n_input // 4
input_3 = n_input // 8
self.conv1 = nn.Conv1d(input_0, input_1, kernel_size=3)
self.bn1 = nn.BatchNorm1d(input_1)
self.conv2 = nn.Conv1d(input_1, input_2, kernel_size=3)
self.bn2 = nn.BatchNorm1d(input_2)
self.conv3 = nn.Conv1d(input_2, input_3, kernel_size=3)
self.bn3 = nn.BatchNorm1d(input_3)
self.avgpool = nn.AdaptiveAvgPool1d(1)
self.fc1 = nn.Linear(input_3, n_output)
self.activation = nn.ReLU()
if pretrained is not None:
self.load_pretrained(pretrained)
self.is_pretrained = True
else:
self.is_pretrained = False
def forward(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = self.activation(x)
x = self.conv2(x)
x = self.bn2(x)
x = self.activation(x)
x = self.conv3(x)
x = self.bn3(x)
x = self.activation(x)
x = self.avgpool(x)
x = x.permute(0, 2, 1)
x = self.fc1(x)
x = x.flatten(1)
x = F.softmax(x, dim=1)
return xI am getting the following error:
>>> stm32ai validate --model exported_1d_cnn_input_1000.onnx --workspace workspace --output output --allocate-inputs --allocate-outputs --relocatable --compression none --optimization balanced
Neural Network Tools for STM32AI v1.6.0 (STM.ai v7.3.0-RC5)
NOT IMPLEMENTED: Order of dimensions of input cannot be interpretedI would appreciate guidance because this is blocking my research.
