温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

argparse标准库在pytorch-grad-cam实战中的使用分析是怎样的

发布时间:2021-12-04 15:53:33 来源:亿速云 阅读:154 作者:柒染 栏目:大数据

这篇文章给大家介绍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实战中的使用分析是怎样的就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI