mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
remove additional unused scripts
This commit is contained in:
parent
45259894e0
commit
85879d3013
@ -1,52 +0,0 @@
|
||||
import os
|
||||
import torch
|
||||
import cv2
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
from diffusers.utils import load_image
|
||||
from diffusers.models.controlnet import ControlNetModel
|
||||
from invokeai.backend.generator import Txt2Img
|
||||
from invokeai.backend.model_management import ModelManager
|
||||
|
||||
|
||||
print("loading 'Girl with a Pearl Earring' image")
|
||||
image = load_image(
|
||||
"https://hf.co/datasets/huggingface/documentation-images/resolve/main/diffusers/input_image_vermeer.png"
|
||||
)
|
||||
image.show()
|
||||
|
||||
print("preprocessing image with Canny edge detection")
|
||||
image_np = np.array(image)
|
||||
low_threshold = 100
|
||||
high_threshold = 200
|
||||
canny_np = cv2.Canny(image_np, low_threshold, high_threshold)
|
||||
canny_image = Image.fromarray(canny_np)
|
||||
canny_image.show()
|
||||
|
||||
# using invokeai model management for base model
|
||||
print("loading base model stable-diffusion-1.5")
|
||||
model_config_path = os.getcwd() + "/../configs/models.yaml"
|
||||
model_manager = ModelManager(model_config_path)
|
||||
model = model_manager.get_model("stable-diffusion-1.5")
|
||||
|
||||
print("loading control model lllyasviel/sd-controlnet-canny")
|
||||
canny_controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float16).to(
|
||||
"cuda"
|
||||
)
|
||||
|
||||
print("testing Txt2Img() constructor with control_model arg")
|
||||
txt2img_canny = Txt2Img(model, control_model=canny_controlnet)
|
||||
|
||||
print("testing Txt2Img.generate() with control_image arg")
|
||||
outputs = txt2img_canny.generate(
|
||||
prompt="old man",
|
||||
control_image=canny_image,
|
||||
control_weight=1.0,
|
||||
seed=0,
|
||||
num_steps=30,
|
||||
precision="float16",
|
||||
)
|
||||
generate_output = next(outputs)
|
||||
out_image = generate_output.image
|
||||
out_image.show()
|
@ -1,33 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Read a checkpoint/safetensors file and write out a template .json file containing
|
||||
its metadata for use in fast model probing.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from invokeai.backend.model_management.models.base import read_checkpoint_meta
|
||||
|
||||
parser = argparse.ArgumentParser(description="Create a .json template from checkpoint/safetensors model")
|
||||
parser.add_argument("--checkpoint", "--in", type=Path, help="Path to the input checkpoint/safetensors file")
|
||||
parser.add_argument("--template", "--out", type=Path, help="Path to the output .json file")
|
||||
|
||||
opt = parser.parse_args()
|
||||
ckpt = read_checkpoint_meta(opt.checkpoint)
|
||||
while "state_dict" in ckpt:
|
||||
ckpt = ckpt["state_dict"]
|
||||
|
||||
tmpl = {}
|
||||
|
||||
for key, tensor in ckpt.items():
|
||||
tmpl[key] = list(tensor.shape)
|
||||
|
||||
try:
|
||||
with open(opt.template, "w") as f:
|
||||
json.dump(tmpl, f)
|
||||
print(f"Template written out as {opt.template}")
|
||||
except Exception as e:
|
||||
print(f"An exception occurred while writing template: {str(e)}")
|
2
scripts/invokeai-model-install.py
Normal file → Executable file
2
scripts/invokeai-model-install.py
Normal file → Executable file
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from invokeai.frontend.install.model_install import main
|
||||
|
||||
main()
|
||||
|
@ -1,37 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Read a checkpoint/safetensors file and compare it to a template .json.
|
||||
Returns True if their metadata match.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import json
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from invokeai.backend.model_management.models.base import read_checkpoint_meta
|
||||
|
||||
parser = argparse.ArgumentParser(description="Compare a checkpoint/safetensors file to a JSON metadata template.")
|
||||
parser.add_argument("--checkpoint", "--in", type=Path, help="Path to the input checkpoint/safetensors file")
|
||||
parser.add_argument("--template", "--out", type=Path, help="Path to the template .json file to match against")
|
||||
|
||||
opt = parser.parse_args()
|
||||
ckpt = read_checkpoint_meta(opt.checkpoint)
|
||||
while "state_dict" in ckpt:
|
||||
ckpt = ckpt["state_dict"]
|
||||
|
||||
checkpoint_metadata = {}
|
||||
|
||||
for key, tensor in ckpt.items():
|
||||
checkpoint_metadata[key] = list(tensor.shape)
|
||||
|
||||
with open(opt.template, "r") as f:
|
||||
template = json.load(f)
|
||||
|
||||
if checkpoint_metadata == template:
|
||||
print("True")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("False")
|
||||
sys.exit(-1)
|
Loading…
Reference in New Issue
Block a user