Ensembling trained Renet18 and Mobilenetv3 models

After reading:

I am trying to ensemble two models I have already trained on the same dataset and classify them into 4 categories. I created a custom ensemble classes according to the posts instructions but when running, the tensors don’t seem to match. Here is the ensemble code:

Here is how i load the checkpoints into the models I have already trained:

And here is the error I get:

I am not sure how to fix this. Any help will be appreciated.

This is happening because the mobilenet fully connected layer is not called fc. It is called classifier, so when you set mobilenet.fc to a sequential it just adds a completely new sequential. This new sequential however is useless because it is not registered in the forward function. To fix this just change the mobilenetv3.fc to mobilenetv3.classifier.