How can I get conv stride info in tracedModel

joe8086: <p>Hi Friends,</p>
<p>I use traced_model._modules[‘conv1’] to access conv module.<br>
But how can I find ‘stride’ info in it?</p>
<p>Thanks,<br>
8086</p>

ptrblck: <p>Would <code>print(traced_model._modules['conv1'].stride)</code> work?</p>

joe8086: <p>Thanks ptrblck, that’s a good guide.<br>
But I did try still fail.<br>
I want to able to access these fields after load traced file.<br>
My test environment is at Windows pytorch 1.1.0</p>
<pre><code class="lang-auto">import torch
import torchvision
m = torchvision.models.resnet18()
t_m = torch.jit.trace(m, torch.rand(1, 3, 224, 224))
m._modules['conv1'].stride
#(2, 2)
t_m._modules['conv1']
#TracedModule[Conv2d]()
t_m._modules['conv1'].stride
---------------------------------------------------------------------------
# AttributeError                            Traceback (most recent call last)
# &lt;ipython-input-26-22862c1bf06c&gt; in &lt;module&gt;()
# ----&gt; 1 t_m._modules['conv1'].stride

# c:\program files\python35\lib\site-packages\torch\jit\__init__.py in __getattr__(self, attr)
   # 1230             if self._c._has_attribute(attr):
   # 1231                 return self._c._get_attribute(attr)
# -&gt; 1232             return Module.__getattr__(self, attr)
   # 1233 
   # 1234         def __setattr__(self, attr, value):

# c:\program files\python35\lib\site-packages\torch\nn\modules\module.py in __getattr__(self, name)
    # 537                 return modules[name]
    # 538         raise AttributeError("'{}' object has no attribute '{}'".format(
# --&gt; 539             type(self).__name__, name))
    # 540 
    # 541     def __setattr__(self, name, value):

# AttributeError: 'TracedModule' object has no attribute 'stride'

torch.jit.save(t_m, 'traced_resnet18.pt')
reload_t_m = torch.jit.load('traced_resnet18.pt')
reload_t_m._modules['conv1']
#ScriptModule()
reload_t_m._modules['conv1'].stride
---------------------------------------------------------------------------
# AttributeError                            Traceback (most recent call last)
# &lt;ipython-input-31-eae0d5d2cc24&gt; in &lt;module&gt;()
# ----&gt; 1 reload_t_m._modules['conv1'].stride

# c:\program files\python35\lib\site-packages\torch\jit\__init__.py in __getattr__(self, attr)
   # 1230             if self._c._has_attribute(attr):
   # 1231                 return self._c._get_attribute(attr)
# -&gt; 1232             return Module.__getattr__(self, attr)
   # 1233 
   # 1234         def __setattr__(self, attr, value):

# c:\program files\python35\lib\site-packages\torch\nn\modules\module.py in __getattr__(self, name)
    # 537                 return modules[name]
    # 538         raise AttributeError("'{}' object has no attribute '{}'".format(
# --&gt; 539             type(self).__name__, name))
    # 540 
    # 541     def __setattr__(self, name, value):

# AttributeError: 'ScriptModule' object has no attribute 'stride'
</code></pre>

joe8086: <p>And does ScriptModel have api to query module’s input list?</p>

ptrblck: <p>Thanks for the code.<br>
The attributes seems to be indeed hidden and I’m not sure if this is a bug or a feature. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=12" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="joe8086" data-post="4" data-topic="56869" data-full="true">
<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/j/b5e925/48.png" class="avatar"> joe8086:</div>
<blockquote>
<p>And does ScriptModel have api to query module’s input list?</p>
</blockquote>
</aside>
<p>I’m not sure to understand the question completely. Could you give an example?</p>