cddb07a176
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
34 lines
1.6 KiB
Python
34 lines
1.6 KiB
Python
from invokeai.app.invocations.baseinvocation import BaseInvocation, invocation
|
|
from invokeai.app.invocations.fields import FieldDescriptions, ImageField, InputField, WithBoard, WithMetadata
|
|
from invokeai.app.invocations.primitives import ImageOutput
|
|
from invokeai.app.services.shared.invocation_context import InvocationContext
|
|
from invokeai.backend.image_util.pidi import PIDINetDetector
|
|
from invokeai.backend.image_util.pidi.model import PiDiNet
|
|
|
|
|
|
@invocation(
|
|
"pidi_edge_detection",
|
|
title="PiDiNet Edge Detection",
|
|
tags=["controlnet", "edge"],
|
|
category="controlnet_preprocessors",
|
|
version="1.0.0",
|
|
)
|
|
class PiDiNetEdgeDetectionInvocation(BaseInvocation, WithMetadata, WithBoard):
|
|
"""Generates an edge map using PiDiNet."""
|
|
|
|
image: ImageField = InputField(description="The image to process")
|
|
quantize_edges: bool = InputField(default=False, description=FieldDescriptions.safe_mode)
|
|
scribble: bool = InputField(default=False, description=FieldDescriptions.scribble_mode)
|
|
|
|
def invoke(self, context: InvocationContext) -> ImageOutput:
|
|
image = context.images.get_pil(self.image.image_name, "RGB")
|
|
loaded_model = context.models.load_remote_model(PIDINetDetector.get_model_url(), PIDINetDetector.load_model)
|
|
|
|
with loaded_model as model:
|
|
assert isinstance(model, PiDiNet)
|
|
detector = PIDINetDetector(model)
|
|
edge_map = detector.run(image=image, quantize_edges=self.quantize_edges, scribble=self.scribble)
|
|
|
|
image_dto = context.images.save(image=edge_map)
|
|
return ImageOutput.build(image_dto)
|