samaonline / Orthogonal-Convolutional-Neural-Networks

Code for paper "Orthogonal Convolutional Neural Networks".
MIT License
113 stars 13 forks source link

What's the reason of AttributeError: 'ResNet' object has no attribute 'module'? #11

Open YeeHoran opened 2 years ago

YeeHoran commented 2 years ago

Dear friends,

I encountered the following error when debugging "main_orth18.py", so what's the problem causing this error, please? Thank you in advance!

File "/home/yihuo/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1196, in getattr raise AttributeError("'{}' object has no attribute '{}'".format(

AttributeError: 'ResNet' object has no attribute 'module'

yubeic commented 2 years ago

If you are not using data-parallel training, then the network would not have a module. I hope this helps!

On Sun, Feb 6, 2022 at 10:15 PM YeeHoran @.***> wrote:

Dear friends,

I encountered the following error when debugging "main_orth18.py", so what's the problem causing this error, please? Thank you in advance!

File "/home/yihuo/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1196, in getattr raise AttributeError("'{}' object has no attribute '{}'".format(

AttributeError: 'ResNet' object has no attribute 'module'

— Reply to this email directly, view it on GitHub https://github.com/samaonline/Orthogonal-Convolutional-Neural-Networks/issues/11, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZV6HM4RJKT7GNUEHFFHHLUZ42NTANCNFSM5NWIJRVA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.*** com>

YeeHoran commented 2 years ago

If you are not using data-parallel training, then the network would not have a module. I hope this helps! Dear yubeic,

Thank you very much for your reply! In fact, I use only one GPU, so it does not use data-parrallel training, so I should replace the section of

    diff = utils.orth_dist(model.module.layer2[0].downsample[0].weight) + utils.orth_dist(model.module.layer3[0].downsample[0].weight) + utils.orth_dist(model.module.layer4[0].downsample[0].weight)
    diff += utils.deconv_orth_dist(model.module.layer1[0].conv1.weight, stride=1) + utils.deconv_orth_dist(model.module.layer1[1].conv1.weight, stride=1)
    diff += utils.deconv_orth_dist(model.module.layer2[0].conv1.weight, stride=2) + utils.deconv_orth_dist(model.module.layer2[1].conv1.weight, stride=1)
    diff += utils.deconv_orth_dist(model.module.layer3[0].conv1.weight, stride=2) + utils.deconv_orth_dist(model.module.layer3[1].conv1.weight, stride=1)
    diff += utils.deconv_orth_dist(model.module.layer4[0].conv1.weight, stride=2) + utils.deconv_orth_dist(model.module.layer4[1].conv1.weight, stride=1)
    #####

by

    diff = utils.orth_dist(model.layer2[0].downsample[0].weight) + utils.orth_dist(model.layer3[0].downsample[0].weight) + utils.orth_dist(model.layer4[0].downsample[0].weight)
    diff += utils.deconv_orth_dist(model.layer1[0].conv1.weight, stride=1) + utils.deconv_orth_dist(model.layer1[1].conv1.weight, stride=1)
    diff += utils.deconv_orth_dist(model.layer2[0].conv1.weight, stride=2) + utils.deconv_orth_dist(model.layer2[1].conv1.weight, stride=1)
    diff += utils.deconv_orth_dist(model.layer3[0].conv1.weight, stride=2) + utils.deconv_orth_dist(model.layer3[1].conv1.weight, stride=1)
    diff += utils.deconv_orth_dist(model.layer4[0].conv1.weight, stride=2) + utils.deconv_orth_dist(model.layer4[1].conv1.weight, stride=1)
    #####

, which delete the "module", is this correct, please? Thank you!

On Sun, Feb 6, 2022 at 10:15 PM YeeHoran @.> wrote: Dear friends, I encountered the following error when debugging "main_orth18.py", so what's the problem causing this error, please? Thank you in advance! File "/home/yihuo/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1196, in getattr raise AttributeError("'{}' object has no attribute '{}'".format( AttributeError: 'ResNet' object has no attribute 'module' — Reply to this email directly, view it on GitHub <#11>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZV6HM4RJKT7GNUEHFFHHLUZ42NTANCNFSM5NWIJRVA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you are subscribed to this thread.Message ID: @. com>

YeeHoran commented 2 years ago

Dear,

After I modified the codes according the above method, it didn't report error, Thank you!

But, I encountered another error:

File "/home/yihuo/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 686, in return self._apply(lambda t: t.cuda(device))

RuntimeError: CUDA error: out of memory CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

I check the error on Internet and found someone add contiguous() method in the code which became "correct_k = correct[:k].contiguous().view(-1).float().sum(0, keepdim=True)".

I did it in this way and it didn't report error any more, but is the logic correct, please?

Thank you in advance!

YeeHoran