title: How to load .pth file?
body: <p>I am given a pytorch model from [this repository][1] and I have to convert it to tflite.
  Here's the code:</p>
  <pre><code>def get_torch_model(model_path):
      &quot;&quot;&quot;
      Loads state-dict into model and creates an instance.
      &quot;&quot;&quot;
      model= torch.load(model_path)
      return model
  </code></pre>
  <pre><code># Conversion
  import torch
  from torchvision import transforms
  
  import onnx
  
  import cv2
  import numpy as np
  import onnx
  import tensorflow as tf
  import torch
  from PIL import Image
  
  import torch.onnx
  
  image, tf_lite_image, sample_input = get_sample_input(&quot;crop.jpg&quot;)
  torch_model = get_torch_model(&quot;pose_resnet_152_256x256.pth&quot;)
  
  ONNX_FILE = &quot;./m_model.onnx&quot;
  </code></pre>
  <p>Up until here everything runs smoothly. But when I run the below cell:</p>
  <pre><code>torch.onnx.export(
          model=torch_model,
          args=sample_input,
          f=ONNX_FILE,
          verbose=False,
          export_params=True,
          do_constant_folding=False,  # fold constant values for optimization
          input_names=['input'],
          opset_version=10,
          output_names=['output']
  )
  
  onnx_model = onnx.load(ONNX_FILE)
  
  onnx.checker.check_model(onnx_model)
  </code></pre>
  <p>The complete log of error:</p>
  <pre><code>---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-33-15df717ec276&gt; in &lt;module&gt;
        8         input_names=['input'],
        9         opset_version=10,
  ---&gt; 10         output_names=['output']
       11 )
       12 
  
  ~\anaconda3\envs\py36\lib\site-packages\torch\onnx\__init__.py in export(model, args, f, export_params, verbose, training, input_names, output_names, aten, export_raw_ir, operator_export_type, opset_version, _retain_param_name, do_constant_folding, example_outputs, strip_doc_string, dynamic_axes, keep_initializers_as_inputs, custom_opsets, enable_onnx_checker, use_external_data_format)
      274                         do_constant_folding, example_outputs,
      275                         strip_doc_string, dynamic_axes, keep_initializers_as_inputs,
  --&gt; 276                         custom_opsets, enable_onnx_checker, use_external_data_format)
      277 
      278 
  
  ~\anaconda3\envs\py36\lib\site-packages\torch\onnx\utils.py in export(model, args, f, export_params, verbose, training, input_names, output_names, aten, export_raw_ir, operator_export_type, opset_version, _retain_param_name, do_constant_folding, example_outputs, strip_doc_string, dynamic_axes, keep_initializers_as_inputs, custom_opsets, enable_onnx_checker, use_external_data_format)
       92             dynamic_axes=dynamic_axes, keep_initializers_as_inputs=keep_initializers_as_inputs,
       93             custom_opsets=custom_opsets, enable_onnx_checker=enable_onnx_checker,
  ---&gt; 94             use_external_data_format=use_external_data_format)
       95 
       96 
  
  ~\anaconda3\envs\py36\lib\site-packages\torch\onnx\utils.py in _export(model, args, f, export_params, verbose, training, input_names, output_names, operator_export_type, export_type, example_outputs, opset_version, _retain_param_name, do_constant_folding, strip_doc_string, dynamic_axes, keep_initializers_as_inputs, fixed_batch_size, custom_opsets, add_node_names, enable_onnx_checker, use_external_data_format, onnx_shape_inference, use_new_jit_passes)
      677         _set_opset_version(opset_version)
      678         _set_operator_export_type(operator_export_type)
  --&gt; 679         with select_model_mode_for_export(model, training):
      680             val_keep_init_as_ip = _decide_keep_init_as_input(keep_initializers_as_inputs,
      681                                                              operator_export_type,
  
  ~\anaconda3\envs\py36\lib\contextlib.py in __enter__(self)
       79     def __enter__(self):
       80         try:
  ---&gt; 81             return next(self.gen)
       82         except StopIteration:
       83             raise RuntimeError(&quot;generator didn't yield&quot;) from None
  
  ~\anaconda3\envs\py36\lib\site-packages\torch\onnx\utils.py in select_model_mode_for_export(model, mode)
       36 def select_model_mode_for_export(model, mode):
       37     if not isinstance(model, torch.jit.ScriptFunction):
  ---&gt; 38         is_originally_training = model.training
       39 
       40         if mode is None:
  
  AttributeError: 'collections.OrderedDict' object has no attribute 'training'
  </code></pre>
  <p>This error occurs when I use torch.onnx.export() .</p>
  <p>Please let me know whats going wrong here.
  Am I not loading the weights properly? If not then how do I load the model? I don't know the class, or architecture details so how do I use model.load_state_dict() ??</p>
  <pre><code>
  
  
    [1]: https://github.com/leoxiaobin/deep-high-resolution-net.pytorch
  </code></pre>