In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to analyze the use of argparse standard library in pytorch-grad-cam practice. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Code display:
Import torchimport argparsedef get_args (): parser = argparse.ArgumentParser () parser.add_argument ('--use-cuda', action='store_true', default=False,help='Use NVIDIA GPU acceleration') parser.add_argument ('--image-path', type=str, default='./examples/both.png' Help='Input image path') args = parser.parse_args () args.use_cuda = args.use_cuda and torch.cuda.is_available () if args.use_cuda:print ("Using GPU for acceleration") else:print ("Using CPU for computation") return argsargs = get_args () print ("print read information" .center (50 args.use_cuda:', args.use_cuda) print ('args.image_path:') Args.image_path) # python testArgs.py-h # python testArgs.py# python testArgs.py-use-cuda# python testArgs.py-use-cuda-image-path 1.jpg # python testArgs.py-image-path 1.jpg-use-cuda
Display the execution results under the console:
Copyright (C) Windows PowerShell Microsoft Corporation. All rights reserved. It took 943 milliseconds to try a new cross-platform PowerShell https://aka.ms/pscore6 to load personal and system profiles. (base) PS C:\ Users\ chenxuqi\ Desktop\ News4cxq\ test4cxq > conda activate ssd (ssd) PS C:\ Users\ chenxuqi\ Desktop\ News4cxq\ test4cxq > python testArgs.py-husage: testArgs.py [- h] [--use-cuda] [--image-path IMAGE_PATH] optional arguments:-h -- help show this help message and exit-- use-cuda Use NVIDIA GPU acceleration-- image-path IMAGE_PATH (ssd) PS C:\ Users\ chenxuqi\ Desktop\ News4cxq\ test4cxq > python testArgs.pyUsing CPU for computation- print read information-- args.use_cuda: False ( Ssd) PS C:\ Users\ chenxuqi\ Desktop\ News4cxq\ test4cxq > python testArgs.py-- Information read by use-cudaUsing GPU for acceleration- print-- args.use_cuda: Trueargs.image_path:. / examples/both.png (ssd) PS C:\ Users\ chenxuqi\ Desktop\ News4cxq\ test4cxq > python testArgs.py-- image -Information read by path 1.jpgUsing CPU for computation- printing-- args.use_cuda: Falseargs.image_path: 1.jpg (ssd) PS C:\ Users\ chenxuqi\ Desktop\ News4cxq\ test4cxq > python testArgs.py-- use-cuda-- image-path 1.jpgUsing GPU for acceleration- -print read information-- args.use_cuda: Trueargs.image_path: 1.jpg (ssd) PS C:\ Users\ chenxuqi\ Desktop\ News4cxq\ test4cxq > python testArgs.py-- image-path 1.jpg-- use-cudaUsing GPU for acceleration- print read information-- -args.use_cuda: Trueargs.image_path: 1.jpg (ssd) PS C:\ Users\ chenxuqi\ Desktop\ News4cxq\ test4cxq > this is how the analysis of the use of argparse standard library in pytorch-grad-cam practice is shared. I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.