attention-module icon indicating copy to clipboard operation
attention-module copied to clipboard

How to use : training error

Open gyunggyung opened this issue 5 years ago • 11 comments

try

python train_imagenet.py --ngpu 4 --workers 20 --arch resnet --depth 50 --epochs 100 --batch-size 256 --lr 0.1 --att-type BAM --prefix RESNET50_IMAGENET_BAM ./data/ImageNet

showing error

(pytorch) C:\github\attention-module>python train_imagenet.py --ngpu 4 --workers 20 --arch resnet --depth 50 --epochs 100 --batch-size 256 --lr 0.1 --att-type BAM --prefix RESNET50_IMAGENET_BAM ./data/ImageNet
args Namespace(arch='resnet', att_type='BAM', batch_size=256, data='./data/ImageNet', depth=50, epochs=100, evaluate=False, lr=0.1, momentum=0.9, ngpu=4, prefix='RESNET50_IMAGENET_BAM', print_freq=10, resume='', seed=1234, start_epoch=0, weight_decay=0.0001, workers=20)
Traceback (most recent call last):
  File "train_imagenet.py", line 307, in <module>
    main()
  File "train_imagenet.py", line 73, in main
    model = ResidualNet( 'ImageNet', args.depth, 1000, args.att_type )
  File "C:\github\attention-module\MODELS\model_resnet.py", line 200, in ResidualNet
    model = ResNet(Bottleneck, [3, 4, 6, 3], network_type, num_classes, att_type)
  File "C:\github\attention-module\MODELS\model_resnet.py", line 116, in __init__
    self.bam1 = BAM(64*block.expansion)
  File "C:\github\attention-module\MODELS\bam.py", line 45, in __init__
    self.channel_att = ChannelGate(gate_channel)
  File "C:\github\attention-module\MODELS\bam.py", line 12, in __init__
    self.gate_activation = gate_activation
NameError: name 'gate_activation' is not defined

try

python train_imagenet.py --ngpu 4 --workers 20 --arch resnet --depth 50 --epochs 100 --batch-size 256 --lr 0.1 --att-type CBAM --prefix RESNET50_IMAGENET_CBAM ./data/ImageNet

showing error

(pytorch) C:\github\attention-module>python train_imagenet.py --ngpu 4 --workers 20 --arch resnet --depth 50 --epochs 100 --batch-size 256 --lr 0.1 --att-type CBAM --prefix RESNET50_IMAGENET_CBAM ./data/ImageNet
args Namespace(arch='resnet', att_type='CBAM', batch_size=256, data='./data/ImageNet', depth=50, epochs=100, evaluate=False, lr=0.1, momentum=0.9, ngpu=4, prefix='RESNET50_IMAGENET_CBAM', print_freq=10, resume='', seed=1234, start_epoch=0, weight_decay=0.0001, workers=20)
C:\github\attention-module\MODELS\model_resnet.py:129: UserWarning: nn.init.kaiming_normal is now deprecated in favor of nn.init.kaiming_normal_.
  init.kaiming_normal(self.fc.weight)
C:\github\attention-module\MODELS\model_resnet.py:133: UserWarning: nn.init.kaiming_normal is now deprecated in favor of nn.init.kaiming_normal_.
  init.kaiming_normal(self.state_dict()[key], mode='fan_out')
Traceback (most recent call last):
  File "train_imagenet.py", line 307, in <module>
    main()
  File "train_imagenet.py", line 81, in main
    model = torch.nn.DataParallel(model, device_ids=list(range(args.ngpu)))
  File "C:\Users\admin\.conda\envs\pytorch\lib\site-packages\torch\nn\parallel\data_parallel.py", line 131, in __init__
    _check_balance(self.device_ids)
  File "C:\Users\admin\.conda\envs\pytorch\lib\site-packages\torch\nn\parallel\data_parallel.py", line 18, in _check_balance
    dev_props = [torch.cuda.get_device_properties(i) for i in device_ids]
  File "C:\Users\admin\.conda\envs\pytorch\lib\site-packages\torch\nn\parallel\data_parallel.py", line 18, in <listcomp>
    dev_props = [torch.cuda.get_device_properties(i) for i in device_ids]
  File "C:\Users\admin\.conda\envs\pytorch\lib\site-packages\torch\cuda\__init__.py", line 301, in get_device_properties
    raise AssertionError("Invalid device id")
AssertionError: Invalid device id

What should I do?

gyunggyung avatar Feb 28 '19 12:02 gyunggyung

I have met the same error

zhengqun avatar Mar 28 '19 12:03 zhengqun

Modify the number of gpu. the default is 4 (--ngpu 4 ).

hadonga avatar Apr 25 '19 09:04 hadonga

I still don't know what gate_activation should be

ggsDing avatar Jun 20 '19 13:06 ggsDing

@ggsDing change --ngpu 4 to --ngpu 1

hadonga avatar Jun 20 '19 14:06 hadonga

@hadonga Didn't get it. I was using the code directly. So 'ngpu' is relatted to 'gate_activation' ?

ggsDing avatar Jun 20 '19 14:06 ggsDing

also meet error ‘NameError: name 'gate_activation' is not defined’,Have you solve this problem

Ferrymania avatar Jan 16 '20 09:01 Ferrymania

‘self.gate_activation’ has not been used so you can delete it in bam.py, line 12

wjf5203 avatar Aug 03 '20 12:08 wjf5203

Can you see the error and how to do it: NameError: name 'size0' is not defined

Napoleon7816 avatar Apr 23 '21 14:04 Napoleon7816

Can you see the error and how to do it: NameError: name 'size0' is not defined

same question, do you know how to solve it?

EasonGZY avatar Sep 27 '21 03:09 EasonGZY

You can simply remove this line 'self.gate_activation = gate_activation', as it is not used in the code :D

eslambakr avatar Nov 16 '21 10:11 eslambakr

Can you see the error and how to do it: NameError: name 'size0' is not defined

same question, do you know how to solve it?

Same question, anybody know how to solve it?

Edison-423 avatar May 29 '23 12:05 Edison-423