Skip to content

Commit

Permalink
fix: cleanup logging - remove unnecessary version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
brycedrennan committed Apr 18, 2024
1 parent cc79cac commit 1faea37
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 70 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
9 changes: 1 addition & 8 deletions imaginairy/vendored/clip/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import torch
from PIL import Image
from pkg_resources import packaging
from torchvision.transforms import CenterCrop, Compose, Normalize, Resize, ToTensor
from tqdm import tqdm

Expand All @@ -23,9 +22,6 @@
BICUBIC = Image.BICUBIC


if packaging.version.parse(torch.__version__) < packaging.version.parse("1.7.1"):
warnings.warn("PyTorch version 1.7.1 or higher is recommended")


__all__ = ["available_models", "load", "tokenize"]
_tokenizer = _Tokenizer()
Expand Down Expand Up @@ -272,10 +268,7 @@ def tokenize(
sot_token = _tokenizer.encoder["<|startoftext|>"]
eot_token = _tokenizer.encoder["<|endoftext|>"]
all_tokens = [[sot_token] + _tokenizer.encode(text) + [eot_token] for text in texts]
if packaging.version.parse(torch.__version__) < packaging.version.parse("1.8.0"):
result = torch.zeros(len(all_tokens), context_length, dtype=torch.long)
else:
result = torch.zeros(len(all_tokens), context_length, dtype=torch.int)
result = torch.zeros(len(all_tokens), context_length, dtype=torch.int)

for i, tokens in enumerate(all_tokens):
if len(tokens) > context_length:
Expand Down
Loading

0 comments on commit 1faea37

Please sign in to comment.