Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tqdm for tile count progress #563

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion inference_realesrgan_video.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ def inference_video(args, video_save_path, device=None, total_workers=1, worker_
model_path = [model_path, wdn_model_path]
dni_weight = [args.denoise_strength, 1 - args.denoise_strength]

pbar = tqdm(unit='frame', desc='inference')
if args.tile > 0:
pbar_single_frame = tqdm(unit='tile', desc='current frame')
else:
pbar_single_frame = None

# restorer
upsampler = RealESRGANer(
scale=netscale,
Expand All @@ -228,6 +234,7 @@ def inference_video(args, video_save_path, device=None, total_workers=1, worker_
pre_pad=args.pre_pad,
half=not args.fp32,
device=device,
pbar=pbar_single_frame,
)

if 'anime' in args.model_name and args.face_enhance:
Expand All @@ -252,7 +259,8 @@ def inference_video(args, video_save_path, device=None, total_workers=1, worker_
fps = reader.get_fps()
writer = Writer(args, audio, height, width, video_save_path, fps)

pbar = tqdm(total=len(reader), unit='frame', desc='inference')
pbar.reset(total=len(reader))

while True:
img = reader.get_frame()
if img is None:
Expand Down
13 changes: 11 additions & 2 deletions realesrgan/utils.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import torch
from basicsr.utils.download_util import load_file_from_url
from torch.nn import functional as F
from tqdm import tqdm

ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand Down Expand Up @@ -36,13 +37,15 @@ def __init__(self,
pre_pad=10,
half=False,
device=None,
gpu_id=None):
gpu_id=None,
pbar=None):
self.scale = scale
self.tile_size = tile
self.tile_pad = tile_pad
self.pre_pad = pre_pad
self.mod_scale = None
self.half = half
self.pbar = pbar

# initialize model
if gpu_id:
Expand Down Expand Up @@ -130,6 +133,11 @@ def tile_process(self):
tiles_x = math.ceil(width / self.tile_size)
tiles_y = math.ceil(height / self.tile_size)

if self.pbar is None and tiles_x*tiles_y>1:
self.pbar = tqdm(total=tiles_x*tiles_y, unit='tile', desc='current frame')
elif self.pbar is not None:
self.pbar.reset(total=tiles_x*tiles_y)

# loop over all tiles
for y in range(tiles_y):
for x in range(tiles_x):
Expand Down Expand Up @@ -160,7 +168,8 @@ def tile_process(self):
output_tile = self.model(input_tile)
except RuntimeError as error:
print('Error', error)
print(f'\tTile {tile_idx}/{tiles_x * tiles_y}')
if self.pbar is not None and tiles_x*tiles_y>1:
self.pbar.update(1)

# output tile area on total image
output_start_x = input_start_x * self.scale
Expand Down