Ensembling trained Renet18 and Mobilenetv3 models

username: darkdante
cooked: <p>After reading:</p>
<ul>
<li><a href="https://discuss.pytorch.org/t/how-to-ensemble-different-cnn-models-when-use-the-same-dataset/91285" class="inline-onebox">How to ensemble different CNN models when use the same dataset</a></li>
<li><a href="https://discuss.pytorch.org/t/custom-ensemble-approach/52024" class="inline-onebox">Custom Ensemble approach</a></li>
</ul>
<p>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:</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/f/ff40577a2b9c9b8059523140076f04b5fa0539e2.png" data-download-href="https://discuss.pytorch.org/uploads/default/ff40577a2b9c9b8059523140076f04b5fa0539e2" title="Screen Shot 2021-04-04 at 6.32.06 PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/f/ff40577a2b9c9b8059523140076f04b5fa0539e2_2_690x458.png" alt="Screen Shot 2021-04-04 at 6.32.06 PM" data-base62-sha1="Aq3BB999MvuZoZewoLL4vZmUvUm" width="690" height="458" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/f/ff40577a2b9c9b8059523140076f04b5fa0539e2_2_690x458.png, https://discuss.pytorch.org/uploads/default/optimized/3X/f/f/ff40577a2b9c9b8059523140076f04b5fa0539e2_2_1035x687.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/f/f/ff40577a2b9c9b8059523140076f04b5fa0539e2_2_1380x916.png 2x" data-dominant-color="151616"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2021-04-04 at 6.32.06 PM</span><span class="informations">1786×1188 279 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Here is how i load the checkpoints into the models I have already trained:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/b/4b90e53043e38211645b4e7a6f1f92485322f06f.png" data-download-href="https://discuss.pytorch.org/uploads/default/4b90e53043e38211645b4e7a6f1f92485322f06f" title="Screen Shot 2021-04-04 at 6.32.25 PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/4/b/4b90e53043e38211645b4e7a6f1f92485322f06f_2_563x499.png" alt="Screen Shot 2021-04-04 at 6.32.25 PM" data-base62-sha1="aMufjkcXAY46T3UkFnTpFjbFlX9" width="563" height="499" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/4/b/4b90e53043e38211645b4e7a6f1f92485322f06f_2_563x499.png, https://discuss.pytorch.org/uploads/default/optimized/3X/4/b/4b90e53043e38211645b4e7a6f1f92485322f06f_2_844x748.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/4/b/4b90e53043e38211645b4e7a6f1f92485322f06f_2_1126x998.png 2x" data-dominant-color="171717"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2021-04-04 at 6.32.25 PM</span><span class="informations">1786×1584 387 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>And here is the error I get:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/6/d6f885db4295d8cf83664b1f5ece6f164c0e7afa.png" data-download-href="https://discuss.pytorch.org/uploads/default/d6f885db4295d8cf83664b1f5ece6f164c0e7afa" title="Screen Shot 2021-04-04 at 6.32.47 PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/6/d6f885db4295d8cf83664b1f5ece6f164c0e7afa_2_690x167.png" alt="Screen Shot 2021-04-04 at 6.32.47 PM" data-base62-sha1="uFIDsDZZK9aCVA4IgtbkiFSnyH0" width="690" height="167" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/6/d6f885db4295d8cf83664b1f5ece6f164c0e7afa_2_690x167.png, https://discuss.pytorch.org/uploads/default/optimized/3X/d/6/d6f885db4295d8cf83664b1f5ece6f164c0e7afa_2_1035x250.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/d/6/d6f885db4295d8cf83664b1f5ece6f164c0e7afa_2_1380x334.png 2x" data-dominant-color="14191F"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2021-04-04 at 6.32.47 PM</span><span class="informations">1786×434 44 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I am not sure how to fix this. Any help will be appreciated.</p>

username: Dwight_Foster
cooked: <p>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.</p>