Home > other >  Argparse repository for GPU id for answers
Argparse repository for GPU id for answers

Time:12-29

 

The import argparse


Def parse_args () :
Parser=argparse. ArgumentParser ()
Parser. Add_argument (' - the gpu, type=STR, dest='gpu_ids')
Parser. Add_argument (' - test_epoch 'type=STR, dest=' test_epoch ')
Args=parser. Parse_args ()

# test gpus
If not the args. Gpu_ids:
Assert 0, print (" both Please set the proper gpu ids ")

If the '-' in the args. Gpu_ids:
Gpus=args. Gpu_ids. Split (' - ')
Gpus [0]=int (gpus [0])
Gpus [1]=int (gpus [1]) + 1
Args. Gpu_ids=', '. Join (map (lambda x: STR (x), a list (range (* gpus))))

Assert the args. Test_epoch, 'Test epoch is required.'
Return the args
Parse_args ()



The output is:
Both Please set the proper gpu ids
Traceback (the most recent call last) :
The File "C: \ Users \ user \ Desktop \ TMP \ test py", line 22, in & lt; module>
Parse_args ()
The File "C: \ Users \ user \ Desktop \ TMP \ test. Py", line 12, in parse_args
Assert 0, print (" both Please set the proper gpu ids ")
AssertionError: None



Why cry
  • Related