I traning ConvNet on single 3080Ti, it return such a error AttributeError: ‘DataParallel’ object has no attribute ‘features’;I check the doc of pytorch that indeed the DataParallel object dont have feature attribute,so why code have it?
Traceback (most recent call last):
File “/home/zhongwei/Desktop/code/DataDAM-main/main_DataDAM.py”, line 374, in
main()
File “/home/zhongwei/Desktop/code/DataDAM-main/main_DataDAM.py”, line 302, in main
hooks = attach_hooks(net)
File “/home/zhongwei/Desktop/code/DataDAM-main/main_DataDAM.py”, line 179, in attach_hooks
print(“base:”, base.features.class)
File “/home/zhongwei/anaconda3/envs/DataDAM/lib/python3.9/site-packages/torch/nn/modules/module.py”, line 1709, in getattr
raise AttributeError(f”‘{type(self).name}’ object has no attribute ‘{name}'”)
AttributeError: ‘DataParallel’ object has no attribute ‘features’
base: <class ‘torch.nn.parallel.data_parallel.DataParallel’>
base: DataParallel
`
def attach_hooks(net):
hooks = []
base = net.module if torch.cuda.device_count() > 1 else net
'''bug here'''
print("base:",base.__class__)
print("base:",base.__class__.__name__)
print("base:", base.features.__class__)
print("base:", base.features.__class__.__name__)
print("base:", base.features.named_modules().__class__)
print("base:", base.features.named_modules().__class__.__name__)
for module in (base.features.named_modules()):
print(module.__class__)
print(module.__class__.__name__)
if isinstance(module[1], nn.ReLU):
# Hook the Ouptus of a ReLU Layer
hooks.append(base.features[int(module[0])].register_forward_hook(getActivation('ReLU_'+str(len(hooks)))))
return hooks`
I try check the details of the DataParallel,and print some infomation