fix: cleanup logging - remove unnecessary version checks

This commit is contained in:
Bryce 2024-04-17 20:00:58 -07:00 committed by Bryce Drennan
parent cc79cac5fc
commit 1faea372f9
7 changed files with 66 additions and 70 deletions

View File

@ -4,11 +4,6 @@
- feature: integrates spandrel for upscaling - feature: integrates spandrel for upscaling
**14.1.1**
- tests: add installation tests for windows, mac, and conda
- fix: dependency issues
**14.2.0** **14.2.0**
- 🎉 feature: add image prompt support via `--image-prompt` and `--image-prompt-strength` - 🎉 feature: add image prompt support via `--image-prompt` and `--image-prompt-strength`

View File

@ -62,7 +62,6 @@ def upscale_cmd(
""" """
Upscale an image 4x using AI. Upscale an image 4x using AI.
""" """
from tqdm import tqdm
from imaginairy.enhancers.face_restoration_codeformer import enhance_faces from imaginairy.enhancers.face_restoration_codeformer import enhance_faces
from imaginairy.enhancers.upscale import upscale_image, upscale_model_lookup from imaginairy.enhancers.upscale import upscale_image, upscale_model_lookup
@ -92,15 +91,15 @@ def upscale_cmd(
elif format_template == "DEFAULT": elif format_template == "DEFAULT":
format_template = DEFAULT_FORMAT_TEMPLATE format_template = DEFAULT_FORMAT_TEMPLATE
for p in tqdm(image_filepaths): for n, p in enumerate(image_filepaths):
savepath = os.path.join(outdir, os.path.basename(p))
if p.startswith("http"): if p.startswith("http"):
img = LazyLoadingImage(url=p) img = LazyLoadingImage(url=p)
else: else:
img = LazyLoadingImage(filepath=p) img = LazyLoadingImage(filepath=p)
orig_height = img.height
for model in upscale_model: for model in upscale_model:
logger.info( 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) 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_name = format_filename(format_template, new_file_name_data)
new_file_path = os.path.join(outdir, new_file_name) new_file_path = os.path.join(outdir, new_file_name)
img.save(new_file_path) 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}"
)

View File

@ -69,10 +69,7 @@ def upscale_image(
model_path = upscaler_model model_path = upscaler_model
model = ModelLoader().load_from_file(model_path) model = ModelLoader().load_from_file(model_path)
logger.info( logger.debug(f"Upscaling image with model {model.architecture}@{upscaler_model}")
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}")
assert isinstance(model, ImageModelDescriptor) assert isinstance(model, ImageModelDescriptor)

View File

@ -40,7 +40,7 @@ def tile_process(
output = img.new_zeros(output_shape) output = img.new_zeros(output_shape)
tiles_x = math.ceil(width / tile_size) tiles_x = math.ceil(width / tile_size)
tiles_y = math.ceil(height / 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 y in range(tiles_y):
for x in range(tiles_x): for x in range(tiles_x):
@ -79,13 +79,13 @@ def tile_process(
) )
# Place the processed tile in the output image # Place the processed tile in the output image
output[ output[:, :, output_start_y:output_end_y, output_start_x:output_end_x] = (
:, :, output_start_y:output_end_y, output_start_x:output_end_x output_tile[
] = output_tile[
:, :,
:, :,
tile_output_start_y:tile_output_end_y, tile_output_start_y:tile_output_end_y,
tile_output_start_x:tile_output_end_x, tile_output_start_x:tile_output_end_x,
] ]
)
return output return output

View File

@ -8,7 +8,6 @@ from typing import List, Union
import torch import torch
from PIL import Image from PIL import Image
from pkg_resources import packaging
from torchvision.transforms import CenterCrop, Compose, Normalize, Resize, ToTensor from torchvision.transforms import CenterCrop, Compose, Normalize, Resize, ToTensor
from tqdm import tqdm from tqdm import tqdm
@ -23,9 +22,6 @@ except ImportError:
BICUBIC = Image.BICUBIC 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"] __all__ = ["available_models", "load", "tokenize"]
_tokenizer = _Tokenizer() _tokenizer = _Tokenizer()
@ -272,9 +268,6 @@ def tokenize(
sot_token = _tokenizer.encoder["<|startoftext|>"] sot_token = _tokenizer.encoder["<|startoftext|>"]
eot_token = _tokenizer.encoder["<|endoftext|>"] eot_token = _tokenizer.encoder["<|endoftext|>"]
all_tokens = [[sot_token] + _tokenizer.encode(text) + [eot_token] for text in texts] 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): for i, tokens in enumerate(all_tokens):

View File

@ -14,7 +14,7 @@ anyio==4.3.0
# starlette # starlette
babel==2.14.0 babel==2.14.0
# via mkdocs-material # via mkdocs-material
build==1.1.1 build==1.2.1
# via pip-tools # via pip-tools
certifi==2024.2.2 certifi==2024.2.2
# via # via
@ -43,55 +43,57 @@ colorama==0.4.6
# mkdocs-material # mkdocs-material
coverage==7.4.4 coverage==7.4.4
# via -r requirements-dev.in # via -r requirements-dev.in
diffusers==0.27.0 diffusers==0.27.2
# via imaginAIry (setup.py) # via imaginAIry (setup.py)
einops==0.7.0 einops==0.7.0
# via imaginAIry (setup.py) # via
# imaginAIry (setup.py)
# spandrel
exceptiongroup==1.2.0 exceptiongroup==1.2.0
# via # via
# anyio # anyio
# pytest # pytest
fastapi==0.110.0 fastapi==0.110.1
# via imaginAIry (setup.py) # via imaginAIry (setup.py)
filelock==3.13.1 filelock==3.13.4
# via # via
# diffusers # diffusers
# huggingface-hub # huggingface-hub
# torch # torch
# transformers # transformers
fsspec==2024.2.0 fsspec==2024.3.1
# via # via
# huggingface-hub # huggingface-hub
# torch # torch
ftfy==6.1.3 ftfy==6.2.0
# via # via
# imaginAIry (setup.py) # imaginAIry (setup.py)
# open-clip-torch # open-clip-torch
ghp-import==2.1.0 ghp-import==2.1.0
# via mkdocs # via mkdocs
griffe==0.42.0 griffe==0.42.2
# via mkdocstrings-python # via mkdocstrings-python
h11==0.14.0 h11==0.14.0
# via # via
# httpcore # httpcore
# uvicorn # uvicorn
httpcore==1.0.4 httpcore==1.0.5
# via httpx # via httpx
httpx==0.27.0 httpx==0.27.0
# via -r requirements-dev.in # via -r requirements-dev.in
huggingface-hub==0.21.4 huggingface-hub==0.22.2
# via # via
# diffusers # diffusers
# open-clip-torch # open-clip-torch
# timm # timm
# tokenizers # tokenizers
# transformers # transformers
idna==3.6 idna==3.7
# via # via
# anyio # anyio
# httpx # httpx
# requests # requests
importlib-metadata==7.0.2 importlib-metadata==7.1.0
# via diffusers # via diffusers
iniconfig==2.0.0 iniconfig==2.0.0
# via pytest # via pytest
@ -105,16 +107,15 @@ jinja2==3.1.3
# torch # torch
kornia==0.7.2 kornia==0.7.2
# via imaginAIry (setup.py) # via imaginAIry (setup.py)
kornia-rs==0.1.1 kornia-rs==0.1.3
# via kornia # via kornia
markdown==3.5.2 markdown==3.6
# via # via
# mkdocs # mkdocs
# mkdocs-autorefs # mkdocs-autorefs
# mkdocs-click # mkdocs-click
# mkdocs-material # mkdocs-material
# mkdocstrings # mkdocstrings
# mkdocstrings-python
# pymdown-extensions # pymdown-extensions
markupsafe==2.1.5 markupsafe==2.1.5
# via # via
@ -133,15 +134,15 @@ mkdocs-autorefs==1.0.1
# via mkdocstrings # via mkdocstrings
mkdocs-click==0.8.1 mkdocs-click==0.8.1
# via -r requirements-dev.in # via -r requirements-dev.in
mkdocs-material==9.5.13 mkdocs-material==9.5.18
# via -r requirements-dev.in # via -r requirements-dev.in
mkdocs-material-extensions==1.3.1 mkdocs-material-extensions==1.3.1
# via mkdocs-material # via mkdocs-material
mkdocstrings[python]==0.24.1 mkdocstrings[python]==0.24.3
# via # via
# -r requirements-dev.in # -r requirements-dev.in
# mkdocstrings-python # mkdocstrings-python
mkdocstrings-python==1.9.0 mkdocstrings-python==1.9.2
# via mkdocstrings # via mkdocstrings
mpmath==1.3.0 mpmath==1.3.0
# via sympy # via sympy
@ -149,7 +150,7 @@ mypy==1.9.0
# via -r requirements-dev.in # via -r requirements-dev.in
mypy-extensions==1.0.0 mypy-extensions==1.0.0
# via mypy # via mypy
networkx==3.2.1 networkx==3.3
# via torch # via torch
numpy==1.24.4 numpy==1.24.4
# via # via
@ -159,6 +160,7 @@ numpy==1.24.4
# jaxtyping # jaxtyping
# opencv-python # opencv-python
# scipy # scipy
# spandrel
# torchvision # torchvision
# transformers # transformers
omegaconf==2.3.0 omegaconf==2.3.0
@ -180,7 +182,7 @@ paginate==0.5.6
# via mkdocs-material # via mkdocs-material
pathspec==0.12.1 pathspec==0.12.1
# via mkdocs # via mkdocs
pillow==10.2.0 pillow==10.3.0
# via # via
# diffusers # diffusers
# imaginAIry (setup.py) # imaginAIry (setup.py)
@ -193,17 +195,17 @@ platformdirs==4.2.0
# mkdocstrings # mkdocstrings
pluggy==1.4.0 pluggy==1.4.0
# via pytest # via pytest
protobuf==5.26.0 protobuf==5.26.1
# via # via
# imaginAIry (setup.py) # imaginAIry (setup.py)
# open-clip-torch # open-clip-torch
psutil==5.9.8 psutil==5.9.8
# via imaginAIry (setup.py) # via imaginAIry (setup.py)
pydantic==2.6.4 pydantic==2.7.0
# via # via
# fastapi # fastapi
# imaginAIry (setup.py) # imaginAIry (setup.py)
pydantic-core==2.16.3 pydantic-core==2.18.1
# via pydantic # via pydantic
pygments==2.17.2 pygments==2.17.2
# via mkdocs-material # via mkdocs-material
@ -223,7 +225,7 @@ pytest==8.1.1
# pytest-asyncio # pytest-asyncio
# pytest-randomly # pytest-randomly
# pytest-sugar # pytest-sugar
pytest-asyncio==0.23.5.post1 pytest-asyncio==0.23.6
# via -r requirements-dev.in # via -r requirements-dev.in
pytest-randomly==3.15.0 pytest-randomly==3.15.0
# via -r requirements-dev.in # via -r requirements-dev.in
@ -243,7 +245,7 @@ pyyaml==6.0.1
# transformers # transformers
pyyaml-env-tag==0.1 pyyaml-env-tag==0.1
# via mkdocs # via mkdocs
regex==2023.12.25 regex==2024.4.16
# via # via
# diffusers # diffusers
# mkdocs-material # mkdocs-material
@ -259,15 +261,16 @@ requests==2.31.0
# transformers # transformers
responses==0.25.0 responses==0.25.0
# via -r requirements-dev.in # via -r requirements-dev.in
ruff==0.3.3 ruff==0.3.7
# via -r requirements-dev.in # via -r requirements-dev.in
safetensors==0.4.2 safetensors==0.4.3
# via # via
# diffusers # diffusers
# imaginAIry (setup.py) # imaginAIry (setup.py)
# spandrel
# timm # timm
# transformers # transformers
scipy==1.12.0 scipy==1.13.0
# via # via
# imaginAIry (setup.py) # imaginAIry (setup.py)
# torchdiffeq # torchdiffeq
@ -279,7 +282,9 @@ sniffio==1.3.1
# via # via
# anyio # anyio
# httpx # httpx
starlette==0.36.3 spandrel==0.3.1
# via imaginAIry (setup.py)
starlette==0.37.2
# via fastapi # via fastapi
sympy==1.12 sympy==1.12
# via torch # via torch
@ -300,20 +305,22 @@ tomli==2.0.1
# pip-tools # pip-tools
# pyproject-hooks # pyproject-hooks
# pytest # pytest
torch==2.2.1 torch==2.2.2
# via # via
# imaginAIry (setup.py) # imaginAIry (setup.py)
# kornia # kornia
# open-clip-torch # open-clip-torch
# spandrel
# timm # timm
# torchdiffeq # torchdiffeq
# torchvision # torchvision
torchdiffeq==0.2.3 torchdiffeq==0.2.3
# via imaginAIry (setup.py) # via imaginAIry (setup.py)
torchvision==0.17.1 torchvision==0.17.2
# via # via
# imaginAIry (setup.py) # imaginAIry (setup.py)
# open-clip-torch # open-clip-torch
# spandrel
# timm # timm
tqdm==4.66.2 tqdm==4.66.2
# via # via
@ -321,19 +328,19 @@ tqdm==4.66.2
# imaginAIry (setup.py) # imaginAIry (setup.py)
# open-clip-torch # open-clip-torch
# transformers # transformers
transformers==4.38.2 transformers==4.39.3
# via imaginAIry (setup.py) # via imaginAIry (setup.py)
typeguard==2.13.3 typeguard==2.13.3
# via jaxtyping # via jaxtyping
types-pillow==10.2.0.20240311 types-pillow==10.2.0.20240415
# via -r requirements-dev.in # via -r requirements-dev.in
types-psutil==5.9.5.20240311 types-psutil==5.9.5.20240316
# via -r requirements-dev.in # via -r requirements-dev.in
types-requests==2.31.0.20240311 types-requests==2.31.0.20240406
# via -r requirements-dev.in # via -r requirements-dev.in
types-tqdm==4.66.0.20240106 types-tqdm==4.66.0.20240417
# via -r requirements-dev.in # via -r requirements-dev.in
typing-extensions==4.10.0 typing-extensions==4.11.0
# via # via
# anyio # anyio
# fastapi # fastapi
@ -341,6 +348,7 @@ typing-extensions==4.10.0
# mypy # mypy
# pydantic # pydantic
# pydantic-core # pydantic-core
# spandrel
# torch # torch
# uvicorn # uvicorn
urllib3==2.2.1 urllib3==2.2.1
@ -348,7 +356,7 @@ urllib3==2.2.1
# requests # requests
# responses # responses
# types-requests # types-requests
uvicorn==0.28.0 uvicorn==0.29.0
# via imaginAIry (setup.py) # via imaginAIry (setup.py)
watchdog==4.0.0 watchdog==4.0.0
# via mkdocs # via mkdocs

View File

@ -21,6 +21,7 @@ def test_upscale_cmd_format_option():
mock_img = Mock() mock_img = Mock()
mock_img.save = Mock() mock_img.save = Mock()
mock_img.height = 1000
with patch.multiple( with patch.multiple(
"imaginairy.enhancers.upscale", upscale_image=Mock(return_value=mock_img) "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 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 mock_img.save.assert_called() # Check if save method was called