mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 01:31:13 +02:00
fix openpose and add test-compile
Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
@@ -115,6 +115,7 @@ Plus continued work on modernization of codebase: UI is now fully TypeScript bas
|
||||
- `taesd` preview constant size with reduced layers
|
||||
- `output path` use correct base folder for initial folders
|
||||
- `ltx` prompt embeds move to device, thanks @ryanmeador
|
||||
- `openpose` processor
|
||||
|
||||
## Update for 2026-05-13
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import argparse
|
||||
import os
|
||||
from proc.leres.pix2pix.util import util
|
||||
from ..util import util
|
||||
# import torch
|
||||
from proc.leres.pix2pix import models
|
||||
from .. import models
|
||||
# import pix2pix.data
|
||||
import numpy as np
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from torch.nn import functional as F
|
||||
|
||||
from typing import Tuple
|
||||
|
||||
from proc.segment_anything.modeling import Sam
|
||||
from ..modeling import Sam
|
||||
from .amg import calculate_stability_score
|
||||
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ dependencies = ["torch"]
|
||||
|
||||
import torch
|
||||
|
||||
from midas.dpt_depth import DPTDepthModel
|
||||
from midas.midas_net import MidasNet
|
||||
from midas.midas_net_custom import MidasNet_small
|
||||
from .midas.dpt_depth import DPTDepthModel
|
||||
from .midas.midas_net import MidasNet
|
||||
from .midas.midas_net_custom import MidasNet_small
|
||||
|
||||
def DPT_BEiT_L_512(pretrained=True, **kwargs):
|
||||
""" # This docstring shows up in hub.help()
|
||||
|
||||
+4
-4
@@ -1,10 +1,10 @@
|
||||
import cv2
|
||||
import torch
|
||||
|
||||
from midas.dpt_depth import DPTDepthModel
|
||||
from midas.midas_net import MidasNet
|
||||
from midas.midas_net_custom import MidasNet_small
|
||||
from midas.transforms import Resize, NormalizeImage, PrepareForNet
|
||||
from .dpt_depth import DPTDepthModel
|
||||
from .midas_net import MidasNet
|
||||
from .midas_net_custom import MidasNet_small
|
||||
from .transforms import Resize, NormalizeImage, PrepareForNet
|
||||
|
||||
from torchvision.transforms import Compose
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ import itertools
|
||||
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from proc.zoe.zoedepth.models.depth_model import DepthModel
|
||||
from proc.zoe.zoedepth.models.base_models.midas import MidasCore
|
||||
from proc.zoe.zoedepth.models.layers.attractor import AttractorLayer, AttractorLayerUnnormed
|
||||
from proc.zoe.zoedepth.models.layers.dist_layers import ConditionalLogBinomial
|
||||
from proc.zoe.zoedepth.models.layers.localbins_layers import Projector, SeedBinRegressor, SeedBinRegressorUnnormed
|
||||
from proc.zoe.zoedepth.models.model_io import load_state_from_resource
|
||||
from ..depth_model import DepthModel
|
||||
from ...base_models.midas import MidasCore
|
||||
from ...layers.attractor import AttractorLayer, AttractorLayerUnnormed
|
||||
from ...layers.dist_layers import ConditionalLogBinomial
|
||||
from ...layers.localbins_layers import Projector, SeedBinRegressor, SeedBinRegressorUnnormed
|
||||
from ...model_io import load_state_from_resource
|
||||
|
||||
|
||||
class ZoeDepth(DepthModel):
|
||||
|
||||
@@ -27,13 +27,13 @@ import itertools
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from proc.zoe.zoedepth.models.depth_model import DepthModel
|
||||
from proc.zoe.zoedepth.models.base_models.midas import MidasCore
|
||||
from proc.zoe.zoedepth.models.layers.attractor import AttractorLayer, AttractorLayerUnnormed
|
||||
from proc.zoe.zoedepth.models.layers.dist_layers import ConditionalLogBinomial
|
||||
from proc.zoe.zoedepth.models.layers.localbins_layers import Projector, SeedBinRegressor, SeedBinRegressorUnnormed
|
||||
from proc.zoe.zoedepth.models.layers.patch_transformer import PatchTransformerEncoder
|
||||
from proc.zoe.zoedepth.models.model_io import load_state_from_resource
|
||||
from ..depth_model import DepthModel
|
||||
from ...base_models.midas import MidasCore
|
||||
from ...layers.attractor import AttractorLayer, AttractorLayerUnnormed
|
||||
from ...layers.dist_layers import ConditionalLogBinomial
|
||||
from ...layers.localbins_layers import Projector, SeedBinRegressor, SeedBinRegressorUnnormed
|
||||
from ...layers.patch_transformer import PatchTransformerEncoder
|
||||
from ...model_io import load_state_from_resource
|
||||
|
||||
class ZoeDepthNK(DepthModel):
|
||||
def __init__(self, core, bin_conf, bin_centers_type="softplus", bin_embedding_dim=128,
|
||||
|
||||
@@ -26,20 +26,8 @@ from diffusers.models.attention_processor import AttentionProcessor
|
||||
from diffusers.models.autoencoders import AutoencoderKL
|
||||
from diffusers.models.lora import LoRACompatibleConv
|
||||
from diffusers.models.modeling_utils import ModelMixin
|
||||
|
||||
try:
|
||||
from diffusers.models.unet_2d_blocks import CrossAttnDownBlock2D, CrossAttnUpBlock2D, DownBlock2D, Downsample2D, ResnetBlock2D, Transformer2DModel, UpBlock2D, Upsample2D # pylint: disable=no-name-in-module
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
from diffusers.models.unets.unet_2d_blocks import CrossAttnDownBlock2D, CrossAttnUpBlock2D, DownBlock2D, Downsample2D, ResnetBlock2D, Transformer2DModel, UpBlock2D, Upsample2D
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
from diffusers.models.unet_2d_condition import UNet2DConditionModel
|
||||
except Exception:
|
||||
from diffusers.models.unets.unet_2d_condition import UNet2DConditionModel
|
||||
from diffusers.models.unets.unet_2d_blocks import CrossAttnDownBlock2D, CrossAttnUpBlock2D, DownBlock2D, Downsample2D, ResnetBlock2D, Transformer2DModel, UpBlock2D, Upsample2D
|
||||
from diffusers.models.unets.unet_2d_condition import UNet2DConditionModel
|
||||
from diffusers.utils import BaseOutput, logging, USE_PEFT_BACKEND
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -43,7 +43,8 @@
|
||||
"ruff": ". venv/bin/activate && ruff check",
|
||||
"pylint": ". venv/bin/activate && pylint *.py modules/ pipelines/ scripts/ extensions-builtin/ | grep -v '^*'",
|
||||
"pyright": ". venv/bin/activate && pyright --threads 4",
|
||||
"ty": ". venv/bin/activate && ty check --force-exclude"
|
||||
"ty": ". venv/bin/activate && ty check --force-exclude",
|
||||
"compile": ". venv/bin/activate && python test/test-compile.py"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^2.1.0",
|
||||
|
||||
@@ -11,10 +11,7 @@ from diffusers.configuration_utils import ConfigMixin, register_to_config
|
||||
from diffusers.models.modeling_utils import ModelMixin
|
||||
from diffusers.models.autoencoders.vae import DecoderOutput
|
||||
from diffusers.models.attention_processor import Attention, AttnProcessor
|
||||
try:
|
||||
from diffusers.models.unet_2d_blocks import UNetMidBlock2D, get_down_block, get_up_block
|
||||
except Exception:
|
||||
from diffusers.models.unets.unet_2d_blocks import UNetMidBlock2D, get_down_block, get_up_block
|
||||
from diffusers.models.unets.unet_2d_blocks import UNetMidBlock2D, get_down_block, get_up_block
|
||||
|
||||
|
||||
def zero_module(module):
|
||||
|
||||
@@ -9,13 +9,8 @@ checked_ok = False
|
||||
|
||||
def check_dependencies():
|
||||
global checked_ok # pylint: disable=global-statement
|
||||
from installer import installed, install
|
||||
packages = [
|
||||
('ligo-segments', 'ligo-segments'),
|
||||
]
|
||||
for pkg in packages:
|
||||
if not installed(pkg[1], quiet=True):
|
||||
install(pkg[0], pkg[1], ignore=False)
|
||||
from installer import install
|
||||
install('ligo-segments')
|
||||
try:
|
||||
from ligo.segments import segment # pylint: disable=unused-import
|
||||
checked_ok = True
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import ast
|
||||
import logging
|
||||
import contextlib
|
||||
import py_compile
|
||||
import importlib.util
|
||||
import importlib.machinery
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
includes = [
|
||||
{ 'folder': '.', 'recursive': False, 'includes': True },
|
||||
{ 'folder': 'pipelines', 'recursive': True, 'includes': True },
|
||||
{ 'folder': 'modules', 'recursive': True, 'includes': False },
|
||||
{ 'folder': 'scripts', 'recursive': True, 'local': True, 'includes': False },
|
||||
]
|
||||
excludes = [
|
||||
'node_modules',
|
||||
'__pycache__',
|
||||
]
|
||||
ignores = [
|
||||
'torch_directml',
|
||||
'intel_extension_for_pytorch',
|
||||
'torch_xla.core.xla_model',
|
||||
'flash_attn',
|
||||
'flash_attn_interface',
|
||||
'openai',
|
||||
'rembg',
|
||||
'controlnet_aux',
|
||||
'image_gen_aux',
|
||||
'torchsde',
|
||||
'ligo.segments',
|
||||
'torchdiffeq',
|
||||
'insightface',
|
||||
'pynvml',
|
||||
]
|
||||
output = '/tmp/pycompile'
|
||||
root = Path('.')
|
||||
|
||||
|
||||
def test_compile(folder: str, recursive: bool):
|
||||
stats = { 'ok': [], 'failed': [], 'errors': [] }
|
||||
for entry in os.scandir(folder):
|
||||
if not any(exclude in entry.path for exclude in excludes) and not entry.name.startswith('.'):
|
||||
if entry.is_file() and entry.name.endswith('.py'):
|
||||
try:
|
||||
cfile = os.path.join(output, os.path.relpath(entry.path, start='.')) + 'c'
|
||||
py_compile.compile(entry.path, cfile=cfile, doraise=True)
|
||||
stats['ok'].append(entry.path)
|
||||
except Exception as e:
|
||||
print(f'fail: file={entry.path} error={e}')
|
||||
stats['failed'].append(entry.path)
|
||||
stats['errors'].append(str(e))
|
||||
elif entry.is_dir() and recursive:
|
||||
nested_stats = test_compile(entry.path, recursive)
|
||||
stats['ok'].extend(nested_stats['ok'])
|
||||
stats['failed'].extend(nested_stats['failed'])
|
||||
stats['errors'].extend(nested_stats['errors'])
|
||||
if len(stats["ok"]) > 0 or len(stats["failed"]) > 0:
|
||||
print(f'Compile: folder={folder} ok={len(stats["ok"])} failed={len(stats["failed"])}')
|
||||
return stats
|
||||
|
||||
|
||||
def list_imports(path: Path):
|
||||
imports = []
|
||||
tree = ast.parse(path.read_text(encoding='utf-8'), filename=str(path))
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.Import):
|
||||
for alias in node.names:
|
||||
imports.append((alias.name, 0, path))
|
||||
elif isinstance(node, ast.ImportFrom):
|
||||
module = node.module
|
||||
if node.level > 0:
|
||||
if module:
|
||||
imports.append((module, node.level, path))
|
||||
else:
|
||||
for alias in node.names:
|
||||
if alias.name != '*':
|
||||
imports.append((alias.name, node.level, path))
|
||||
elif module:
|
||||
imports.append((module, 0, path))
|
||||
return imports
|
||||
|
||||
|
||||
def find_import(module: str | None, level: int, path: Path):
|
||||
package_parts = path.relative_to(root).with_suffix('').parts
|
||||
package_parts = package_parts[:-1]
|
||||
if level > len(package_parts) + 1:
|
||||
return None
|
||||
if level == 0:
|
||||
base = list(package_parts)
|
||||
else:
|
||||
base = list(package_parts[: -level + 1]) if level > 1 else list(package_parts)
|
||||
if module:
|
||||
base.extend(module.split('.'))
|
||||
return '.'.join(base) if base else None
|
||||
|
||||
|
||||
def local_import(path: Path) -> bool: # modules that modify sys.path to allow local imports
|
||||
text = path.read_text(encoding='utf-8')
|
||||
return 'sys.path.append' in text or 'sys.path.insert' in text
|
||||
|
||||
|
||||
def install_import(path: Path, module_name: str): # modules that install packages at runtime and import them
|
||||
text = path.read_text(encoding='utf-8')
|
||||
if f'install("{module_name}' in text or f'install(\'{module_name}' in text:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def test_import(module: str | None, level: int, path: Path, local: bool = False):
|
||||
module_name = find_import(module, level, path) if level > 0 else module
|
||||
if not module_name:
|
||||
return True
|
||||
old_disable = logging.root.manager.disable
|
||||
error = None
|
||||
try:
|
||||
logging.disable(logging.CRITICAL)
|
||||
if install_import(path, module_name):
|
||||
return True
|
||||
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
|
||||
try:
|
||||
spec = importlib.util.find_spec(module_name)
|
||||
except ModuleNotFoundError as e:
|
||||
spec = None
|
||||
error = e
|
||||
if spec is not None:
|
||||
return True
|
||||
if local or local_import(path):
|
||||
for extra in [str(path.parent.parent), str(path.parent)]:
|
||||
spec = importlib.machinery.PathFinder.find_spec(module_name, [extra] + sys.path)
|
||||
if spec is not None:
|
||||
return True
|
||||
if error is not None and any(ignore in str(error) for ignore in ignores):
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
if any(ignore in str(e) for ignore in ignores):
|
||||
return True
|
||||
return False
|
||||
finally:
|
||||
logging.disable(old_disable)
|
||||
|
||||
|
||||
def verify_imports(folder: str, recursive: bool, local: bool = False):
|
||||
stats = { 'ok': [], 'failed': [] }
|
||||
for entry in os.scandir(folder):
|
||||
if not any(exclude in entry.path for exclude in excludes) and not entry.name.startswith('.'):
|
||||
if entry.is_file() and entry.name.endswith('.py'):
|
||||
file_path = Path(entry.path)
|
||||
has_failure = False
|
||||
for module, level, _path in list_imports(file_path):
|
||||
if module in ignores:
|
||||
continue
|
||||
if not test_import(module, level, file_path, local):
|
||||
stats['failed'].append(f'{entry.path}: module={module} level={level}')
|
||||
has_failure = True
|
||||
if not has_failure:
|
||||
stats['ok'].append(entry.path)
|
||||
elif entry.is_dir() and recursive:
|
||||
nested_stats = verify_imports(entry.path, recursive)
|
||||
stats['ok'].extend(nested_stats['ok'])
|
||||
stats['failed'].extend(nested_stats['failed'])
|
||||
if len(stats['ok']) > 0 or len(stats['failed']) > 0:
|
||||
print(f'Imports: folder={folder} ok={len(stats["ok"])} failed={len(stats["failed"])}')
|
||||
if len(stats['failed']) > 0:
|
||||
for fail in stats['failed']:
|
||||
print(f' {fail}')
|
||||
return stats
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.makedirs(output, exist_ok=True)
|
||||
sys.path.insert(0, str(root))
|
||||
sys.path.insert(0, str(root / 'modules' / 'control'))
|
||||
for item in includes:
|
||||
print(f"Test {item['folder']}")
|
||||
test_compile(item['folder'], item['recursive'])
|
||||
if item.get('includes', False):
|
||||
verify_imports(item['folder'], item.get('recursive', False), item.get('local', False))
|
||||
Reference in New Issue
Block a user