From 1faea372f997e84334f6933b8cced3b77221a2c8 Mon Sep 17 00:00:00 2001 From: Bryce Date: Wed, 17 Apr 2024 20:00:58 -0700 Subject: [PATCH] fix: cleanup logging - remove unnecessary version checks --- docs/changelog.md | 5 -- imaginairy/cli/upscale.py | 12 ++-- imaginairy/enhancers/upscale.py | 5 +- imaginairy/utils/tile_up.py | 18 +++--- imaginairy/vendored/clip/clip.py | 9 +-- requirements-dev.txt | 84 +++++++++++++++------------- tests/test_enhancers/test_upscale.py | 3 +- 7 files changed, 66 insertions(+), 70 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 68a8b8f..6003b50 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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` diff --git a/imaginairy/cli/upscale.py b/imaginairy/cli/upscale.py index aa3d72a..95ce2e7 100644 --- a/imaginairy/cli/upscale.py +++ b/imaginairy/cli/upscale.py @@ -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 @@ -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) @@ -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}" + ) diff --git a/imaginairy/enhancers/upscale.py b/imaginairy/enhancers/upscale.py index e076a34..ca7ba27 100644 --- a/imaginairy/enhancers/upscale.py +++ b/imaginairy/enhancers/upscale.py @@ -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) diff --git a/imaginairy/utils/tile_up.py b/imaginairy/utils/tile_up.py index cc1ec77..4412337 100644 --- a/imaginairy/utils/tile_up.py +++ b/imaginairy/utils/tile_up.py @@ -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): @@ -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 diff --git a/imaginairy/vendored/clip/clip.py b/imaginairy/vendored/clip/clip.py index 197464c..69f41c6 100644 --- a/imaginairy/vendored/clip/clip.py +++ b/imaginairy/vendored/clip/clip.py @@ -8,7 +8,6 @@ from typing import List, Union import torch from PIL import Image -from pkg_resources import packaging from torchvision.transforms import CenterCrop, Compose, Normalize, Resize, ToTensor from tqdm import tqdm @@ -23,9 +22,6 @@ except ImportError: 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() @@ -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: diff --git a/requirements-dev.txt b/requirements-dev.txt index d827529..11f6801 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -14,7 +14,7 @@ anyio==4.3.0 # starlette babel==2.14.0 # via mkdocs-material -build==1.1.1 +build==1.2.1 # via pip-tools certifi==2024.2.2 # via @@ -43,55 +43,57 @@ colorama==0.4.6 # mkdocs-material coverage==7.4.4 # via -r requirements-dev.in -diffusers==0.27.0 +diffusers==0.27.2 # via imaginAIry (setup.py) einops==0.7.0 - # via imaginAIry (setup.py) + # via + # imaginAIry (setup.py) + # spandrel exceptiongroup==1.2.0 # via # anyio # pytest -fastapi==0.110.0 +fastapi==0.110.1 # via imaginAIry (setup.py) -filelock==3.13.1 +filelock==3.13.4 # via # diffusers # huggingface-hub # torch # transformers -fsspec==2024.2.0 +fsspec==2024.3.1 # via # huggingface-hub # torch -ftfy==6.1.3 +ftfy==6.2.0 # via # imaginAIry (setup.py) # open-clip-torch ghp-import==2.1.0 # via mkdocs -griffe==0.42.0 +griffe==0.42.2 # via mkdocstrings-python h11==0.14.0 # via # httpcore # uvicorn -httpcore==1.0.4 +httpcore==1.0.5 # via httpx httpx==0.27.0 # via -r requirements-dev.in -huggingface-hub==0.21.4 +huggingface-hub==0.22.2 # via # diffusers # open-clip-torch # timm # tokenizers # transformers -idna==3.6 +idna==3.7 # via # anyio # httpx # requests -importlib-metadata==7.0.2 +importlib-metadata==7.1.0 # via diffusers iniconfig==2.0.0 # via pytest @@ -105,16 +107,15 @@ jinja2==3.1.3 # torch kornia==0.7.2 # via imaginAIry (setup.py) -kornia-rs==0.1.1 +kornia-rs==0.1.3 # via kornia -markdown==3.5.2 +markdown==3.6 # via # mkdocs # mkdocs-autorefs # mkdocs-click # mkdocs-material # mkdocstrings - # mkdocstrings-python # pymdown-extensions markupsafe==2.1.5 # via @@ -133,15 +134,15 @@ mkdocs-autorefs==1.0.1 # via mkdocstrings mkdocs-click==0.8.1 # via -r requirements-dev.in -mkdocs-material==9.5.13 +mkdocs-material==9.5.18 # via -r requirements-dev.in mkdocs-material-extensions==1.3.1 # via mkdocs-material -mkdocstrings[python]==0.24.1 +mkdocstrings[python]==0.24.3 # via # -r requirements-dev.in # mkdocstrings-python -mkdocstrings-python==1.9.0 +mkdocstrings-python==1.9.2 # via mkdocstrings mpmath==1.3.0 # via sympy @@ -149,7 +150,7 @@ mypy==1.9.0 # via -r requirements-dev.in mypy-extensions==1.0.0 # via mypy -networkx==3.2.1 +networkx==3.3 # via torch numpy==1.24.4 # via @@ -159,6 +160,7 @@ numpy==1.24.4 # jaxtyping # opencv-python # scipy + # spandrel # torchvision # transformers omegaconf==2.3.0 @@ -180,7 +182,7 @@ paginate==0.5.6 # via mkdocs-material pathspec==0.12.1 # via mkdocs -pillow==10.2.0 +pillow==10.3.0 # via # diffusers # imaginAIry (setup.py) @@ -193,17 +195,17 @@ platformdirs==4.2.0 # mkdocstrings pluggy==1.4.0 # via pytest -protobuf==5.26.0 +protobuf==5.26.1 # via # imaginAIry (setup.py) # open-clip-torch psutil==5.9.8 # via imaginAIry (setup.py) -pydantic==2.6.4 +pydantic==2.7.0 # via # fastapi # imaginAIry (setup.py) -pydantic-core==2.16.3 +pydantic-core==2.18.1 # via pydantic pygments==2.17.2 # via mkdocs-material @@ -223,7 +225,7 @@ pytest==8.1.1 # pytest-asyncio # pytest-randomly # pytest-sugar -pytest-asyncio==0.23.5.post1 +pytest-asyncio==0.23.6 # via -r requirements-dev.in pytest-randomly==3.15.0 # via -r requirements-dev.in @@ -243,7 +245,7 @@ pyyaml==6.0.1 # transformers pyyaml-env-tag==0.1 # via mkdocs -regex==2023.12.25 +regex==2024.4.16 # via # diffusers # mkdocs-material @@ -259,15 +261,16 @@ requests==2.31.0 # transformers responses==0.25.0 # via -r requirements-dev.in -ruff==0.3.3 +ruff==0.3.7 # via -r requirements-dev.in -safetensors==0.4.2 +safetensors==0.4.3 # via # diffusers # imaginAIry (setup.py) + # spandrel # timm # transformers -scipy==1.12.0 +scipy==1.13.0 # via # imaginAIry (setup.py) # torchdiffeq @@ -279,7 +282,9 @@ sniffio==1.3.1 # via # anyio # httpx -starlette==0.36.3 +spandrel==0.3.1 + # via imaginAIry (setup.py) +starlette==0.37.2 # via fastapi sympy==1.12 # via torch @@ -300,20 +305,22 @@ tomli==2.0.1 # pip-tools # pyproject-hooks # pytest -torch==2.2.1 +torch==2.2.2 # via # imaginAIry (setup.py) # kornia # open-clip-torch + # spandrel # timm # torchdiffeq # torchvision torchdiffeq==0.2.3 # via imaginAIry (setup.py) -torchvision==0.17.1 +torchvision==0.17.2 # via # imaginAIry (setup.py) # open-clip-torch + # spandrel # timm tqdm==4.66.2 # via @@ -321,19 +328,19 @@ tqdm==4.66.2 # imaginAIry (setup.py) # open-clip-torch # transformers -transformers==4.38.2 +transformers==4.39.3 # via imaginAIry (setup.py) typeguard==2.13.3 # via jaxtyping -types-pillow==10.2.0.20240311 +types-pillow==10.2.0.20240415 # via -r requirements-dev.in -types-psutil==5.9.5.20240311 +types-psutil==5.9.5.20240316 # via -r requirements-dev.in -types-requests==2.31.0.20240311 +types-requests==2.31.0.20240406 # via -r requirements-dev.in -types-tqdm==4.66.0.20240106 +types-tqdm==4.66.0.20240417 # via -r requirements-dev.in -typing-extensions==4.10.0 +typing-extensions==4.11.0 # via # anyio # fastapi @@ -341,6 +348,7 @@ typing-extensions==4.10.0 # mypy # pydantic # pydantic-core + # spandrel # torch # uvicorn urllib3==2.2.1 @@ -348,7 +356,7 @@ urllib3==2.2.1 # requests # responses # types-requests -uvicorn==0.28.0 +uvicorn==0.29.0 # via imaginAIry (setup.py) watchdog==4.0.0 # via mkdocs diff --git a/tests/test_enhancers/test_upscale.py b/tests/test_enhancers/test_upscale.py index 3fe50c1..350ba60 100644 --- a/tests/test_enhancers/test_upscale.py +++ b/tests/test_enhancers/test_upscale.py @@ -21,6 +21,7 @@ def test_upscale_cmd_format_option(): mock_img = Mock() mock_img.save = Mock() + mock_img.height = 1000 with patch.multiple( "imaginairy.enhancers.upscale", upscale_image=Mock(return_value=mock_img) @@ -38,5 +39,5 @@ def test_upscale_cmd_format_option(): ) assert result.exit_code == 0 - assert "Saved to " in result.output + assert "saved to " in result.output mock_img.save.assert_called() # Check if save method was called