PyTorch 报错:TypeError: exceptions must derive from BaseException

简介: PyTorch 报错:TypeError: exceptions must derive from BaseException

项目场景:


PyTorch 报错:TypeError: exceptions must derive from BaseException


其实是个低级错误,我个人认为是因为没有找到要运行的载体。


问题描述


在 base_options.py 里面设置 --netG 的参数只能在这几个里面选择:


self.parser.add_argument('--netG', type=str, default='p2hed', choices=['p2hed', 'refineD', 'p2hed_att'], help='selects model to use for netG')


但是在选择 netG 时的代码写成了:


def define_G(input_nc, output_nc, ngf, netG, n_downsample_global=3, n_blocks_global=9, n_local_enhancers=1, 
             n_blocks_local=3, norm='instance', gpu_ids=[]):    
    norm_layer = get_norm_layer(norm_type=norm)     
    if netG == 'p2hed':    
        netG = DDNet_p2hED(input_nc, output_nc, ngf, n_downsample_global, n_blocks_global, norm_layer)
    elif netG == 'refineDepth':
        netG = DDNet_RefineDepth(input_nc, output_nc, ngf, n_downsample_global, n_blocks_global, n_local_enhancers, n_blocks_local, norm_layer)
    elif netG == 'p2h_noatt':        
        netG = DDNet_p2hed_noatt(input_nc, output_nc, ngf, n_downsample_global, n_blocks_global, n_local_enhancers, n_blocks_local, norm_layer)
    else:
        raise('generator not implemented!')
    #print(netG)
    if len(gpu_ids) > 0:
        assert(torch.cuda.is_available())   
        netG.cuda(gpu_ids[0])
    netG.apply(weights_init)
    return netG


原因分析:


注意,没有 ‘rfineD’ 这个选项,所以当运行代码时,程序找不到 netG 该选择那个网络,故而报错。


解决方案:


其实,把上面那个代码里面的  “ elif netG == 'refineDepth': ” 改成 “elif netG == 'refineD':” 就可以了。

目录
相关文章
|
PyTorch 算法框架/工具 Python
AttributeError: module ‘distutils‘ has no attribute ‘version‘解决跑pytorch代码报错
AttributeError: module ‘distutils‘ has no attribute ‘version‘解决跑pytorch代码报错
|
PyTorch 算法框架/工具 C++
导入pytorch报错:Redistributable is not installed...安装vc_redist.x64.exe报错:Error 1402:Could not open key..
导入pytorch报错:Redistributable is not installed...安装vc_redist.x64.exe报错:Error 1402:Could not open key..
导入pytorch报错:Redistributable is not installed...安装vc_redist.x64.exe报错:Error 1402:Could not open key..
|
并行计算 PyTorch 算法框架/工具
离线下载安装PyTorch的不报错方法
离线下载安装PyTorch的不报错方法
|
PyTorch 算法框架/工具
Pytorch报错:AttributeError: ‘version_info‘ object has no attribute ‘__version__‘
Pytorch报错:AttributeError: ‘version_info‘ object has no attribute ‘__version__‘
313 0
|
PyTorch 算法框架/工具
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
1013 0
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
|
PyTorch 算法框架/工具
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
已经安装pytorch但是报错No module named ‘torch‘
1251 0
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
|
数据可视化 PyTorch 算法框架/工具
Pychram Pytorch Tensorboard 报错 “No dashboards are active for the current data set.“ 解决方案
Pychram Pytorch Tensorboard 报错 “No dashboards are active for the current data set.“ 解决方案
Pychram Pytorch Tensorboard 报错 “No dashboards are active for the current data set.“ 解决方案
|
编解码 算法 PyTorch
解决方案:炼丹师养成计划 Pytorch+DeepLearning遇见的各种报错与踩坑避坑记录(二)
解决方案:炼丹师养成计划 Pytorch+DeepLearning遇见的各种报错与踩坑避坑记录(二)
解决方案:炼丹师养成计划 Pytorch+DeepLearning遇见的各种报错与踩坑避坑记录(二)
|
并行计算 异构计算
解决方案:炼丹师养成计划 Pytorch+DeepLearning遇见的各种报错与踩坑避坑记录(一)
解决方案:炼丹师养成计划 Pytorch+DeepLearning遇见的各种报错与踩坑避坑记录(一)
|
4月前
|
机器学习/深度学习 PyTorch API
PyTorch量化感知训练技术:模型压缩与高精度边缘部署实践
本文深入探讨神经网络模型量化技术,重点讲解训练后量化(PTQ)与量化感知训练(QAT)两种主流方法。PTQ通过校准数据集确定量化参数,快速实现模型压缩,但精度损失较大;QAT在训练中引入伪量化操作,使模型适应低精度环境,显著提升量化后性能。文章结合PyTorch实现细节,介绍Eager模式、FX图模式及PyTorch 2导出量化等工具,并分享大语言模型Int4/Int8混合精度实践。最后总结量化最佳策略,包括逐通道量化、混合精度设置及目标硬件适配,助力高效部署深度学习模型。
613 21
PyTorch量化感知训练技术:模型压缩与高精度边缘部署实践

热门文章

最新文章

推荐镜像

更多