Project scenario:
PyTorch reports an error: TypeError: exceptions must deliver from BaseException
Problem description
In base_options.py, set the –netG parameters to be selected only from these.
self.parser.add_argument('--netG', type=str, default='p2hed', choices=['p2hed', 'refineD', 'p2hed_att'], help='selects model to use for netG')
However, when selecting netG, the code is written as follows:
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
Cause analysis:
Note that there is no option of ‘rfineD’, so when running the code, the program cannot find the network that netG should select, so it reports an error.
Solution:
In fact, change the “elif netG==’refineDepth’:” to “elif netG==’refineD’:”. it will be OK!
Read More:
- [CUDA Environment] Python Pytorch Error: CudaSetupArgument
- Pytorch directly creates a tensor on the GPU error [How to Solve]
- Pytorch Error: runtimeerror: expected scalar type double but found float
- pytorch model.load_state_dict Error [How to Solve]
- pytorch RuntimeError: Error(s) in loading state_ Dict for dataparall… Import model error solution
- pytorch: RuntimeError CUDA error device-side assert triggered
- [Pytorch Error Solution] Pytorch distributed RuntimeError: Address already in use
- Pytorch ValueError: Expected more than 1 value per channel when training, got input size [1, 768
- [Solved] Django.core.exceptions.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.7.17).
- [Solved] Pytorch Error: RuntimeError: Error(s) in loading state_dict for Network: size mismatch
- [Solved] Selenium.common.exceptions.WebDriverException: Message: newSession
- Pytorch CUDA Error: UserWarning: CUDA initialization: CUDA unknown error…
- [Solved] django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.Did you install mysqlclie
- [Solved] D2lzh_Pytorch Import error: importerror: DLL load failed while importing
- [Solved] pytorch loss.backward() Error: RuntimeError: Function AddBackward0 returned an invalid gradient at index 1…
- [Solved] PyTorch Lightning Error: KeyError: ‘hidden_states‘
- [Solved] socketio.exceptions.ConnectionError: OPEN packet not returned by server
- Pytorch Error: RuntimeError: value cannot be converted to type float without overflow: (0.00655336,-0.00
- MySQLdb._exceptions.ProgrammingError appears when scrapy crawls Weibo hot comments
- Pytorch Run Error: BrokenPipeError [How to Solve]