code: def load_mobilenetv2_from_tensorflow_checkpoint(
      model, checkpoint_filename
  ):
      ckpt_reader = tf.train.NewCheckpointReader(checkpoint_filename)
  
      # Loading weights for the expanded convolutions.
      tf_scope_to_expanded_conv = {
          "MobilenetV2/expanded_conv": model.expanded_conv,
      }
      for i in range(16):
          tf_scope_to_expanded_conv[
              "MobilenetV2/expanded_conv_{}".format(i + 1)
          ] = getattr(model, "expanded_conv_{}".format(i + 1))
      for tf_scope, expanded_conv in tf_scope_to_expanded_conv.items():
          print("Loading weights for %s" % tf_scope)
          # Expand convolution parameters
          if hasattr(expanded_conv, "expand"):
              expand_params = {
                  "weights": get_tensor(
                      ckpt_reader, tf_scope + "/expand/weights"
                  ),
                  "beta": get_tensor(
                      ckpt_reader, tf_scope + "/expand/BatchNorm/beta"
                  ),
                  "gamma": get_tensor(
                      ckpt_reader, tf_scope + "/expand/BatchNorm/gamma"
                  ),
                  "moving_mean": get_tensor(
                      ckpt_reader,
                      tf_scope + "/expand/BatchNorm/moving_mean",
                  ),
                  "moving_variance": get_tensor(
                      ckpt_reader,
                      tf_scope + "/expand/BatchNorm/moving_variance",
                  ),
              }
          else:
              print(
                  "Skipping expanded convolution for {}".format(
                      tf_scope
                  )
              )
              expand_params = None
          # Depthwise convolution parameters
          depthwise_params = {
              "weights": get_tensor(
                  ckpt_reader, tf_scope + "/depthwise/depthwise_weights"
              ),
              "beta": get_tensor(
                  ckpt_reader, tf_scope + "/depthwise/BatchNorm/beta"
              ),
              "gamma": get_tensor(
                  ckpt_reader, tf_scope + "/depthwise/BatchNorm/gamma"
              ),
              "moving_mean": get_tensor(
                  ckpt_reader,
                  tf_scope + "/depthwise/BatchNorm/moving_mean",
              ),
              "moving_variance": get_tensor(
                  ckpt_reader,
                  tf_scope + "/depthwise/BatchNorm/moving_variance",
              ),
          }
  
          # Project convolution parameters
          project_params = {
              "weights": get_tensor(
                  ckpt_reader, tf_scope + "/project/weights"
              ),
              "beta": get_tensor(
                  ckpt_reader, tf_scope + "/project/BatchNorm/beta"
              ),
              "gamma": get_tensor(
                  ckpt_reader, tf_scope + "/project/BatchNorm/gamma"
              ),
              "moving_mean": get_tensor(
                  ckpt_reader,
                  tf_scope + "/project/BatchNorm/moving_mean",
              ),
              "moving_variance": get_tensor(
                  ckpt_reader,
                  tf_scope + "/project/BatchNorm/moving_variance",
              ),
          }
          load_expanded_conv(
              expanded_conv,
              expand_params=expand_params,
              depthwise_params=depthwise_params,
              project_params=project_params,
          )
      # Similarly loading the vanilla convolutions.
      # Initial convolution
      init_conv_with_tf_weights(
          model.conv.conv,
          weights=get_tensor(ckpt_reader, "MobilenetV2/Conv/weights"),
      )
      init_bn_with_tf_params(
          model.conv.bn,
          beta=get_tensor(
              ckpt_reader, "MobilenetV2/Conv/BatchNorm/beta"
          ),
          gamma=get_tensor(
              ckpt_reader, "MobilenetV2/Conv/BatchNorm/gamma"
          ),
          moving_mean=get_tensor(
              ckpt_reader, "MobilenetV2/Conv/BatchNorm/moving_mean"
          ),
          moving_variance=get_tensor(
              ckpt_reader, "MobilenetV2/Conv/BatchNorm/moving_variance"
          ),
      )
      # Final convolution before dropout (conv1)
      init_conv_with_tf_weights(
          model.conv1.conv,
          weights=get_tensor(ckpt_reader, "MobilenetV2/Conv_1/weights"),
      )
      init_bn_with_tf_params(
          model.conv1.bn,
          beta=get_tensor(
              ckpt_reader, "MobilenetV2/Conv_1/BatchNorm/beta"
          ),
          gamma=get_tensor(
              ckpt_reader, "MobilenetV2/Conv_1/BatchNorm/gamma"
          ),
          moving_mean=get_tensor(
              ckpt_reader, "MobilenetV2/Conv_1/BatchNorm/moving_mean"
          ),
          moving_variance=get_tensor(
              ckpt_reader,
              "MobilenetV2/Conv_1/BatchNorm/moving_variance",
          ),
      )
      # Logits convolution
      init_conv_with_tf_weights(
          model.logits_conv,
          weights=get_tensor(
              ckpt_reader, "MobilenetV2/Logits/Conv2d_1c_1x1/weights"
          ),
          bias=get_tensor(
              ckpt_reader, "MobilenetV2/Logits/Conv2d_1c_1x1/biases"
          ),
      )
  
file_path: chainercv/examples/mobilenet/tfckpt2npz.py
imports: import argparse
  import chainer
  import tensorflow
  from chainercv.links import MobileNetV2
label_desc: Use image node_id 5 for calling a global function with example usage: load_mobilenetv2_from_tensorflow_checkpoint(model, checkpoint_filename) without return types