Hi Friends,
I use traced_model._modules[‘conv1’] to access conv module.
But how can I find ‘stride’ info in it?
Thanks,
8086
Hi Friends,
I use traced_model._modules[‘conv1’] to access conv module.
But how can I find ‘stride’ info in it?
Thanks,
8086
Would print(traced_model._modules['conv1'].stride)
work?
Thanks ptrblck, that’s a good guide.
But I did try still fail.
I want to able to access these fields after load traced file.
My test environment is at Windows pytorch 1.1.0
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)
# <ipython-input-26-22862c1bf06c> in <module>()
# ----> 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)
# -> 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(
# --> 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)
# <ipython-input-31-eae0d5d2cc24> in <module>()
# ----> 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)
# -> 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(
# --> 539 type(self).__name__, name))
# 540
# 541 def __setattr__(self, name, value):
# AttributeError: 'ScriptModule' object has no attribute 'stride'
And does ScriptModel have api to query module’s input list?
Thanks for the code.
The attributes seems to be indeed hidden and I’m not sure if this is a bug or a feature.
I’m not sure to understand the question completely. Could you give an example?