Hello !
I’m actually working on a project involving automatic resolution of a marble labyrinth on a raspberry pi 5. Since I required more fps, I bought an Hailo hat in order to improve it.
I’m struggling running a custom model :
class MobileNetV2Custom(nn.Module):
def init(self):
super(MobileNetV2Custom, self).init()
base_model = models.mobilenet_v2(weights=None)
base_model.features[0][0] = nn.Conv2d(3, 32, kernel_size=3, stride=2, padding=1, bias=False)
self.features = base_model.features
self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
self.fc = nn.Sequential(
nn.Flatten(),
nn.Linear(1280, 256),
nn.ReLU(),
nn.Linear(256, 128),
nn.ReLU(),
)
self.out_coord = nn.Linear(128, 2)
self.out_presence = nn.Linear(128, 1)
def forward(self, x):
x = self.features(x)
x = self.avgpool(x)
x = self.fc(x)
coord = self.out_coord(x)
presence = torch.sigmoid(self.out_presence(x))
# Fusion outputs (coord + presence)
return torch.cat((coord, presence), dim=1)
I’m following notebook tutorials to convert from onnx to hef. I can see that the runner.infer is very good (like the onnx) but when compiling, it changes coordinates and the presence. For instance, presence is no more a sigmoid between 0,1. When there’s the ball, it gets to 1.5. I’m assuming it’s a normalization issue in the output. I tried getting the scale and zero but the command i saw in the forum didn’t work.
My last attempt was to get the 3 outputs separated but I had no more luck :
class MobileNetV2Custom(nn.Module):
def init(self):
super(MobileNetV2Custom, self).init()
base_model = models.mobilenet_v2(weights=None)
base_model.features[0][0] = nn.Conv2d(3, 32, kernel_size=3, stride=2, padding=1, bias=False)
self.features = base_model.features
self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
self.fc = nn.Sequential(
nn.Flatten(),
nn.Linear(1280, 256),
nn.ReLU(),
nn.Linear(256, 128),
nn.ReLU(),
)
self.out_x = nn.Linear(128, 1)
self.out_y = nn.Linear(128, 1)
self.out_presence = nn.Linear(128, 1)
def forward(self, x):
x = self.features(x)
x = self.avgpool(x)
x = self.fc(x)
x_out = self.out_x(x)
y_out = self.out_y(x)
presence_out = torch.sigmoid(self.out_presence(x))
return x_out, y_out, presence_out
In this case, with :
hn, npz = runner.translate_onnx_model(
onnx_path,
onnx_model_name,
start_node_names=[“input”],
end_node_names=[“x_out”, “y_out”, “presence_out”],
net_input_shapes={“input”: [1, 3, 158, 200]},
)
I get the error :
…
3786 pred.replace_output_index(conv.index, dense.index)
→ 3787 pred.output_shapes[pred.outputs.index(dense.name)] = dense.input_shape
3788 self._output_graph.add_edge(pred, dense)
3789 self._output_graph.remove_edge(pred, conv)
IndexError: list assignment index out of range
Can you please help me.
Alexandre.