Skip to content

Commit

Permalink
fix: cleanup logging output
Browse files Browse the repository at this point in the history
  • Loading branch information
brycedrennan committed Apr 18, 2024
1 parent 69b90ec commit e6ec063
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
5 changes: 0 additions & 5 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

- feature: integrates spandrel for upscaling

**14.1.1**

- tests: add installation tests for windows, mac, and conda
- fix: dependency issues

**14.2.0**
- 🎉 feature: add image prompt support via `--image-prompt` and `--image-prompt-strength`

Expand Down
12 changes: 7 additions & 5 deletions imaginairy/cli/upscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def upscale_cmd(
"""
Upscale an image 4x using AI.
"""
from tqdm import tqdm

from imaginairy.enhancers.face_restoration_codeformer import enhance_faces
from imaginairy.enhancers.upscale import upscale_image, upscale_model_lookup
Expand Down Expand Up @@ -92,15 +91,15 @@ def upscale_cmd(
elif format_template == "DEFAULT":
format_template = DEFAULT_FORMAT_TEMPLATE

for p in tqdm(image_filepaths):
savepath = os.path.join(outdir, os.path.basename(p))
for n, p in enumerate(image_filepaths):
if p.startswith("http"):
img = LazyLoadingImage(url=p)
else:
img = LazyLoadingImage(filepath=p)
orig_height = img.height
for model in upscale_model:
logger.info(
f"Upscaling {p} from {img.width}x{img.height} to {img.width * 4}x{img.height * 4} and saving it to {savepath}"
f"Upscaling ({n + 1}/{len(image_filepaths)}) {p} ({img.width}x{img.height})..."
)

img = upscale_image(img, model)
Expand Down Expand Up @@ -131,4 +130,7 @@ def upscale_cmd(
new_file_name = format_filename(format_template, new_file_name_data)
new_file_path = os.path.join(outdir, new_file_name)
img.save(new_file_path)
print(f"Saved to {new_file_path}")
scale = int(img.height / orig_height)
logger.info(
f"Upscaled {scale}x to {img.width}x{img.height} and saved to {new_file_path}"
)
5 changes: 1 addition & 4 deletions imaginairy/enhancers/upscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ def upscale_image(
model_path = upscaler_model

model = ModelLoader().load_from_file(model_path)
logger.info(
f"Upscaling from {img.width}x{img.height} to {img.width * model.scale}x{img.height * model.scale}"
)
print(f"Upscaling image with model {model.architecture}@{upscaler_model}")
logger.debug(f"Upscaling image with model {model.architecture}@{upscaler_model}")

assert isinstance(model, ImageModelDescriptor)

Expand Down
18 changes: 9 additions & 9 deletions imaginairy/utils/tile_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def tile_process(
output = img.new_zeros(output_shape)
tiles_x = math.ceil(width / tile_size)
tiles_y = math.ceil(height / tile_size)
logger.info(f"Tiling with {tiles_x}x{tiles_y} ({tiles_x*tiles_y}) tiles")
logger.debug(f"Tiling with {tiles_x}x{tiles_y} ({tiles_x*tiles_y}) tiles")

for y in range(tiles_y):
for x in range(tiles_x):
Expand Down Expand Up @@ -79,13 +79,13 @@ def tile_process(
)

# Place the processed tile in the output image
output[
:, :, output_start_y:output_end_y, output_start_x:output_end_x
] = output_tile[
:,
:,
tile_output_start_y:tile_output_end_y,
tile_output_start_x:tile_output_end_x,
]
output[:, :, output_start_y:output_end_y, output_start_x:output_end_x] = (
output_tile[
:,
:,
tile_output_start_y:tile_output_end_y,
tile_output_start_x:tile_output_end_x,
]
)

return output

0 comments on commit e6ec063

Please sign in to comment.