further improvements to ability to find location of data files

- implement the following pattern for finding data files under both
  regular and editable install conditions:

  import invokeai.foo.bar as bar
  path = bar.__path__[0]

- this *seems* to work reliably with Python 3.9. Testing on 3.10 needs
  to be performed.
This commit is contained in:
Lincoln Stein 2023-01-31 12:24:55 -05:00
parent ec1e83e912
commit 1c377b7995
3 changed files with 10 additions and 25 deletions

View File

@ -17,12 +17,13 @@ import cv2 as cv
from einops import rearrange, repeat
from pathlib import Path
from pytorch_lightning import seed_everything
from invokeai import assets
import invokeai.assets.web as web_assets
from ldm.invoke.devices import choose_autocast
from ldm.models.diffusion.cross_attention_map_saving import AttentionMapSaver
from ldm.util import rand_perlin_2d
downsampling = 8
CAUTION_IMG = 'caution.png'
class CkptGenerator():
def __init__(self, model, precision):
@ -315,16 +316,7 @@ class CkptGenerator():
path = None
if self.caution_img:
return self.caution_img
path = None
for candidate in [
*assets.__path__,
Path(__file__).parent / '..' / '..' / '..' / 'invokeai' / 'assets'
]:
if Path(candidate,CAUTION_IMG).exists():
path = Path(candidate,CAUTION_IMG)
break
if not path:
return
path = Path(web_assets.__path__[0]) / CAUTION_IMG
caution = Image.open(path)
self.caution_img = caution.resize((caution.width // 2, caution.height //2))
return self.caution_img

View File

@ -22,7 +22,7 @@ from urllib import request
import requests
import transformers
from diffusers import StableDiffusionPipeline, AutoencoderKL
from invokeai import configs
import invokeai.configs as configs
from ldm.invoke.generator.diffusers_pipeline import StableDiffusionGeneratorPipeline
from ldm.invoke.devices import choose_precision, choose_torch_device
from getpass_asterisk import getpass_asterisk
@ -52,7 +52,7 @@ Model_dir = 'models'
Weights_dir = 'ldm/stable-diffusion-v1/'
# the initial "configs" dir is now bundled in the `invokeai.configs` package
Dataset_path = Path(configs.__path__[-1]) / 'INITIAL_MODELS.yaml'
Dataset_path = Path(configs.__path__[0]) / 'INITIAL_MODELS.yaml'
Default_config_file = Path (global_config_dir()) / 'models.yaml'
SD_Configs = Path (global_config_dir()) / 'stable-diffusion'

View File

@ -13,6 +13,7 @@ from contextlib import nullcontext
import cv2
import numpy as np
import torch
from PIL import Image, ImageFilter, ImageChops
from diffusers import DiffusionPipeline
from einops import rearrange
@ -20,12 +21,12 @@ from pathlib import Path
from pytorch_lightning import seed_everything
from tqdm import trange
from invokeai import assets
import invokeai.assets.web as web_assets
from ldm.models.diffusion.ddpm import DiffusionWrapper
from ldm.util import rand_perlin_2d
downsampling = 8
CAUTION_IMG = 'web/caution.png'
CAUTION_IMG = 'caution.png'
class Generator:
downsampling_factor: int
@ -321,16 +322,8 @@ class Generator:
path = None
if self.caution_img:
return self.caution_img
path = None
for candidate in [
*assets.__path__,
Path(__file__).parent / '..' / '..' / '..' / 'invokeai' / 'assets'
]:
if Path(candidate,CAUTION_IMG).exists():
path = Path(candidate,CAUTION_IMG)
break
if not path:
return
path = Path(web_assets.__path__[0]) / CAUTION_IMG
print(f'DEBUG: path to caution = {path}')
caution = Image.open(path)
self.caution_img = caution.resize((caution.width // 2, caution.height //2))
return self.caution_img