重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
這篇文章給大家介紹argparse標準庫在pytorch-grad-cam實戰中的使用分析是怎樣的,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
在長順等地區,都構建了全面的區域性戰略布局,加強發展的系統性、市場前瞻性、產品創新能力,以專注、極致的服務理念,為客戶提供成都做網站、網站建設 網站設計制作按需策劃設計,公司網站建設,企業網站建設,品牌網站制作,全網整合營銷推廣,外貿網站建設,長順網站建設費用合理。
代碼展示:
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 args args = get_args()print("打印讀取的信息".center(50,'-'))print('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
控制臺下執行結果展示:
Windows PowerShell 版權所有 (C) Microsoft Corporation。保留所有權利。 嘗試新的跨平臺 PowerShell https://aka.ms/pscore6 加載個人及系統配置文件用了 943 毫秒。(base) PS C:\Users\chenxuqi\Desktop\News4cxq\test4cxq> conda activate ssd(ssd) PS C:\Users\chenxuqi\Desktop\News4cxq\test4cxq> python testArgs.py -h usage: 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---------------------打印讀取的信息----------------------args.use_cuda: False(ssd) PS C:\Users\chenxuqi\Desktop\News4cxq\test4cxq> python testArgs.py --use-cudaUsing GPU for acceleration---------------------打印讀取的信息----------------------args.use_cuda: True args.image_path: ./examples/both.png(ssd) PS C:\Users\chenxuqi\Desktop\News4cxq\test4cxq> python testArgs.py --image-path 1.jpgUsing CPU for computation---------------------打印讀取的信息----------------------args.use_cuda: False args.image_path: 1.jpg(ssd) PS C:\Users\chenxuqi\Desktop\News4cxq\test4cxq> python testArgs.py --use-cuda --image-path 1.jpgUsing GPU for acceleration---------------------打印讀取的信息----------------------args.use_cuda: True args.image_path: 1.jpg(ssd) PS C:\Users\chenxuqi\Desktop\News4cxq\test4cxq> python testArgs.py --image-path 1.jpg --use-cudaUsing GPU for acceleration---------------------打印讀取的信息----------------------args.use_cuda: True args.image_path: 1.jpg(ssd) PS C:\Users\chenxuqi\Desktop\News4cxq\test4cxq>
關于argparse標準庫在pytorch-grad-cam實戰中的使用分析是怎樣的就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。