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':” 就可以了。

目录
相关文章
|
11月前
|
PyTorch 算法框架/工具 Python
AttributeError: module ‘distutils‘ has no attribute ‘version‘解决跑pytorch代码报错
AttributeError: module ‘distutils‘ has no attribute ‘version‘解决跑pytorch代码报错
|
并行计算 PyTorch 算法框架/工具
离线下载安装PyTorch的不报错方法
离线下载安装PyTorch的不报错方法
|
PyTorch 算法框架/工具
Pytorch报错:AttributeError: ‘version_info‘ object has no attribute ‘__version__‘
Pytorch报错:AttributeError: ‘version_info‘ object has no attribute ‘__version__‘
143 0
|
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但是报错No module named ‘torch‘
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
624 0
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
|
PyTorch 算法框架/工具
【pytorch问题】已经安装pytorch但是报错No module named ‘torch‘
已经安装pytorch但是报错No module named ‘torch‘
556 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遇见的各种报错与踩坑避坑记录(一)
|
1月前
|
机器学习/深度学习 PyTorch 算法框架/工具
【从零开始学习深度学习】26.卷积神经网络之AlexNet模型介绍及其Pytorch实现【含完整代码】
【从零开始学习深度学习】26.卷积神经网络之AlexNet模型介绍及其Pytorch实现【含完整代码】