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 算法框架/工具
离线下载安装PyTorch的不报错方法
离线下载安装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报错:AttributeError: ‘version_info‘ object has no attribute ‘__version__‘
Pytorch报错:AttributeError: ‘version_info‘ object has no attribute ‘__version__‘
263 0
|
PyTorch 算法框架/工具
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
890 0
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
|
PyTorch 算法框架/工具
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
已经安装pytorch但是报错No module named ‘torch‘
1066 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遇见的各种报错与踩坑避坑记录(一)
|
30天前
|
机器学习/深度学习 JavaScript PyTorch
9个主流GAN损失函数的数学原理和Pytorch代码实现:从经典模型到现代变体
生成对抗网络(GAN)的训练效果高度依赖于损失函数的选择。本文介绍了经典GAN损失函数理论,并用PyTorch实现多种变体,包括原始GAN、LS-GAN、WGAN及WGAN-GP等。通过分析其原理与优劣,如LS-GAN提升训练稳定性、WGAN-GP改善图像质量,展示了不同场景下损失函数的设计思路。代码实现覆盖生成器与判别器的核心逻辑,为实际应用提供了重要参考。未来可探索组合优化与自适应设计以提升性能。
104 7
9个主流GAN损失函数的数学原理和Pytorch代码实现:从经典模型到现代变体

热门文章

最新文章

下一篇
oss创建bucket