to parse the CLI parameters. The documentation mentions that this CLI flag should be used to tell the code "whether to run on GPU or cpu".
However argparse does not work that way: When --use-cuda is specified, it will store True but if the user omits the flag, default=True kicks in and sets use_cuda := True.
To make the parameter work as intended I see the following options:
use default=False with the consequence that cuda will be off by default which is likely not what you want.
parser.add_argument('--use-cuda', nargs='?', default=True, help='Enable CUDA') and add some custom code to convert str inputs like "False" to a boolean value (example from StackOverflow).
On top of that at least the torch/resnet code uses .cuda() unconditionally so the user setting will not have an effect anyway. I think the cleanest solution would be to pass a device parameter from the script to ResNet.
Currently the code 1 uses
to parse the CLI parameters. The documentation mentions that this CLI flag should be used to tell the code "whether to run on GPU or cpu".
However
argparse
does not work that way: When--use-cuda
is specified, it will storeTrue
but if the user omits the flag,default=True
kicks in and setsuse_cuda := True
.To make the parameter work as intended I see the following options:
default=False
with the consequence that cuda will be off by default which is likely not what you want.parser.add_argument('--use-cuda', nargs='?', default=True, help='Enable CUDA')
and add some custom code to convertstr
inputs like"False"
to a boolean value (example from StackOverflow).On top of that at least the torch/resnet code uses
.cuda()
unconditionally so the user setting will not have an effect anyway. I think the cleanest solution would be to pass adevice
parameter from the script toResNet
.