catch more specific errors

This commit is contained in:
Xintao
2021-11-24 00:14:05 +08:00
parent 35ee6f781e
commit 7dd860a881
4 changed files with 4 additions and 4 deletions

View File

@@ -94,7 +94,7 @@ def main():
_, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
else:
output, _ = upsampler.enhance(img, outscale=args.outscale)
except Exception as error:
except RuntimeError as error:
print('Error', error)
print('If you encounter CUDA out of memory, try to set --tile with a smaller number.')
else:

View File

@@ -92,7 +92,7 @@ class RealESRGANDataset(data.Dataset):
while retry > 0:
try:
img_bytes = self.file_client.get(gt_path, 'gt')
except Exception as e:
except (IOError, OSError) as e:
logger = get_root_logger()
logger.warn(f'File client error: {e}, remaining retry times: {retry - 1}')
# change another file to read

View File

@@ -128,7 +128,7 @@ class RealESRGANer():
try:
with torch.no_grad():
output_tile = self.model(input_tile)
except Exception as error:
except RuntimeError as error:
print('Error', error)
print(f'\tTile {tile_idx}/{tiles_x * tiles_y}')

View File

@@ -14,7 +14,7 @@ def main(args):
# read the image once for check, as some images may have errors
try:
img = cv2.imread(img_path)
except Exception as error:
except (IOError, OSError) as error:
print(f'Read {img_path} error: {error}')
status = False
if img is None: