How to load inceptionV3 model weights correctly?

Ann1: <p>I am trying to reconstruct the architecture of a model that uses inceptionV3 pretrained weights, I read the info from the “tflite” file of the said model.</p>
<pre><code class="lang-auto">interpreter = tf.lite.Interpreter(model_path="model_predict.tflite")
all_tensor_details = interpreter.get_tensor_details()
interpreter.allocate_tensors()

for tensor_item in all_tensor_details:
  print("Weight %s:" % tensor_item["name"])
</code></pre>
<p>It is using inceptionV3 weights, which sound like:</p>
<pre><code class="lang-auto">Weight InceptionV3/Conv2d_4a_3x3/BatchNorm/FusedBatchNorm:
Weight InceptionV3/Mixed_5b/Branch_0/Conv2d_0a_1x1/BatchNorm/FusedBatchNorm:
</code></pre>
<p>Am I loading these weights correctly here?:</p>
<pre><code class="lang-auto">class Predict(nn.Module):
  def __init__(self, inception):
    super(Predict, self).__init__()
    ...
    model += [inception.Conv2d_4a_3x3]
    model += [tf.nn.batch_normalization(name=None)]
    model += [tf.compat.v1.nn.fused_batch_norm(mean=None, variance=None, epsilon=0.001,
    data_format='NHWC', is_training=True, name=None,
    exponential_avg_factor=1.0)]

    model += [inception.Mixed_5b]
    ...
inception = torchvision.models.inception_v3(pretrained=True)
my_pred = Predict(inception)
</code></pre>
<p>By that, I mean, was it right to include the batch normalization and fused batch normalization functions, or are they part of inception.Conv2d_4a_3x3 already? I have never used inceptionV3 before, and I only found this post that helped me a bit:</p><aside class="quote quote-modified" data-post="1" data-topic="95428">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/a/34f0e0/48.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/load-the-weights-from-pretrained-model-into-modified-model/95428">Load the weights from pretrained model into modified model</a> 
  </div>
  <blockquote>
    I am trying to use inception model as extractor in different layers 
So I implemented a class like follow: 
class InceptExt(nn.Module):
    def __init__(self, inception):
        super(InceptExt, self).__init__()
        self.Conv2d_1a_3x3 = inception.Conv2d_1a_3x3
        self.Conv2d_2a_3x3 = inception.Conv2d_2a_3x3
        self.Conv2d_2b_3x3 = inception.Conv2d_2b_3x3
        self.Conv2d_3b_1x1 = inception.Conv2d_3b_1x1
        self.Conv2d_4a_3x3 = inception.Conv2d_4a_3x3
        self.Mixed_5b …
  </blockquote>
</aside>
<p>
but there is no explanation about the batch normalization. Plus, for the 2nd weight array, inceptionV3 does not contain anything called “Branch_0” separately, so I am assuming everything, including the batch norms, are part of the same weight. That I want to make sure of.</p>

ptrblck: <p>I’m unsure, if mixing TensorFlow and PyTorch would work, so it would be interesting to hear what your use case is and if a similar approach would work before.<br>
You can find the <code>InceptionV3</code> definition <a href="https://github.com/pytorch/vision/blob/744e37d7b5dec429b03cda213224543816499cb2/torchvision/models/inception.py">here</a> and see how each layer is used.</p>