remove old comfyUI

This commit is contained in:
salt
2024-02-29 14:11:16 -08:00
parent d44ea6619d
commit 9aad2f3d72
2932 changed files with 0 additions and 932769 deletions
@@ -1,9 +0,0 @@
__pycache__
*.ini
wildcards/**
.vscode/
.idea/
subpack
impact_subpack
*.txt
*.yaml
@@ -1,3 +0,0 @@
[submodule "subpack"]
path = subpack
url = https://github.com/ltdrdata/ComfyUI-Impact-Subpack
@@ -1,674 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
@@ -1,455 +0,0 @@
[![Youtube Badge](https://img.shields.io/badge/Youtube-FF0000?style=for-the-badge&logo=Youtube&logoColor=white&link=https://www.youtube.com/watch?v=AccoxDZIg3Y&list=PL_Ej2RDzjQLGfEeizq4GISeY3FtVyFmGP)](https://www.youtube.com/watch?v=AccoxDZIg3Y&list=PL_Ej2RDzjQLGfEeizq4GISeY3FtVyFmGP)
# ComfyUI-Impact-Pack
**Custom nodes pack for ComfyUI**
This custom node helps to conveniently enhance images through Detector, Detailer, Upscaler, Pipe, and more.
## NOTICE
* V4.77: Compatibility patch applied. Requires ComfyUI version (Oct. 8th) or later.
* V4.73.3: ControlNetApply (SEGS) supports AnimateDiff
* V4.20.1: Due to the feature update in `RegionalSampler`, the parameter order has changed, causing malfunctions in previously created `RegionalSamplers`. Please adjust the parameters accordingly.
* V4.12: `MASKS` is changed to `MASK`.
* V4.7.2 isn't compatible with old version of `ControlNet Auxiliary Preprocessor`. If you will use `MediaPipe FaceMesh to SEGS` update to latest version(Sep. 17th).
* Selection weight syntax is changed(: -> ::) since V3.16. ([tutorial](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/ImpactWildcardProcessor.md))
* Starting from V3.6, requires latest version(Aug 8, 9ccc965) of ComfyUI.
* **In versions below V3.3.1, there was an issue with the image quality generated after using the UltralyticsDetectorProvider. Please make sure to upgrade to a newer version.**
* Starting from V3.0, nodes related to `mmdet` are optional nodes that are activated only based on the configuration settings.
- Through ComfyUI-Impact-Subpack, you can utilize UltralyticsDetectorProvider to access various detection models.
* Between versions 2.22 and 2.21, there is partial compatibility loss regarding the Detailer workflow. If you continue to use the existing workflow, errors may occur during execution. An additional output called "enhanced_alpha_list" has been added to Detailer-related nodes.
* The permission error related to cv2 that occurred during the installation of Impact Pack has been patched in version 2.21.4. However, please note that the latest versions of ComfyUI and ComfyUI-Manager are required.
* The "PreviewBridge" feature may not function correctly on ComfyUI versions released before July 1, 2023.
* Attempting to load the "ComfyUI-Impact-Pack" on ComfyUI versions released before June 27, 2023, will result in a failure.
* With the addition of wildcard support in FaceDetailer, the structure of DETAILER_PIPE-related nodes and Detailer nodes has changed. There may be malfunctions when using the existing workflow.
## Custom Nodes
* [Detectors](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/detectors.md)
* SAMLoader - Loads the SAM model.
* UltralyticsDetectorProvider - Loads the Ultralystics model to provide SEGM_DETECTOR, BBOX_DETECTOR.
- Unlike `MMDetDetectorProvider`, for segm models, `BBOX_DETECTOR` is also provided.
- The various models available in UltralyticsDetectorProvider can be downloaded through **ComfyUI-Manager**.
* ONNXDetectorProvider - Loads the ONNX model to provide BBOX_DETECTOR.
* CLIPSegDetectorProvider - Wrapper for CLIPSeg to provide BBOX_DETECTOR.
* You need to install the ComfyUI-CLIPSeg node extension.
* SEGM Detector (combined) - Detects segmentation and returns a mask from the input image.
* BBOX Detector (combined) - Detects bounding boxes and returns a mask from the input image.
* SAMDetector (combined) - Utilizes the SAM technology to extract the segment at the location indicated by the input SEGS on the input image and outputs it as a unified mask.
* SAMDetector (Segmented) - It is similar to `SAMDetector (combined)`, but it separates and outputs the detected segments. Multiple segments can be found for the same detected area, and currently, a policy is in place to group them arbitrarily in sets of three. This aspect is expected to be improved in the future.
* As a result, it outputs the `combined_mask`, which is a unified mask, and `batch_masks`, which are multiple masks grouped together in batch form.
* While `batch_masks` may not be completely separated, it provides functionality to perform some level of segmentation.
* Simple Detector (SEGS) - Operating primarily with `BBOX_DETECTOR`, and with the additional provision of `SAM_MODEL` or `SEGM_DETECTOR`, this node internally generates improved SEGS through mask operations on both *bbox* and *silhouette*. It serves as a convenient tool to simplify a somewhat intricate workflow.
* ControlNet, IPAdapter
* ControlNetApply (SEGS) - To apply ControlNet in SEGS, you need to use the Preprocessor Provider node from the Inspire Pack to utilize this node.
* `segs_preprocessor` and `control_image` can be selectively applied. If an `control_image` is given, `segs_preprocessor` will be ignored.
* If set to `control_image`, you can preview the cropped cnet image through `SEGSPreview (CNET Image)`. Images generated by `segs_preprocessor` should be verified through the `cnet_images` output of each Detailer.
* The `segs_preprocessor` operates by applying preprocessing on-the-fly based on the cropped image during the detailing process, while `control_image` will be cropped and used as input to `ControlNetApply (SEGS)`.
* ControlNetClear (SEGS) - Clear applied ControlNet in SEGS
* IPAdapterApply (SEGS) - To apply IPAdapter in SEGS, you need to use the Preprocessor Provider node from the Inspire Pack to utilize this node.
* Bitwise(SEGS & SEGS) - Performs a 'bitwise and' operation between two SEGS.
* Bitwise(SEGS - SEGS) - Subtracts one SEGS from another.
* Bitwise(SEGS & MASK) - Performs a bitwise AND operation between SEGS and MASK.
* Bitwise(SEGS & MASKS ForEach) - Performs a bitwise AND operation between SEGS and MASKS.
* Please note that this operation is performed with batches of MASKS, not just a single MASK.
* Bitwise(MASK & MASK) - Performs a 'bitwise and' operation between two masks.
* Bitwise(MASK - MASK) - Subtracts one mask from another.
* Bitwise(MASK + MASK) - Combine two masks.
* SEGM Detector (SEGS) - Detects segmentation and returns SEGS from the input image.
* BBOX Detector (SEGS) - Detects bounding boxes and returns SEGS from the input image.
* Detailer
* Detailer (SEGS) - Refines the image based on SEGS.
* DetailerDebug (SEGS) - Refines the image based on SEGS. Additionally, it provides the ability to monitor the cropped image and the refined image of the cropped image.
* To prevent regeneration caused by the seed that does not change every time when using 'external_seed', please disable the 'seed random generate' option in the 'Detailer...' node.
* MASK to SEGS - Generates SEGS based on the mask.
* MASK to SEGS For AnimateDiff - Generates SEGS based on the mask for AnimateDiff.
* MediaPipe FaceMesh to SEGS - Separate each landmark from the mediapipe facemesh image to create labeled SEGS.
* Usually, the size of images created through the MediaPipe facemesh preprocessor is downscaled. It resizes the MediaPipe facemesh image to the original size given as reference_image_opt for matching sizes during processing.
* ToBinaryMask - Separates the mask generated with alpha values between 0 and 255 into 0 and 255. The non-zero parts are always set to 255.
* Masks to Mask List - This node converts the MASKS in batch form to a list of individual masks.
* Mask List to Masks - This node converts the MASK list to MASK batch form.
* EmptySEGS - Provides an empty SEGS.
* MaskPainter - Provides a feature to draw masks.
* FaceDetailer - Easily detects faces and improves them.
* FaceDetailer (pipe) - Easily detects faces and improves them (for multipass).
* MaskDetailer (pipe) - This is a simple inpaint node that applies the Detailer to the mask area.
* `FromDetailer (SDXL/pipe), BasicPipe -> DetailerPipe (SDXL), Edit DetailerPipe (SDXL)` - These are pipe functions used in Detailer for utilizing the refiner model of SDXL.
* SEGS Manipulation nodes
* SEGSDetailer - Performs detailed work on SEGS without pasting it back onto the original image.
* SEGSPaste - Pastes the results of SEGS onto the original image.
* If `ref_image_opt` is present, the images contained within SEGS are ignored. Instead, the image within `ref_image_opt` corresponding to the crop area of SEGS is taken and pasted. The size of the image in `ref_image_opt` should be the same as the original image size.
* This node can be used in conjunction with the processing results of AnimateDiff.
* SEGSPreview - Provides a preview of SEGS.
* This option is used to preview the improved image through `SEGSDetailer` before merging it into the original. Prior to going through ```SEGSDetailer```, SEGS only contains mask information without image information. If fallback_image_opt is connected to the original image, SEGS without image information will generate a preview using the original image. However, if SEGS already contains image information, fallback_image_opt will be ignored.
* This node can be used in conjunction with the processing results of AnimateDiff.
* SEGSPreview (CNET Image) - Show images configured with `ControlNetApply (SEGS)` for debugging purposes.
* SEGSToImageList - Convert SEGS To Image List
* SEGSToMaskList - Convert SEGS To Mask List
* SEGS Filter (label) - This node filters SEGS based on the label of the detected areas.
* SEGS Filter (ordered) - This node sorts SEGS based on size and position and retrieves SEGs within a certain range.
* SEGS Filter (range) - This node retrieves only SEGs from SEGS that have a size and position within a certain range.
* SEGS Assign (label) - Assign labels sequentially to SEGS. This node is useful when used with `[LAB]` of FaceDetailer.
* SEGSConcat - Concatenate segs1 and segs2. If source shape of segs1 and segs2 are different from segs2 will be ignored.
* Picker (SEGS) - Among the input SEGS, you can select a specific SEG through a dialog. If no SEG is selected, it outputs an empty SEGS. Increasing the batch_size of SEGSDetailer can be used for the purpose of selecting from the candidates.
* Set Default Image For SEGS - Set a default image for SEGS. SEGS with images set this way do not need to have a fallback image set. When override is set to false, the original image is preserved.
* Remove Image from SEGS - Remove the image set for the SEGS that has been configured by "Set Default Image for SEGS" or SEGSDetailer. When the image for the SEGS is removed, the Detailer node will operate based on the currently processed image instead of the SEGS.
* Make Tile SEGS - [experimental] Create SEGS in the form of tiles from an image to facilitate experiments for Tiled Upscale using the Detailer.
* The `filter_in_segs_opt` and `filter_out_segs_opt` are optional inputs. If these inputs are provided, when creating the tiles, the mask for each tile is generated by overlapping with the mask of `filter_in_segs_opt` and excluding the overlap with the mask of `filter_out_segs_opt`. Tiles with an empty mask will not be created as SEGS.
* Dilate Mask (SEGS) - Dilate/Erosion Mask in SEGS
* Gaussian Blur Mask (SEGS) - Apply Gaussian Blur to Mask in SEGS
* SEGS_ELT Manipulation - experimental nodes
* DecomposeSEGS - Decompose SEGS to allow for detailed manipulation.
* AssembleSEGS - Reassemble the decomposed SEGS.
* From SEG_ELT - Extract detailed information from SEG_ELT.
* Edit SEG_ELT - Modify some of the information in SEG_ELT.
* Dilate SEG_ELT - Dilate the mask of SEG_ELT.
* Mask Manipulation
* Dilate Mask - Dilate Mask.
* Support erosion for negative value.
* Gaussian Blur Mask - Apply Gaussian Blur to Mask. You can utilize this for mask feathering.
* Pipe nodes
* ToDetailerPipe, FromDetailerPipe - These nodes are used to bundle multiple inputs used in the detailer, such as models and vae, ..., into a single DETAILER_PIPE or extract the elements that are bundled in the DETAILER_PIPE.
* ToBasicPipe, FromBasicPipe - These nodes are used to bundle model, clip, vae, positive conditioning, and negative conditioning into a single BASIC_PIPE, or extract each element from the BASIC_PIPE.
* EditBasicPipe, EditDetailerPipe - These nodes are used to replace some elements in BASIC_PIPE or DETAILER_PIPE.
* FromDetailerPipe_v2, FromBasicPipe_v2 - It has the same functionality as `FromDetailerPipe` and `FromBasicPipe`, but it has an additional output that directly exports the input pipe. It is useful when editing EditBasicPipe and EditDetailerPipe.
* Latent Scale (on Pixel Space) - This node converts latent to pixel space, upscales it, and then converts it back to latent.
* If upscale_model_opt is provided, it uses the model to upscale the pixel and then downscales it using the interpolation method provided in scale_method to the target resolution.
* PixelKSampleUpscalerProvider - An upscaler is provided that converts latent to pixels using VAEDecode, performs upscaling, converts back to latent using VAEEncode, and then performs k-sampling. This upscaler can be attached to nodes such as 'Iterative Upscale' for use.
* Similar to 'Latent Scale (on Pixel Space)', if upscale_model_opt is provided, it performs pixel upscaling using the model.
* PixelTiledKSampleUpscalerProvider - It is similar to PixelKSampleUpscalerProvider, but it uses ComfyUI_TiledKSampler and Tiled VAE Decoder/Encoder to avoid GPU VRAM issues at high resolutions.
* You need to install the [BlenderNeko/ComfyUI_TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) node extension.
* PK_HOOK
* DenoiseScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the denoise to target_denoise as the iterative-step progresses.
* CfgScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the cfg to target_cfg as the iterative-step progresses.
* StepsScheduleHookProvider - IterativeUpscale provides a hook that gradually changes the sampling-steps to target_steps as the iterative-step progresses.
* NoiseInjectionHookProvider - During each iteration of IterativeUpscale, noise is injected into the latent space while varying the strength according to a schedule.
* You need to install the [BlenderNeko/ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) node extension.
* The seed serves as the initial value required for generating noise, and it increments by 1 with each iteration as the process unfolds.
* The source determines the types of CPU noise and GPU noise to be configured.
* Currently, there is only a simple schedule available, where the strength of the noise varies from start_strength to end_strength during the progression of each iteration.
* UnsamplerHookProvider - Apply Unsampler during each iteration. To use this node, ComfyUI_Noise must be installed.
* PixelKSampleHookCombine - This is used to connect two PK_HOOKs. hook1 is executed first and then hook2 is executed.
* If you want to simultaneously change cfg and denoise, you can combine the PK_HOOKs of CfgScheduleHookProvider and PixelKSampleHookCombine.
* DETAILER_HOOK
* NoiseInjectionDetailerHookProvider - The `detailer_hook` is a hook in the `Detailer` that injects noise during the processing of each SEGS.
* UnsamplerDetailerHookProvider - Apply Unsampler during each cycle. To use this node, ComfyUI_Noise must be installed.
* DenoiseSchedulerDetailerHookProvider - During the progress of the cycle, the detailer's denoise is altered up to the `target_denoise`.
* CoreMLDetailerHookProvider - CoreML supports only 512x512, 512x768, 768x512, 768x768 size sampling. CoreMLDetailerHookProvider precisely fixes the upscale of the crop_region to this size. When using this hook, it will always be selected size, regardless of the guide_size. However, if the guide_size is too small, skipping will occur.
* DetailerHookCombine - This is used to connect two DETAILER_HOOKs. Similar to PixelKSampleHookCombine.
* SEGSOrderedFilterDetailerHook, SEGSRangeFilterDetailerHook, SEGSLabelFilterDetailerHook - There are a wrapper node that provides SEGSFilter nodes to be applied in FaceDetailer or Detector by creating DETAILER_HOOK.
* PreviewDetailerHOok - Connecting this hook node helps provide assistance for viewing previews whenever SEGS Detailing tasks are completed. When working with a large number of SEGS, such as Make Tile SEGS, it allows for monitoring the situation as improvements progress incrementally.
* Since this is the hook applied when pasting onto the original image, it has no effect on nodes like `SEGSDetailer`.
* Iterative Upscale (Latent/on Pixel Space) - The upscaler takes the input upscaler and splits the scale_factor into steps, then iteratively performs upscaling.
This takes latent as input and outputs latent as the result.
* Iterative Upscale (Image) - The upscaler takes the input upscaler and splits the scale_factor into steps, then iteratively performs upscaling. This takes image as input and outputs image as the result.
* Internally, this node uses 'Iterative Upscale (Latent)'.
* TwoSamplersForMask - This node can apply two samplers depending on the mask area. The base_sampler is applied to the area where the mask is 0, while the mask_sampler is applied to the area where the mask is 1.
* Note: The latent encoded through VAEEncodeForInpaint cannot be used.
* KSamplerProvider - This is a wrapper that enables KSampler to be used in TwoSamplersForMask TwoSamplersForMaskUpscalerProvider.
* TiledKSamplerProvider - ComfyUI_TiledKSampler is a wrapper that provides KSAMPLER.
* You need to install the [BlenderNeko/ComfyUI_TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) node extension.
* TwoAdvancedSamplersForMask - TwoSamplersForMask is similar to TwoAdvancedSamplersForMask, but they differ in their operation. TwoSamplersForMask performs sampling in the mask area only after all the samples in the base area are finished. On the other hand, TwoAdvancedSamplersForMask performs sampling in both the base area and the mask area sequentially at each step.
* KSamplerAdvancedProvider - This is a wrapper that enables KSampler to be used in TwoAdvancedSamplersForMask, RegionalSampler.
* sigma_factor: By multiplying the denoise schedule by the sigma_factor, you can adjust the amount of denoising based on the configured denoise.
* TwoSamplersForMaskUpscalerProvider - This is an Upscaler that extends TwoSamplersForMask to be used in Iterative Upscale.
* TwoSamplersForMaskUpscalerProviderPipe - pipe version of TwoSamplersForMaskUpscalerProvider.
* Image Utils
* PreviewBridge (image) - This custom node can be used with a bridge for image when using the MaskEditor feature of Clipspace.
* PreviewBridge (latent) - This custom node can be used with a bridge for latent image when using the MaskEditor feature of Clipspace.
* If a latent with a mask is provided as input, it displays the mask. Additionally, the mask output provides the mask set in the latent.
* If a latent without a mask is provided as input, it outputs the original latent as is, but the mask output provides an output with the entire region set as a mask.
* When set mask through MaskEditor, a mask is applied to the latent, and the output includes the stored mask. The same mask is also output as the mask output.
* When connected to `vae_opt`, it takes higher priority than the `preview_method`.
* ImageSender, ImageReceiver - The images generated in ImageSender are automatically sent to the ImageReceiver with the same link_id.
* LatentSender, LatentReceiver - The latent generated in LatentSender are automatically sent to the LatentReceiver with the same link_id.
* Furthermore, LatentSender is implemented with PreviewLatent, which stores the latent in payload form within the image thumbnail.
* Due to the current structure of ComfyUI, it is unable to distinguish between SDXL latent and SD1.5/SD2.1 latent. Therefore, it generates thumbnails by decoding them using the SD1.5 method.
* Switch nodes
* Switch (image,mask), Switch (latent), Switch (SEGS) - Among multiple inputs, it selects the input designated by the selector and outputs it. The first input must be provided, while the others are optional. However, if the input specified by the selector is not connected, an error may occur.
* Switch (Any) - This is a Switch node that takes an arbitrary number of inputs and produces a single output. Its type is determined when connected to any node, and connecting inputs increases the available slots for connections.
* Inversed Switch (Any) - In contrast to `Switch (Any)`, it takes a single input and outputs one of many. Due to ComfyUI's functional limitations, the value of `select` must be determined at the time of queuing a prompt, and while it can serve as a `Primitive Node` or `ImpactInt`, it cannot function properly when connected through other nodes.
* Guide
* When the `Switch (Any)` and `Inversed Switch (Any)` selects are transformed into primitives, it's important to be cautious because the select range is not appropriately constrained, potentially leading to unintended behavior.
* `Switch (image,mask)`, `Switch (latent)`, `Switch (SEGS)`, `Switch (Any)` supports `sel_mode` param. The `sel_mode` sets the moment at which the `select` parameter is determined. `select_on_prompt` determines the `select` at the time of queuing the prompt, while `select_on_execution` determines it during the execution of the workflow. While `select_on_execution` offers more flexibility, it can potentially trigger workflow execution errors due to running nodes that may be impossible to execute within the limitations of ComfyUI. `select_on_prompt` bypasses this constraint by treating any inputs not selected as if they were disconnected. However, please note that when using `select_on_prompt`, the `select` can only be used with widgets or `Primitive Nodes` determined at the queue prompt.
* There is an issue when connecting the built-in reroute node with the switch's input/output slots. it can lead to forced disconnections during workflow loading. Therefore, it is advisable not to use reroute for making connections in such cases. However, there are no issues when using the reroute node in Pythongossss.
* [Wildcards](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/ImpactWildcard.md) - These are nodes that supports syntax in the form of `__wildcard-name__` and dynamic prompt syntax like `{a|b|c}`.
* Wildcard files can be used by placing `.txt` or `.yaml` files under either `ComfyUI-Impact-Pack/wildcards` or `ComfyUI-Impact-Pack/custom_wildcards` paths.
* You can download and use [Wildcard YAML](https://civitai.com/models/138970/billions-of-wildcards-all-in-one) files in this format.
* After the first execution, you can change the custom wildcards path in the `custom_wildcards` entry within the `ComfyUI-Impact-Pack/impact-pack.ini` file created.
* ImpactWildcardProcessor - The text is generated by processing the wildcard in the Text. If the mode is set to "populate", a dynamic prompt is generated with each execution and the input is filled in the second textbox. If the mode is set to "fixed", the content of the second textbox remains unchanged.
* When an image is generated with the "fixed" mode, the prompt used for that particular generation is stored in the metadata.
* ImpactWildcardEncode - Similar to ImpactWildcardProcessor, this provides the loading functionality of LoRAs (e.g. `<lora:some_awesome_lora:0.7:1.2>`). Populated prompts are encoded using the clip after all the lora loading is done.
* If the `Inspire Pack` is installed, you can use **Lora Block Weight** in the form of `LBW=lbw spec;`
* `<lora:chunli:1.0:1.0:LBW=B11:0,0,0,0,0,0,0,0,0,0,A,0,0,0,0,0,0;A=0.;>`, `<lora:chunli:1.0:1.0:LBW=0,0,0,0,0,0,0,0,0,0,A,B,0,0,0,0,0;A=0.5;B=0.2;>`, `<lora:chunli:1.0:1.0:LBW=SD-MIDD;>`
* Regional Sampling - These nodes offer the capability to divide regions and perform partial sampling using a mask. Unlike TwoSamplersForMask, sampling for each region is applied during each step.
* RegionalPrompt - This node combines a **mask** for specifying regions and the **sampler** to apply to each region to create `REGIONAL_PROMPTS`.
* CombineRegionalPrompts - Combine multiple `REGIONAL_PROMPTS` to create a single `REGIONAL_PROMPTS`.
* RegionalSampler - This node performs sampling using a base sampler and regional prompts. Sampling by the base sampler is executed at each step, while sampling for each region is performed through the sampler bound to each region.
* overlap_factor - Specifies the amount of overlap for each region to blend well with the area outside the mask.
* restore_latent - When sampling each region, restore the areas outside the mask to the base latent, preventing additional noise from being introduced outside the mask during region sampling.
* RegionalSamplerAdvanced - This is the Advanced version of the RegionalSampler. You can control it using `step` instead of `denoise`.
* NOTE: The `sde` sampler and `uni_pc` sampler introduce additional noise during each step of the sampling process. To mitigate this, when sampling each region, the `uni_pc` sampler applies additional `dpmpp_fast`, and the sde sampler applies the `dpmpp_2m` sampler as an additional measure.
* KSampler (pipe), KSampler (advanced/pipe)
* Image batch To Image List - Convert Image batch to Image List
- You can use images generated in a multi batch to handle them
* Make Image List - Convert multiple images into a single image list
* Make Image Batch - Convert multiple images into a single image batch
- The input of images can be scaled up as needed
* String Selector - It selects and returns a portion of the string. When `multiline` mode is disabled, it simply returns the string of the line pointed to by the selector. When `multiline` mode is enabled, it divides the string based on lines that start with `#` and returns them. If the `select` value is larger than the number of items, it will start counting from the first line again and return accordingly.
* Combine Conditionings - It takes multiple conditionings as input and combines them into a single conditioning.
* Concat Conditionings - It takes multiple conditionings as input and concat them into a single conditioning.
* Logics (experimental) - These nodes are experimental nodes designed to implement the logic for loops and dynamic switching.
* ImpactCompare, ImpactConditionalBranch, ImpactConditionalBranchSelMode, ImpactInt, ImpactValueSender, ImpactValueReceiver, ImpactImageInfo, ImpactMinMax, ImpactNeg, ImpactConditionalStopIteration
* ImpactIsNotEmptySEGS - This node returns `true` only if the input SEGS is not empty.
* Queue Trigger - When this node is executed, it adds a new queue to assist with repetitive tasks. It will only execute if the signal's status changes.
* Queue Trigger (Countdown) - Like the Queue Trigger, it adds a queue, but only adds it if it's greater than 1, and decrements the count by one each time it runs.
* Sleep - Waits for the specified time (in seconds).
* Set Widget Value - This node sets one of the optional inputs to the specified node's widget. An error may occur if the types do not match.
* Set Mute State - This node changes the mute state of a specific node.
* Control Bridge - This node modifies the state of the connected control nodes based on the `mode` and `behavior` . If there are nodes that require a change, the current execution is paused, the mute status is updated, and a new prompt queue is inserted.
* When the `mode` is `active`, it makes the connected control nodes active regardless of the behavior.
* When the `mode` is `Bypass/Mute`, it changes the state of the connected nodes based on whether the behavior is `Bypass` or `Mute`.
* **Limitation**: Due to these characteristics, it does not function correctly when the batch count exceeds 1. Additionally, it does not guarantee proper operation when the seed is randomized or when the state of nodes is altered by actions such as `Queue Trigger`, `Set Widget Value`, `Set Mute`, before the Control Bridge.
* When utilizing this node, please structure the workflow in such a way that `Queue Trigger`, `Set Widget Value`, `Set Mute State`, and similar actions are executed at the end of the workflow.
* If you want to change the value of the seed at each iteration, please ensure that Set Widget Value is executed at the end of the workflow instead of using randomization.
* It is not a problem if the seed changes due to randomization as long as it occurs after the Control Bridge section.
* Remote Boolean (on prompt), Remote Int (on prompt) - At the start of the prompt, this node forcibly sets the `widget_value` of `node_id`. It is disregarded if the target widget type is different.
* You can find the `node_id` by checking through [ComfyUI-Manager](https://github.com/ltdrdata/ComfyUI-Manager) using the format `Badge: #ID Nickname`.
* Experimental set of nodes for implementing loop functionality (tutorial to be prepared later / [example workflow](test/loop-test.json)).
* HuggingFace - These nodes provide functionalities based on HuggingFace repository models.
* `HF Transformers Classifier Provider` - This is a node that provides a classifier based on HuggingFace's transformers models.
* The 'repo id' parameter should contain HuggingFace's repo id. When `preset_repo_id` is set to `Manual repo id`, use the manually entered repo id in `manual_repo_id`.
* e.g. 'rizvandwiki/gender-classification-2' is a repository that provides a model for gender classification.
* `SEGS Classify` - This node utilizes the `TRANSFORMERS_CLASSIFIER` loaded with 'HF Transformers Classifier Provider' to classify `SEGS`.
* The 'expr' allows for forms like `label > number`, and in the case of `preset_expr` being `Manual expr`, it uses the expression entered in `manual_expr`.
* For example, in the case of `male <= 0.4`, if the score of the `male` label in the classification result is less than or equal to 0.4, it is categorized as `filtered_SEGS`, otherwise, it is categorized as `remained_SEGS`.
* For supported labels, please refer to the `config.json` of the respective HuggingFace repository.
* `#Female` and `#Male` are symbols that group multiple labels such as `Female, women, woman, ...`, for convenience, rather than being single labels.
## MMDet nodes
* MMDetDetectorProvider - Loads the MMDet model to provide BBOX_DETECTOR and SEGM_DETECTOR.
* To use the existing MMDetDetectorProvider, you need to enable the MMDet usage configuration.
## Feature
* Interactive SAM Detector (Clipspace) - When you right-click on a node that has 'MASK' and 'IMAGE' outputs, a context menu will open. From this menu, you can either open a dialog to create a SAM Mask using 'Open in SAM Detector', or copy the content (likely mask data) using 'Copy (Clipspace)' and generate a mask using 'Impact SAM Detector' from the clipspace menu, and then paste it using 'Paste (Clipspace)'.
* Providing a feature to detect errors that occur when mixing models and clips from checkpoints such as `SDXL Base`, `SDXL Refiner`, `SD1.x`, `SD2.x` during sample execution, and reporting appropriate errors.
## Deprecated
* The following nodes have been kept only for compatibility with existing workflows, and are no longer supported. Please replace them with new nodes.
* ONNX Detector (SEGS) - BBOX Detector (SEGS)
* MMDetLoader -> MMDetDetectorProvider
* SegsMaskCombine -> SEGS to MASK (combined)
* BboxDetectorForEach -> BBOX Detector (SEGS)
* SegmDetectorForEach -> SEGM Detector (SEGS)
* BboxDetectorCombined -> BBOX Detector (combined)
* SegmDetectorCombined -> SEGM Detector (combined)
* MaskPainter -> PreviewBridge
* To use the existing deprecated legacy nodes, you need to enable the MMDet usage configuration.
## Ultralytics models
* huggingface.co/Bingsu/[adetailer](https://github.com/ultralytics/assets/releases/) - You can download face, people detection models, and clothing detection models.
* ultralytics/[assets](https://github.com/ultralytics/assets/releases/) - You can download various types of detection models other than faces or people.
* civitai/[adetailer](https://civitai.com/search/models?sortBy=models_v5&query=adetailer) - You can download various types detection models....Many models are associated with NSFW content.
## How to activate 'MMDet usage'
* Upon the initial execution, an `impact-pack.ini` file will be generated in the custom_nodes/ComfyUI-Impact-Pack directory.
```
[default]
dependency_version = 2
mmdet_skip = True
```
* Change `mmdet_skip = True` to `mmdet_skip = False`
```
[default]
dependency_version = 2
mmdet_skip = False
```
* Restart ComfyUI
## Installation
1. `cd custom_nodes`
1. `git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack.git`
3. `cd ComfyUI-Impact-Pack`
4. (optional) `git submodule update --init --recursive`
* Impact Pack will automatically download subpack during its initial launch.
5. (optional) `python install.py`
* Impact Pack will automatically install its dependencies during its initial launch.
* For the portable version, you should execute the command `..\..\..\python_embeded\python.exe install.py` to run the installation script.
6. Restart ComfyUI
* NOTE: If an error occurs during the installation process, please refer to [Troubleshooting Page](troubleshooting/TROUBLESHOOTING.md) for assistance.
* You can use this colab notebook [colab notebook](https://colab.research.google.com/github/ltdrdata/ComfyUI-Impact-Pack/blob/Main/notebook/comfyui_colab_impact_pack.ipynb) to launch it. This notebook automatically downloads the impact pack to the custom_nodes directory, installs the tested dependencies, and runs it.
## Package Dependencies (If you need to manual setup.)
* pip install
* openmim
* segment-anything
* ultralytics
* scikit-image
* piexif
* (optional) pycocotools
* (optional) onnxruntime
* mim install (optional)
* mmcv==2.0.0, mmdet==3.0.0, mmengine==0.7.2
* linux packages (ubuntu)
* libgl1-mesa-glx
* libglib2.0-0
## Config example
* Once you run the Impact Pack for the first time, an `impact-pack.ini` file will be automatically generated in the Impact Pack directory. You can modify this configuration file to customize the default behavior.
* `dependency_version` - don't touch this
* `mmdet_skip` - disable MMDet based nodes and legacy nodes if `True`
* `sam_editor_cpu` - use cpu for `SAM editor` instead of gpu
* sam_editor_model: Specify the SAM model for the SAM editor.
* You can download various SAM models using ComfyUI-Manager.
* Path to SAM model: `ComfyUI/models/sams`
```
[default]
dependency_version = 9
mmdet_skip = True
sam_editor_cpu = False
sam_editor_model = sam_vit_b_01ec64.pth
```
## Other Materials (auto-download on initial startup)
* ComfyUI/models/mmdets/bbox <= https://huggingface.co/dustysys/ddetailer/resolve/main/mmdet/bbox/mmdet_anime-face_yolov3.pth
* ComfyUI/models/mmdets/bbox <= https://raw.githubusercontent.com/Bing-su/dddetailer/master/config/mmdet_anime-face_yolov3.py
* ComfyUI/models/sams <= https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth
## Troubleshooting page
* [Troubleshooting Page](troubleshooting/TROUBLESHOOTING.md)
## How to use (DDetailer feature)
#### 1. Basic auto face detection and refine exapmle.
![simple](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/simple.png)
* The face that has been damaged due to low resolution is restored with high resolution by generating and synthesizing it, in order to restore the details.
* The FaceDetailer node is a combination of a Detector node for face detection and a Detailer node for image enhancement. See the [Advanced Tutorial](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/tutorial/advanced.md) for a more detailed explanation.
* Pass the MMDetLoader 's bbox model and the detection model loaded by SAMLoader to FaceDetailer . Since it performs the function of KSampler for image enhancement, it overlaps with KSampler's options.
* The MASK output of FaceDetailer provides a visualization of where the detected and enhanced areas are.
![simple-orig](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/simple-original.png) ![simple-refined](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/simple-refined.png)
* You can see that the face in the image on the left has increased detail as in the image on the right.
#### 2. 2Pass refine (restore a severely damaged face)
![2pass-workflow-example](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/2pass-simple.png)
* Although two FaceDetailers can be attached together for a 2-pass configuration, various common inputs used in KSampler can be passed through DETAILER_PIPE, so FaceDetailerPipe can be used to configure easily.
* In 1pass, only rough outline recovery is required, so restore with a reasonable resolution and low options. However, if you increase the dilation at this time, not only the face but also the surrounding parts are included in the recovery range, so it is useful when you need to reshape the face other than the facial part.
![2pass-example-original](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/2pass-original.png) ![2pass-example-middle](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/2pass-1pass.png) ![2pass-example-result](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/2pass-2pass.png)
* In the first stage, the severely damaged face is restored to some extent, and in the second stage, the details are restored
#### 3. Face Bbox(bounding box) + Person silhouette segmentation (prevent distortion of the background.)
![combination-workflow-example](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/combination.jpg)
![combination-example-original](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/combination-original.png) ![combination-example-refined](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/combination-refined.png)
* Facial synthesis that emphasizes details is delicately aligned with the contours of the face, and it can be observed that it does not affect the image outside of the face.
* The BBoxDetectorForEach node is used to detect faces, and the SAMDetectorCombined node is used to find the segment related to the detected face. By using the Segs & Mask node with the two masks obtained in this way, an accurate mask that intersects based on segs can be generated. If this generated mask is input to the DetailerForEach node, only the target area can be created in high resolution from the image and then composited.
#### 4. Iterative Upscale
![upscale-workflow-example](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/upscale-workflow.png)
* The IterativeUpscale node is a node that enlarges an image/latent by a scale_factor. In this process, the upscale is carried out progressively by dividing it into steps.
* IterativeUpscale takes an Upscaler as an input, similar to a plugin, and uses it during each iteration. PixelKSampleUpscalerProvider is an Upscaler that converts the latent representation to pixel space and applies ksampling.
* The upscale_model_opt is an optional parameter that determines whether to use the upscale function of the model base if available. Using the upscale function of the model base can significantly reduce the number of iterative steps required. If an x2 upscaler is used, the image/latent is first upscaled by a factor of 2 and then downscaled to the target scale at each step before further processing is done.
* The following image is an image of 304x512 pixels and the same image scaled up to three times its original size using IterativeUpscale.
![combination-example-original](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/upscale-original.png) ![combination-example-refined](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/upscale-3x.png)
#### 5. Interactive SAM Detector (Clipspace)
* When you right-click on the node that outputs 'MASK' and 'IMAGE', a menu called "Open in SAM Detector" appears, as shown in the following picture. Clicking on the menu opens a dialog in SAM's functionality, allowing you to generate a segment mask.
![samdetector-menu](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/SAMDetector-menu.png)
* By clicking the left mouse button on a coordinate, a positive prompt in blue color is entered, indicating the area that should be included. Clicking the right mouse button on a coordinate enters a negative prompt in red color, indicating the area that should be excluded. Positive prompts represent the areas that should be included, while negative prompts represent the areas that should be excluded.
* You can remove the points that were added by using the "undo" button. After selecting the points, pressing the "detect" button generates the mask. Additionally, you can adjust the fidelity slider to determine the extent to which the mask belongs to the confidence region.
![samdetector-dialog](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/SAMDetector-dialog.jpg)
* If you opened the dialog through "Open in SAM Detector" from the node, you can directly apply the changes by clicking the "Save to node" button. However, if you opened the dialog through the "clipspace" menu, you can save it to clipspace by clicking the "Save" button.
![samdetector-result](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/images/SAMDetector-result.jpg)
* When you execute using the reflected mask in the node, you can observe that the image and mask are displayed separately.
## Others Tutorials
* [ComfyUI-extension-tutorials/ComfyUI-Impact-Pack](https://github.com/ltdrdata/ComfyUI-extension-tutorials/tree/Main/ComfyUI-Impact-Pack) - You can find various tutorials and workflows on this page.
* [Advanced Tutorial](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/advanced.md)
* [SAM Application](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/sam.md)
* [PreviewBridge](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/previewbridge.md)
* [Mask Pointer](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/maskpointer.md)
* [ONNX Tutorial](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/ONNX.md)
* [CLIPSeg Tutorial](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/clipseg.md)
* [Extreme Highresolution Upscale](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/extreme-upscale.md)
* [TwoSamplersForMask](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/TwoSamplers.md)
* [TwoAdvancedSamplersForMask](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/TwoAdvancedSamplers.md)
* [Advanced Iterative Upscale: PK_HOOK](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/pk_hook.md)
* [Advanced Iterative Upscale: TwoSamplersForMask Upscale Provider](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/TwoSamplersUpscale.md)
* [Interactive SAM + PreviewBridge](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/sam_with_preview_bridge.md)
* [ImageSender/ImageReceiver/LatentSender/LatentReceiver](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/sender_receiver.md)
* [ImpactWildcardProcessor](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/ImpactWildcardProcessor.md)
## Credits
ComfyUI/[ComfyUI](https://github.com/comfyanonymous/ComfyUI) - A powerful and modular stable diffusion GUI.
dustysys/[ddetailer](https://github.com/dustysys/ddetailer) - DDetailer for Stable-diffusion-webUI extension.
Bing-su/[dddetailer](https://github.com/Bing-su/dddetailer) - The anime-face-detector used in ddetailer has been updated to be compatible with mmdet 3.0.0, and we have also applied a patch to the pycocotools dependency for Windows environment in ddetailer.
facebook/[segment-anything](https://github.com/facebookresearch/segment-anything) - Segmentation Anything!
hysts/[anime-face-detector](https://github.com/hysts/anime-face-detector) - Creator of `anime-face_yolov3`, which has impressive performance on a variety of art styles.
open-mmlab/[mmdetection](https://github.com/open-mmlab/mmdetection) - Object detection toolset. `dd-person_mask2former` was trained via transfer learning using their [R-50 Mask2Former instance segmentation model](https://github.com/open-mmlab/mmdetection/tree/master/configs/mask2former#instance-segmentation) as a base.
biegert/[ComfyUI-CLIPSeg](https://github.com/biegert/ComfyUI-CLIPSeg) - This is a custom node that enables the use of CLIPSeg technology, which can find segments through prompts, in ComfyUI.
BlenderNeok/[ComfyUI-TiledKSampler](https://github.com/BlenderNeko/ComfyUI_TiledKSampler) -
The tile sampler allows high-resolution sampling even in places with low GPU VRAM.
BlenderNeok/[ComfyUI_Noise](https://github.com/BlenderNeko/ComfyUI_Noise) - The noise injection feature relies on this function.
WASasquatch/[was-node-suite-comfyui](https://github.com/WASasquatch/was-node-suite-comfyui) - A powerful custom node extensions of ComfyUI.
Trung0246/[ComfyUI-0246](https://github.com/Trung0246/ComfyUI-0246) - Nice bypass hack!
@@ -1,504 +0,0 @@
"""
@author: Dr.Lt.Data
@title: Impact Pack
@nickname: Impact Pack
@description: This extension offers various detector nodes and detailer nodes that allow you to configure a workflow that automatically enhances facial details. And provide iterative upscaler.
"""
import shutil
import folder_paths
import os
import sys
import traceback
comfy_path = os.path.dirname(folder_paths.__file__)
impact_path = os.path.join(os.path.dirname(__file__))
subpack_path = os.path.join(os.path.dirname(__file__), "impact_subpack")
modules_path = os.path.join(os.path.dirname(__file__), "modules")
wildcards_path = os.path.join(os.path.dirname(__file__), "wildcards")
custom_wildcards_path = os.path.join(os.path.dirname(__file__), "custom_wildcards")
sys.path.append(modules_path)
import impact.config
import impact.sample_error_enhancer
print(f"### Loading: ComfyUI-Impact-Pack ({impact.config.version})")
def do_install():
import importlib
spec = importlib.util.spec_from_file_location('impact_install', os.path.join(os.path.dirname(__file__), 'install.py'))
impact_install = importlib.util.module_from_spec(spec)
spec.loader.exec_module(impact_install)
# ensure dependency
if not os.path.exists(os.path.join(subpack_path, ".git")) and os.path.exists(subpack_path):
print(f"### CompfyUI-Impact-Pack: corrupted subpack detected.")
shutil.rmtree(subpack_path)
if impact.config.get_config()['dependency_version'] < impact.config.dependency_version or not os.path.exists(subpack_path):
print(f"### ComfyUI-Impact-Pack: Updating dependencies [{impact.config.get_config()['dependency_version']} -> {impact.config.dependency_version}]")
do_install()
sys.path.append(subpack_path)
# Core
# recheck dependencies for colab
try:
import impact.subpack_nodes # This import must be done before cv2.
import folder_paths
import torch
import cv2
import numpy as np
import comfy.samplers
import comfy.sd
import warnings
from PIL import Image, ImageFilter
from skimage.measure import label, regionprops
from collections import namedtuple
import piexif
if not impact.config.get_config()['mmdet_skip']:
import mmcv
from mmdet.apis import (inference_detector, init_detector)
from mmdet.evaluation import get_classes
except:
import importlib
print("### ComfyUI-Impact-Pack: Reinstall dependencies (several dependencies are missing.)")
do_install()
import impact.impact_server # to load server api
def setup_js():
import nodes
js_dest_path = os.path.join(comfy_path, "web", "extensions", "impact-pack")
if hasattr(nodes, "EXTENSION_WEB_DIRS"):
if os.path.exists(js_dest_path):
shutil.rmtree(js_dest_path)
else:
print(f"[WARN] ComfyUI-Impact-Pack: Your ComfyUI version is outdated. Please update to the latest version.")
# setup js
if not os.path.exists(js_dest_path):
os.makedirs(js_dest_path)
js_src_path = os.path.join(impact_path, "js", "impact-pack.js")
shutil.copy(js_src_path, js_dest_path)
js_src_path = os.path.join(impact_path, "js", "impact-sam-editor.js")
shutil.copy(js_src_path, js_dest_path)
js_src_path = os.path.join(impact_path, "js", "comboBoolMigration.js")
shutil.copy(js_src_path, js_dest_path)
setup_js()
from impact.impact_pack import *
from impact.detectors import *
from impact.pipe import *
from impact.logics import *
from impact.util_nodes import *
from impact.segs_nodes import *
from impact.special_samplers import *
from impact.hf_nodes import *
from impact.bridge_nodes import *
from impact.hook_nodes import *
from impact.animatediff_nodes import *
import threading
wildcard_path = impact.config.get_config()['custom_wildcards']
def wildcard_load():
with wildcards.wildcard_lock:
impact.wildcards.read_wildcard_dict(wildcards_path)
try:
impact.wildcards.read_wildcard_dict(impact.config.get_config()['custom_wildcards'])
except Exception as e:
print(f"[Impact Pack] Failed to load custom wildcards directory.")
print(f"[Impact Pack] Wildcards loading done.")
threading.Thread(target=wildcard_load).start()
NODE_CLASS_MAPPINGS = {
"SAMLoader": SAMLoader,
"CLIPSegDetectorProvider": CLIPSegDetectorProvider,
"ONNXDetectorProvider": ONNXDetectorProvider,
"BitwiseAndMaskForEach": BitwiseAndMaskForEach,
"SubtractMaskForEach": SubtractMaskForEach,
"DetailerForEach": DetailerForEach,
"DetailerForEachDebug": DetailerForEachTest,
"DetailerForEachPipe": DetailerForEachPipe,
"DetailerForEachDebugPipe": DetailerForEachTestPipe,
"DetailerForEachPipeForAnimateDiff": DetailerForEachPipeForAnimateDiff,
"SAMDetectorCombined": SAMDetectorCombined,
"SAMDetectorSegmented": SAMDetectorSegmented,
"FaceDetailer": FaceDetailer,
"FaceDetailerPipe": FaceDetailerPipe,
"MaskDetailerPipe": MaskDetailerPipe,
"ToDetailerPipe": ToDetailerPipe,
"ToDetailerPipeSDXL": ToDetailerPipeSDXL,
"FromDetailerPipe": FromDetailerPipe,
"FromDetailerPipe_v2": FromDetailerPipe_v2,
"FromDetailerPipeSDXL": FromDetailerPipe_SDXL,
"ToBasicPipe": ToBasicPipe,
"FromBasicPipe": FromBasicPipe,
"FromBasicPipe_v2": FromBasicPipe_v2,
"BasicPipeToDetailerPipe": BasicPipeToDetailerPipe,
"BasicPipeToDetailerPipeSDXL": BasicPipeToDetailerPipeSDXL,
"DetailerPipeToBasicPipe": DetailerPipeToBasicPipe,
"EditBasicPipe": EditBasicPipe,
"EditDetailerPipe": EditDetailerPipe,
"EditDetailerPipeSDXL": EditDetailerPipeSDXL,
"LatentPixelScale": LatentPixelScale,
"PixelKSampleUpscalerProvider": PixelKSampleUpscalerProvider,
"PixelKSampleUpscalerProviderPipe": PixelKSampleUpscalerProviderPipe,
"IterativeLatentUpscale": IterativeLatentUpscale,
"IterativeImageUpscale": IterativeImageUpscale,
"PixelTiledKSampleUpscalerProvider": PixelTiledKSampleUpscalerProvider,
"PixelTiledKSampleUpscalerProviderPipe": PixelTiledKSampleUpscalerProviderPipe,
"TwoSamplersForMaskUpscalerProvider": TwoSamplersForMaskUpscalerProvider,
"TwoSamplersForMaskUpscalerProviderPipe": TwoSamplersForMaskUpscalerProviderPipe,
"PixelKSampleHookCombine": PixelKSampleHookCombine,
"DenoiseScheduleHookProvider": DenoiseScheduleHookProvider,
"StepsScheduleHookProvider": StepsScheduleHookProvider,
"CfgScheduleHookProvider": CfgScheduleHookProvider,
"NoiseInjectionHookProvider": NoiseInjectionHookProvider,
"UnsamplerHookProvider": UnsamplerHookProvider,
"CoreMLDetailerHookProvider": CoreMLDetailerHookProvider,
"PreviewDetailerHookProvider": PreviewDetailerHookProvider,
"DetailerHookCombine": DetailerHookCombine,
"NoiseInjectionDetailerHookProvider": NoiseInjectionDetailerHookProvider,
"UnsamplerDetailerHookProvider": UnsamplerDetailerHookProvider,
"DenoiseSchedulerDetailerHookProvider": DenoiseSchedulerDetailerHookProvider,
"SEGSOrderedFilterDetailerHookProvider": SEGSOrderedFilterDetailerHookProvider,
"SEGSRangeFilterDetailerHookProvider": SEGSRangeFilterDetailerHookProvider,
"SEGSLabelFilterDetailerHookProvider": SEGSLabelFilterDetailerHookProvider,
"BitwiseAndMask": BitwiseAndMask,
"SubtractMask": SubtractMask,
"AddMask": AddMask,
"ImpactSegsAndMask": SegsBitwiseAndMask,
"ImpactSegsAndMaskForEach": SegsBitwiseAndMaskForEach,
"EmptySegs": EmptySEGS,
"MediaPipeFaceMeshToSEGS": MediaPipeFaceMeshToSEGS,
"MaskToSEGS": MaskToSEGS,
"MaskToSEGS_for_AnimateDiff": MaskToSEGS_for_AnimateDiff,
"ToBinaryMask": ToBinaryMask,
"MasksToMaskList": MasksToMaskList,
"MaskListToMaskBatch": MaskListToMaskBatch,
"ImageListToImageBatch": ImageListToImageBatch,
"SetDefaultImageForSEGS": DefaultImageForSEGS,
"RemoveImageFromSEGS": RemoveImageFromSEGS,
"BboxDetectorSEGS": BboxDetectorForEach,
"SegmDetectorSEGS": SegmDetectorForEach,
"ONNXDetectorSEGS": BboxDetectorForEach,
"ImpactSimpleDetectorSEGS_for_AD": SimpleDetectorForAnimateDiff,
"ImpactSimpleDetectorSEGS": SimpleDetectorForEach,
"ImpactSimpleDetectorSEGSPipe": SimpleDetectorForEachPipe,
"ImpactControlNetApplySEGS": ControlNetApplySEGS,
"ImpactControlNetApplyAdvancedSEGS": ControlNetApplyAdvancedSEGS,
"ImpactControlNetClearSEGS": ControlNetClearSEGS,
"ImpactIPAdapterApplySEGS": IPAdapterApplySEGS,
"ImpactDecomposeSEGS": DecomposeSEGS,
"ImpactAssembleSEGS": AssembleSEGS,
"ImpactFrom_SEG_ELT": From_SEG_ELT,
"ImpactEdit_SEG_ELT": Edit_SEG_ELT,
"ImpactDilate_Mask_SEG_ELT": Dilate_SEG_ELT,
"ImpactDilateMask": DilateMask,
"ImpactGaussianBlurMask": GaussianBlurMask,
"ImpactDilateMaskInSEGS": DilateMaskInSEGS,
"ImpactGaussianBlurMaskInSEGS": GaussianBlurMaskInSEGS,
"ImpactScaleBy_BBOX_SEG_ELT": SEG_ELT_BBOX_ScaleBy,
"BboxDetectorCombined_v2": BboxDetectorCombined,
"SegmDetectorCombined_v2": SegmDetectorCombined,
"SegsToCombinedMask": SegsToCombinedMask,
"KSamplerProvider": KSamplerProvider,
"TwoSamplersForMask": TwoSamplersForMask,
"TiledKSamplerProvider": TiledKSamplerProvider,
"KSamplerAdvancedProvider": KSamplerAdvancedProvider,
"TwoAdvancedSamplersForMask": TwoAdvancedSamplersForMask,
"PreviewBridge": PreviewBridge,
"PreviewBridgeLatent": PreviewBridgeLatent,
"ImageSender": ImageSender,
"ImageReceiver": ImageReceiver,
"LatentSender": LatentSender,
"LatentReceiver": LatentReceiver,
"ImageMaskSwitch": ImageMaskSwitch,
"LatentSwitch": GeneralSwitch,
"SEGSSwitch": GeneralSwitch,
"ImpactSwitch": GeneralSwitch,
"ImpactInversedSwitch": GeneralInversedSwitch,
"ImpactWildcardProcessor": ImpactWildcardProcessor,
"ImpactWildcardEncode": ImpactWildcardEncode,
"SEGSDetailer": SEGSDetailer,
"SEGSPaste": SEGSPaste,
"SEGSPreview": SEGSPreview,
"SEGSPreviewCNet": SEGSPreviewCNet,
"SEGSToImageList": SEGSToImageList,
"ImpactSEGSToMaskList": SEGSToMaskList,
"ImpactSEGSToMaskBatch": SEGSToMaskBatch,
"ImpactSEGSConcat": SEGSConcat,
"ImpactSEGSPicker": SEGSPicker,
"ImpactMakeTileSEGS": MakeTileSEGS,
"SEGSDetailerForAnimateDiff": SEGSDetailerForAnimateDiff,
"ImpactKSamplerBasicPipe": KSamplerBasicPipe,
"ImpactKSamplerAdvancedBasicPipe": KSamplerAdvancedBasicPipe,
"ReencodeLatent": ReencodeLatent,
"ReencodeLatentPipe": ReencodeLatentPipe,
"ImpactImageBatchToImageList": ImageBatchToImageList,
"ImpactMakeImageList": MakeImageList,
"ImpactMakeImageBatch": MakeImageBatch,
"RegionalSampler": RegionalSampler,
"RegionalSamplerAdvanced": RegionalSamplerAdvanced,
"CombineRegionalPrompts": CombineRegionalPrompts,
"RegionalPrompt": RegionalPrompt,
"ImpactCombineConditionings": CombineConditionings,
"ImpactConcatConditionings": ConcatConditionings,
"ImpactSEGSLabelAssign": SEGSLabelAssign,
"ImpactSEGSLabelFilter": SEGSLabelFilter,
"ImpactSEGSRangeFilter": SEGSRangeFilter,
"ImpactSEGSOrderedFilter": SEGSOrderedFilter,
"ImpactCompare": ImpactCompare,
"ImpactConditionalBranch": ImpactConditionalBranch,
"ImpactConditionalBranchSelMode": ImpactConditionalBranchSelMode,
"ImpactIfNone": ImpactIfNone,
"ImpactConvertDataType": ImpactConvertDataType,
"ImpactLogicalOperators": ImpactLogicalOperators,
"ImpactInt": ImpactInt,
"ImpactFloat": ImpactFloat,
"ImpactValueSender": ImpactValueSender,
"ImpactValueReceiver": ImpactValueReceiver,
"ImpactImageInfo": ImpactImageInfo,
"ImpactLatentInfo": ImpactLatentInfo,
"ImpactMinMax": ImpactMinMax,
"ImpactNeg": ImpactNeg,
"ImpactConditionalStopIteration": ImpactConditionalStopIteration,
"ImpactStringSelector": StringSelector,
"RemoveNoiseMask": RemoveNoiseMask,
"ImpactLogger": ImpactLogger,
"ImpactDummyInput": ImpactDummyInput,
"ImpactQueueTrigger": ImpactQueueTrigger,
"ImpactQueueTriggerCountdown": ImpactQueueTriggerCountdown,
"ImpactSetWidgetValue": ImpactSetWidgetValue,
"ImpactNodeSetMuteState": ImpactNodeSetMuteState,
"ImpactControlBridge": ImpactControlBridge,
"ImpactIsNotEmptySEGS": ImpactNotEmptySEGS,
"ImpactSleep": ImpactSleep,
"ImpactRemoteBoolean": ImpactRemoteBoolean,
"ImpactRemoteInt": ImpactRemoteInt,
"ImpactHFTransformersClassifierProvider": HF_TransformersClassifierProvider,
"ImpactSEGSClassify": SEGS_Classify
}
NODE_DISPLAY_NAME_MAPPINGS = {
"SAMLoader": "SAMLoader (Impact)",
"BboxDetectorSEGS": "BBOX Detector (SEGS)",
"SegmDetectorSEGS": "SEGM Detector (SEGS)",
"ONNXDetectorSEGS": "ONNX Detector (SEGS/legacy) - use BBOXDetector",
"ImpactSimpleDetectorSEGS_for_AD": "Simple Detector for AnimateDiff (SEGS)",
"ImpactSimpleDetectorSEGS": "Simple Detector (SEGS)",
"ImpactSimpleDetectorSEGSPipe": "Simple Detector (SEGS/pipe)",
"ImpactControlNetApplySEGS": "ControlNetApply (SEGS)",
"ImpactControlNetApplyAdvancedSEGS": "ControlNetApplyAdvanced (SEGS)",
"ImpactIPAdapterApplySEGS": "IPAdapterApply (SEGS)",
"BboxDetectorCombined_v2": "BBOX Detector (combined)",
"SegmDetectorCombined_v2": "SEGM Detector (combined)",
"SegsToCombinedMask": "SEGS to MASK (combined)",
"MediaPipeFaceMeshToSEGS": "MediaPipe FaceMesh to SEGS",
"MaskToSEGS": "MASK to SEGS",
"MaskToSEGS_for_AnimateDiff": "MASK to SEGS for AnimateDiff",
"BitwiseAndMaskForEach": "Bitwise(SEGS & SEGS)",
"SubtractMaskForEach": "Bitwise(SEGS - SEGS)",
"ImpactSegsAndMask": "Bitwise(SEGS & MASK)",
"ImpactSegsAndMaskForEach": "Bitwise(SEGS & MASKS ForEach)",
"BitwiseAndMask": "Bitwise(MASK & MASK)",
"SubtractMask": "Bitwise(MASK - MASK)",
"AddMask": "Bitwise(MASK + MASK)",
"DetailerForEach": "Detailer (SEGS)",
"DetailerForEachPipe": "Detailer (SEGS/pipe)",
"DetailerForEachDebug": "DetailerDebug (SEGS)",
"DetailerForEachDebugPipe": "DetailerDebug (SEGS/pipe)",
"SEGSDetailerForAnimateDiff": "SEGSDetailer For AnimateDiff (SEGS/pipe)",
"DetailerForEachPipeForAnimateDiff": "Detailer For AnimateDiff (SEGS/pipe)",
"SAMDetectorCombined": "SAMDetector (combined)",
"SAMDetectorSegmented": "SAMDetector (segmented)",
"FaceDetailerPipe": "FaceDetailer (pipe)",
"MaskDetailerPipe": "MaskDetailer (pipe)",
"FromDetailerPipeSDXL": "FromDetailer (SDXL/pipe)",
"BasicPipeToDetailerPipeSDXL": "BasicPipe -> DetailerPipe (SDXL)",
"EditDetailerPipeSDXL": "Edit DetailerPipe (SDXL)",
"BasicPipeToDetailerPipe": "BasicPipe -> DetailerPipe",
"DetailerPipeToBasicPipe": "DetailerPipe -> BasicPipe",
"EditBasicPipe": "Edit BasicPipe",
"EditDetailerPipe": "Edit DetailerPipe",
"LatentPixelScale": "Latent Scale (on Pixel Space)",
"IterativeLatentUpscale": "Iterative Upscale (Latent/on Pixel Space)",
"IterativeImageUpscale": "Iterative Upscale (Image)",
"TwoSamplersForMaskUpscalerProvider": "TwoSamplersForMask Upscaler Provider",
"TwoSamplersForMaskUpscalerProviderPipe": "TwoSamplersForMask Upscaler Provider (pipe)",
"ReencodeLatent": "Reencode Latent",
"ReencodeLatentPipe": "Reencode Latent (pipe)",
"ImpactKSamplerBasicPipe": "KSampler (pipe)",
"ImpactKSamplerAdvancedBasicPipe": "KSampler (Advanced/pipe)",
"ImpactSEGSLabelAssign": "SEGS Assign (label)",
"ImpactSEGSLabelFilter": "SEGS Filter (label)",
"ImpactSEGSRangeFilter": "SEGS Filter (range)",
"ImpactSEGSOrderedFilter": "SEGS Filter (ordered)",
"ImpactSEGSConcat": "SEGS Concat",
"ImpactSEGSToMaskList": "SEGS to Mask List",
"ImpactSEGSToMaskBatch": "SEGS to Mask Batch",
"ImpactSEGSPicker": "Picker (SEGS)",
"ImpactMakeTileSEGS": "Make Tile SEGS",
"ImpactDecomposeSEGS": "Decompose (SEGS)",
"ImpactAssembleSEGS": "Assemble (SEGS)",
"ImpactFrom_SEG_ELT": "From SEG_ELT",
"ImpactEdit_SEG_ELT": "Edit SEG_ELT",
"ImpactDilate_Mask_SEG_ELT": "Dilate Mask (SEG_ELT)",
"ImpactScaleBy_BBOX_SEG_ELT": "ScaleBy BBOX (SEG_ELT)",
"ImpactDilateMask": "Dilate Mask",
"ImpactGaussianBlurMask": "Gaussian Blur Mask",
"ImpactDilateMaskInSEGS": "Dilate Mask (SEGS)",
"ImpactGaussianBlurMaskInSEGS": "Gaussian Blur Mask (SEGS)",
"PreviewBridge": "Preview Bridge (Image)",
"PreviewBridgeLatent": "Preview Bridge (Latent)",
"ImageSender": "Image Sender",
"ImageReceiver": "Image Receiver",
"ImageMaskSwitch": "Switch (images, mask)",
"ImpactSwitch": "Switch (Any)",
"ImpactInversedSwitch": "Inversed Switch (Any)",
"MasksToMaskList": "Masks to Mask List",
"MaskListToMaskBatch": "Mask List to Masks",
"ImpactImageBatchToImageList": "Image batch to Image List",
"ImageListToImageBatch": "Image List to Image Batch",
"ImpactMakeImageList": "Make Image List",
"ImpactMakeImageBatch": "Make Image Batch",
"ImpactStringSelector": "String Selector",
"ImpactIsNotEmptySEGS": "SEGS isn't Empty",
"SetDefaultImageForSEGS": "Set Default Image for SEGS",
"RemoveImageFromSEGS": "Remove Image from SEGS",
"RemoveNoiseMask": "Remove Noise Mask",
"ImpactCombineConditionings": "Combine Conditionings",
"ImpactConcatConditionings": "Concat Conditionings",
"ImpactQueueTrigger": "Queue Trigger",
"ImpactQueueTriggerCountdown": "Queue Trigger (Countdown)",
"ImpactSetWidgetValue": "Set Widget Value",
"ImpactNodeSetMuteState": "Set Mute State",
"ImpactControlBridge": "Control Bridge",
"ImpactSleep": "Sleep",
"ImpactRemoteBoolean": "Remote Boolean (on prompt)",
"ImpactRemoteInt": "Remote Int (on prompt)",
"ImpactHFTransformersClassifierProvider": "HF Transformers Classifier Provider",
"ImpactSEGSClassify": "SEGS Classify",
"LatentSwitch": "Switch (latent/legacy)",
"SEGSSwitch": "Switch (SEGS/legacy)",
"SEGSPreviewCNet": "SEGSPreview (CNET Image)"
}
if not impact.config.get_config()['mmdet_skip']:
from impact.mmdet_nodes import *
import impact.legacy_nodes
NODE_CLASS_MAPPINGS.update({
"MMDetDetectorProvider": MMDetDetectorProvider,
"MMDetLoader": impact.legacy_nodes.MMDetLoader,
"MaskPainter": impact.legacy_nodes.MaskPainter,
"SegsMaskCombine": impact.legacy_nodes.SegsMaskCombine,
"BboxDetectorForEach": impact.legacy_nodes.BboxDetectorForEach,
"SegmDetectorForEach": impact.legacy_nodes.SegmDetectorForEach,
"BboxDetectorCombined": impact.legacy_nodes.BboxDetectorCombined,
"SegmDetectorCombined": impact.legacy_nodes.SegmDetectorCombined,
})
NODE_DISPLAY_NAME_MAPPINGS.update({
"MaskPainter": "MaskPainter (Deprecated)",
"MMDetLoader": "MMDetLoader (Legacy)",
"SegsMaskCombine": "SegsMaskCombine (Legacy)",
"BboxDetectorForEach": "BboxDetectorForEach (Legacy)",
"SegmDetectorForEach": "SegmDetectorForEach (Legacy)",
"BboxDetectorCombined": "BboxDetectorCombined (Legacy)",
"SegmDetectorCombined": "SegmDetectorCombined (Legacy)",
})
try:
import impact.subpack_nodes
NODE_CLASS_MAPPINGS.update(impact.subpack_nodes.NODE_CLASS_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(impact.subpack_nodes.NODE_DISPLAY_NAME_MAPPINGS)
except Exception as e:
print("### ComfyUI-Impact-Pack: (IMPORT FAILED) Subpack\n")
print(" The module at the `custom_nodes/ComfyUI-Impact-Pack/impact_subpack` path appears to be incomplete.")
print(" Recommended to delete the path and restart ComfyUI.")
print(" If the issue persists, please report it to https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues.")
print("\n---------------------------------")
traceback.print_exc()
print("---------------------------------\n")
WEB_DIRECTORY = "js"
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
try:
import cm_global
cm_global.register_extension('ComfyUI-Impact-Pack',
{'version': config.version_code,
'name': 'Impact Pack',
'nodes': set(NODE_CLASS_MAPPINGS.keys()),
'description': 'This extension provides inpainting functionality based on the detector and detailer, along with convenient workflow features like wildcards and logics.', })
except:
pass
@@ -1,38 +0,0 @@
import os
import sys
import time
import platform
import shutil
import subprocess
comfy_path = '../..'
def rmtree(path):
retry_count = 3
while True:
try:
retry_count -= 1
if platform.system() == "Windows":
subprocess.check_call(['attrib', '-R', path + '\\*', '/S'])
shutil.rmtree(path)
return True
except Exception as ex:
print(f"ex: {ex}")
time.sleep(3)
if retry_count < 0:
raise ex
print(f"Uninstall retry({retry_count})")
js_dest_path = os.path.join(comfy_path, "web", "extensions", "impact-pack")
if os.path.exists(js_dest_path):
rmtree(js_dest_path)
@@ -1,8 +0,0 @@
[default]
dependency_version = 20
mmdet_skip = True
sam_editor_cpu = False
sam_editor_model = sam_vit_b_01ec64.pth
custom_wildcards = /home/salt/clone/storyteller/storyteller-ml/workflows/comfy/ComfyUI/custom_nodes/ComfyUI-Impact-Pack/custom_wildcards
disable_gpu_opencv = True
@@ -1,5 +0,0 @@
__pycache__
*.ini
wildcards/**
.vscode/
.idea/
@@ -1,661 +0,0 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.
@@ -1,18 +0,0 @@
# ComfyUI-Impact-Subpack
This extension serves as a complement to the Impact Pack, offering features that are not deemed suitable for inclusion by default in the ComfyUI Impact Pack
The nodes in this repository cannot be used standalone and depend on [ComfyUI-Impact-Pack](https://github.com/ltdrdata/ComfyUI-Impact-Pack).
## Nodes
* UltralyticsDetectorProvider - This node provides an object detection detector based on Ultralystics.
* By using this Detector Provider, you can replace the existing mmdet-based detector.
## Credits
ComfyUI/[ComfyUI](https://github.com/comfyanonymous/ComfyUI) - A powerful and modular stable diffusion GUI.
Bing-su/[adetailer](https://github.com/Bing-su/adetailer/) - This repo sitoryprovides an object detection model and features based on Ultralystics.
huggingface/Bingsu/[adetailer](https://huggingface.co/Bingsu/adetailer/tree/main) - This repository offers various models based on Ultralystics.
* You can download other models supported by the UltralyticsDetectorProvider from here.
@@ -1,213 +0,0 @@
from pathlib import Path
from PIL import Image
import impact.core as core
import cv2
import numpy as np
from torchvision.transforms.functional import to_pil_image
import torch
try:
from ultralytics import YOLO
except Exception as e:
print(e)
print(f"\n!!!!!\n\n[ComfyUI-Impact-Subpack] If this error occurs, please check the following link:\n\thttps://github.com/ltdrdata/ComfyUI-Impact-Pack/blob/Main/troubleshooting/TROUBLESHOOTING.md\n\n!!!!!\n")
raise e
def load_yolo(model_path: str):
try:
return YOLO(model_path)
except ModuleNotFoundError:
# https://github.com/ultralytics/ultralytics/issues/3856
YOLO("yolov8n.pt")
return YOLO(model_path)
def inference_bbox(
model,
image: Image.Image,
confidence: float = 0.3,
device: str = "",
):
pred = model(image, conf=confidence, device=device)
bboxes = pred[0].boxes.xyxy.cpu().numpy()
cv2_image = np.array(image)
if len(cv2_image.shape) == 3:
cv2_image = cv2_image[:, :, ::-1].copy() # Convert RGB to BGR for cv2 processing
else:
# Handle the grayscale image here
# For example, you might want to convert it to a 3-channel grayscale image for consistency:
cv2_image = cv2.cvtColor(cv2_image, cv2.COLOR_GRAY2BGR)
cv2_gray = cv2.cvtColor(cv2_image, cv2.COLOR_BGR2GRAY)
segms = []
for x0, y0, x1, y1 in bboxes:
cv2_mask = np.zeros(cv2_gray.shape, np.uint8)
cv2.rectangle(cv2_mask, (int(x0), int(y0)), (int(x1), int(y1)), 255, -1)
cv2_mask_bool = cv2_mask.astype(bool)
segms.append(cv2_mask_bool)
n, m = bboxes.shape
if n == 0:
return [[], [], [], []]
results = [[], [], [], []]
for i in range(len(bboxes)):
results[0].append(pred[0].names[int(pred[0].boxes[i].cls.item())])
results[1].append(bboxes[i])
results[2].append(segms[i])
results[3].append(pred[0].boxes[i].conf.cpu().numpy())
return results
def inference_segm(
model,
image: Image.Image,
confidence: float = 0.3,
device: str = "",
):
pred = model(image, conf=confidence, device=device)
bboxes = pred[0].boxes.xyxy.cpu().numpy()
n, m = bboxes.shape
if n == 0:
return [[], [], [], []]
# NOTE: masks.data will be None when n == 0
segms = pred[0].masks.data.cpu().numpy()
results = [[], [], [], []]
for i in range(len(bboxes)):
results[0].append(pred[0].names[int(pred[0].boxes[i].cls.item())])
results[1].append(bboxes[i])
mask = torch.from_numpy(segms[i])
scaled_mask = torch.nn.functional.interpolate(mask.unsqueeze(0).unsqueeze(0), size=(image.size[1], image.size[0]),
mode='bilinear', align_corners=False)
scaled_mask = scaled_mask.squeeze().squeeze()
results[2].append(scaled_mask.numpy())
results[3].append(pred[0].boxes[i].conf.cpu().numpy())
return results
class UltraBBoxDetector:
bbox_model = None
def __init__(self, bbox_model):
self.bbox_model = bbox_model
def detect(self, image, threshold, dilation, crop_factor, drop_size=1, detailer_hook=None):
drop_size = max(drop_size, 1)
detected_results = inference_bbox(self.bbox_model, core.tensor2pil(image), threshold)
segmasks = core.create_segmasks(detected_results)
if dilation > 0:
segmasks = core.dilate_masks(segmasks, dilation)
items = []
h = image.shape[1]
w = image.shape[2]
for x, label in zip(segmasks, detected_results[0]):
item_bbox = x[0]
item_mask = x[1]
y1, x1, y2, x2 = item_bbox
if x2 - x1 > drop_size and y2 - y1 > drop_size: # minimum dimension must be (2,2) to avoid squeeze issue
crop_region = core.make_crop_region(w, h, item_bbox, crop_factor)
if detailer_hook is not None:
crop_region = detailer_hook.post_crop_region(w, h, item_bbox, crop_region)
cropped_image = core.crop_image(image, crop_region)
cropped_mask = core.crop_ndarray2(item_mask, crop_region)
confidence = x[2]
# bbox_size = (item_bbox[2]-item_bbox[0],item_bbox[3]-item_bbox[1]) # (w,h)
item = core.SEG(cropped_image, cropped_mask, confidence, crop_region, item_bbox, label, None)
items.append(item)
shape = image.shape[1], image.shape[2]
segs = shape, items
if detailer_hook is not None and hasattr(detailer_hook, "post_detection"):
segs = detailer_hook.post_detection(segs)
return segs
def detect_combined(self, image, threshold, dilation):
detected_results = inference_bbox(self.bbox_model, core.tensor2pil(image), threshold)
segmasks = core.create_segmasks(detected_results)
if dilation > 0:
segmasks = core.dilate_masks(segmasks, dilation)
return core.combine_masks(segmasks)
def setAux(self, x):
pass
class UltraSegmDetector:
bbox_model = None
def __init__(self, bbox_model):
self.bbox_model = bbox_model
def detect(self, image, threshold, dilation, crop_factor, drop_size=1, detailer_hook=None):
drop_size = max(drop_size, 1)
detected_results = inference_segm(self.bbox_model, core.tensor2pil(image), threshold)
segmasks = core.create_segmasks(detected_results)
if dilation > 0:
segmasks = core.dilate_masks(segmasks, dilation)
items = []
h = image.shape[1]
w = image.shape[2]
for x, label in zip(segmasks, detected_results[0]):
item_bbox = x[0]
item_mask = x[1]
y1, x1, y2, x2 = item_bbox
if x2 - x1 > drop_size and y2 - y1 > drop_size: # minimum dimension must be (2,2) to avoid squeeze issue
crop_region = core.make_crop_region(w, h, item_bbox, crop_factor)
if detailer_hook is not None:
crop_region = detailer_hook.post_crop_region(w, h, item_bbox, crop_region)
cropped_image = core.crop_image(image, crop_region)
cropped_mask = core.crop_ndarray2(item_mask, crop_region)
confidence = x[2]
# bbox_size = (item_bbox[2]-item_bbox[0],item_bbox[3]-item_bbox[1]) # (w,h)
item = core.SEG(cropped_image, cropped_mask, confidence, crop_region, item_bbox, label, None)
items.append(item)
shape = image.shape[1], image.shape[2]
segs = shape, items
if detailer_hook is not None and hasattr(detailer_hook, "post_detection"):
segs = detailer_hook.post_detection(segs)
return segs
def detect_combined(self, image, threshold, dilation):
detected_results = inference_segm(self.bbox_model, core.tensor2pil(image), threshold)
segmasks = core.create_segmasks(detected_results)
if dilation > 0:
segmasks = core.dilate_masks(segmasks, dilation)
return core.combine_masks(segmasks)
def setAux(self, x):
pass
@@ -1,45 +0,0 @@
import os
import folder_paths
import impact.core as core
import impact.subcore as subcore
from impact.utils import add_folder_path_and_extensions
version_code = 20
print(f"### Loading: ComfyUI-Impact-Pack (Subpack: V0.4)")
model_path = folder_paths.models_dir
add_folder_path_and_extensions("ultralytics_bbox", [os.path.join(model_path, "ultralytics", "bbox")], folder_paths.supported_pt_extensions)
add_folder_path_and_extensions("ultralytics_segm", [os.path.join(model_path, "ultralytics", "segm")], folder_paths.supported_pt_extensions)
add_folder_path_and_extensions("ultralytics", [os.path.join(model_path, "ultralytics")], folder_paths.supported_pt_extensions)
class UltralyticsDetectorProvider:
@classmethod
def INPUT_TYPES(s):
bboxs = ["bbox/"+x for x in folder_paths.get_filename_list("ultralytics_bbox")]
segms = ["segm/"+x for x in folder_paths.get_filename_list("ultralytics_segm")]
return {"required": {"model_name": (bboxs + segms, )}}
RETURN_TYPES = ("BBOX_DETECTOR", "SEGM_DETECTOR")
FUNCTION = "doit"
CATEGORY = "ImpactPack"
def doit(self, model_name):
model_path = folder_paths.get_full_path("ultralytics", model_name)
model = subcore.load_yolo(model_path)
if model_name.startswith("bbox"):
return subcore.UltraBBoxDetector(model), core.NO_SEGM_DETECTOR()
else:
return subcore.UltraBBoxDetector(model), subcore.UltraSegmDetector(model)
NODE_CLASS_MAPPINGS = {
"UltralyticsDetectorProvider": UltralyticsDetectorProvider
}
NODE_DISPLAY_NAME_MAPPINGS = {
}
@@ -1,32 +0,0 @@
import os
import sys
from torchvision.datasets.utils import download_url
subpack_path = os.path.join(os.path.dirname(__file__))
comfy_path = os.path.join(subpack_path, '..', '..', '..')
sys.path.append(comfy_path)
import folder_paths
model_path = folder_paths.models_dir
ultralytics_bbox_path = os.path.join(model_path, "ultralytics", "bbox")
ultralytics_segm_path = os.path.join(model_path, "ultralytics", "segm")
if not os.path.exists(os.path.join(subpack_path, '..', '..', 'skip_download_model')):
if not os.path.exists(ultralytics_bbox_path):
os.makedirs(ultralytics_bbox_path)
if not os.path.exists(ultralytics_segm_path):
os.makedirs(ultralytics_segm_path)
if not os.path.exists(os.path.join(ultralytics_bbox_path, "face_yolov8m.pt")):
download_url("https://huggingface.co/Bingsu/adetailer/resolve/main/face_yolov8m.pt",
ultralytics_bbox_path)
if not os.path.exists(os.path.join(ultralytics_bbox_path, "hand_yolov8s.pt")):
download_url("https://huggingface.co/Bingsu/adetailer/resolve/main/hand_yolov8s.pt",
ultralytics_bbox_path)
if not os.path.exists(os.path.join(ultralytics_segm_path, "person_yolov8m-seg.pt")):
download_url("https://huggingface.co/Bingsu/adetailer/resolve/main/person_yolov8m-seg.pt",
ultralytics_segm_path)
@@ -1 +0,0 @@
ultralytics!=8.0.177
@@ -1,285 +0,0 @@
import os
import shutil
import sys
import subprocess
import threading
import locale
import traceback
import re
if sys.argv[0] == 'install.py':
sys.path.append('.') # for portable version
impact_path = os.path.join(os.path.dirname(__file__), "modules")
old_subpack_path = os.path.join(os.path.dirname(__file__), "subpack")
subpack_path = os.path.join(os.path.dirname(__file__), "impact_subpack")
subpack_repo = "https://github.com/ltdrdata/ComfyUI-Impact-Subpack"
comfy_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
sys.path.append(impact_path)
sys.path.append(comfy_path)
# ---
def handle_stream(stream, is_stdout):
stream.reconfigure(encoding=locale.getpreferredencoding(), errors='replace')
for msg in stream:
if is_stdout:
print(msg, end="", file=sys.stdout)
else:
print(msg, end="", file=sys.stderr)
def process_wrap(cmd_str, cwd=None, handler=None):
print(f"[Impact Pack] EXECUTE: {cmd_str} in '{cwd}'")
process = subprocess.Popen(cmd_str, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1)
if handler is None:
handler = handle_stream
stdout_thread = threading.Thread(target=handler, args=(process.stdout, True))
stderr_thread = threading.Thread(target=handler, args=(process.stderr, False))
stdout_thread.start()
stderr_thread.start()
stdout_thread.join()
stderr_thread.join()
return process.wait()
# ---
pip_list = None
def get_installed_packages():
global pip_list
if pip_list is None:
try:
result = subprocess.check_output([sys.executable, '-m', 'pip', 'list'], universal_newlines=True)
pip_list = set([line.split()[0].lower() for line in result.split('\n') if line.strip()])
except subprocess.CalledProcessError as e:
print(f"[ComfyUI-Manager] Failed to retrieve the information of installed pip packages.")
return set()
return pip_list
def is_installed(name):
name = name.strip()
pattern = r'([^<>!=]+)([<>!=]=?)'
match = re.search(pattern, name)
if match:
name = match.group(1)
result = name.lower() in get_installed_packages()
return result
def is_requirements_installed(file_path):
print(f"req_path: {file_path}")
if os.path.exists(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
for line in lines:
if not is_installed(line):
return False
return True
try:
import platform
import folder_paths
from torchvision.datasets.utils import download_url
import impact.config
print("### ComfyUI-Impact-Pack: Check dependencies")
if "python_embeded" in sys.executable or "python_embedded" in sys.executable:
pip_install = [sys.executable, '-s', '-m', 'pip', 'install']
mim_install = [sys.executable, '-s', '-m', 'mim', 'install']
else:
pip_install = [sys.executable, '-m', 'pip', 'install']
mim_install = [sys.executable, '-m', 'mim', 'install']
def ensure_subpack():
import git
if os.path.exists(subpack_path):
try:
repo = git.Repo(subpack_path)
repo.remotes.origin.pull()
except:
traceback.print_exc()
if platform.system() == 'Windows':
print(f"[ComfyUI-Impact-Pack] Please turn off ComfyUI and remove '{subpack_path}' and restart ComfyUI.")
else:
shutil.rmtree(subpack_path)
git.Repo.clone_from(subpack_repo, subpack_path)
else:
git.Repo.clone_from(subpack_repo, subpack_path)
if os.path.exists(old_subpack_path):
shutil.rmtree(old_subpack_path)
def remove_olds():
global comfy_path
comfy_path = os.path.dirname(folder_paths.__file__)
custom_nodes_path = os.path.join(comfy_path, "custom_nodes")
old_ini_path = os.path.join(custom_nodes_path, "impact-pack.ini")
old_py_path = os.path.join(custom_nodes_path, "comfyui-impact-pack.py")
if os.path.exists(impact.config.old_config_path):
impact.config.get_config()['mmdet_skip'] = False
os.remove(impact.config.old_config_path)
if os.path.exists(old_ini_path):
print(f"Delete legacy file: {old_ini_path}")
os.remove(old_ini_path)
if os.path.exists(old_py_path):
print(f"Delete legacy file: {old_py_path}")
os.remove(old_py_path)
def ensure_pip_packages_first():
subpack_req = os.path.join(subpack_path, "requirements.txt")
if os.path.exists(subpack_req) and not is_requirements_installed(subpack_req):
process_wrap(pip_install + ['-r', 'requirements.txt'], cwd=subpack_path)
if not impact.config.get_config()['mmdet_skip']:
process_wrap(pip_install + ['openmim'])
try:
import pycocotools
except Exception:
if platform.system() not in ["Windows"] or platform.machine() not in ["AMD64", "x86_64"]:
print(f"Your system is {platform.system()}; !! You need to install 'libpython3-dev' for this step. !!")
process_wrap(pip_install + ['pycocotools'])
else:
pycocotools = {
(3, 8): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp38-cp38-win_amd64.whl",
(3, 9): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp39-cp39-win_amd64.whl",
(3, 10): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp310-cp310-win_amd64.whl",
(3, 11): "https://github.com/Bing-su/dddetailer/releases/download/pycocotools/pycocotools-2.0.6-cp311-cp311-win_amd64.whl",
}
version = sys.version_info[:2]
url = pycocotools[version]
process_wrap(pip_install + [url])
def ensure_pip_packages_last():
my_path = os.path.dirname(__file__)
requirements_path = os.path.join(my_path, "requirements.txt")
if not is_requirements_installed(requirements_path):
process_wrap(pip_install + ['-r', requirements_path])
# fallback
try:
import segment_anything
from skimage.measure import label, regionprops
import piexif
except Exception:
process_wrap(pip_install + ['-r', requirements_path])
# !! cv2 importing test must be very last !!
try:
import cv2
except Exception:
try:
if not is_installed('opencv-python'):
process_wrap(pip_install + ['opencv-python'])
if not is_installed('opencv-python-headless'):
process_wrap(pip_install + ['opencv-python-headless'])
except:
print(f"[ERROR] ComfyUI-Impact-Pack: failed to install 'opencv-python'. Please, install manually.")
def ensure_mmdet_package():
try:
import mmcv
import mmdet
from mmdet.evaluation import get_classes
except Exception:
process_wrap(pip_install + ['opendatalab==0.0.9'])
process_wrap(pip_install + ['-U', 'openmim'])
process_wrap(mim_install + ['mmcv>=2.0.0rc4, <2.1.0'])
process_wrap(mim_install + ['mmdet==3.0.0'])
process_wrap(mim_install + ['mmengine==0.7.4'])
def install():
remove_olds()
subpack_install_script = os.path.join(subpack_path, "install.py")
print(f"### ComfyUI-Impact-Pack: Updating subpack")
try:
import git
except Exception:
if not is_installed('GitPython'):
process_wrap(pip_install + ['GitPython'])
ensure_subpack() # The installation of the subpack must take place before ensure_pip. cv2 triggers a permission error.
if os.path.exists(subpack_install_script):
process_wrap([sys.executable, 'install.py'], cwd=subpack_path)
if not is_requirements_installed(os.path.join(subpack_path, 'requirements.txt')):
process_wrap(pip_install + ['-r', 'requirements.txt'], cwd=subpack_path)
else:
print(f"### ComfyUI-Impact-Pack: (Install Failed) Subpack\nFile not found: `{subpack_install_script}`")
ensure_pip_packages_first()
if not impact.config.get_config()['mmdet_skip']:
ensure_mmdet_package()
ensure_pip_packages_last()
# Download model
print("### ComfyUI-Impact-Pack: Check basic models")
model_path = folder_paths.models_dir
bbox_path = os.path.join(model_path, "mmdets", "bbox")
sam_path = os.path.join(model_path, "sams")
onnx_path = os.path.join(model_path, "onnx")
if not os.path.exists(os.path.join(os.path.dirname(__file__), '..', 'skip_download_model')):
if not os.path.exists(bbox_path):
os.makedirs(bbox_path)
if not impact.config.get_config()['mmdet_skip']:
if not os.path.exists(os.path.join(bbox_path, "mmdet_anime-face_yolov3.pth")):
download_url("https://huggingface.co/dustysys/ddetailer/resolve/main/mmdet/bbox/mmdet_anime-face_yolov3.pth", bbox_path)
if not os.path.exists(os.path.join(bbox_path, "mmdet_anime-face_yolov3.py")):
download_url("https://raw.githubusercontent.com/Bing-su/dddetailer/master/config/mmdet_anime-face_yolov3.py", bbox_path)
if not os.path.exists(os.path.join(sam_path, "sam_vit_b_01ec64.pth")):
download_url("https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth", sam_path)
if not os.path.exists(onnx_path):
print(f"### ComfyUI-Impact-Pack: onnx model directory created ({onnx_path})")
os.mkdir(onnx_path)
impact.config.write_config()
install()
except Exception as e:
print("[ERROR] ComfyUI-Impact-Pack: Dependency installation has failed. Please install manually.")
traceback.print_exc()
@@ -1,35 +0,0 @@
import { ComfyApp, app } from "../../scripts/app.js";
let conflict_check = undefined;
app.registerExtension({
name: "Comfy.impact.comboBoolMigration",
nodeCreated(node, app) {
for(let i in node.widgets) {
let widget = node.widgets[i];
if(conflict_check == undefined) {
conflict_check = !!app.extensions.find((ext) => ext.name === "Comfy.comboBoolMigration");
}
if(conflict_check)
return;
if(widget.type == "toggle") {
let value = widget.value;
var v = Object.getOwnPropertyDescriptor(widget, 'value');
if(!v) {
Object.defineProperty(widget, "value", {
set: (value) => {
delete widget.value;
widget.value = value == true || value == widget.options.on;
},
get: () => { return value; }
});
}
}
}
}
});
@@ -1,95 +0,0 @@
import { api } from "../../scripts/api.js";
import { app } from "../../scripts/app.js";
let original_show = app.ui.dialog.show;
function dialog_show_wrapper(html) {
if (typeof html === "string") {
if(html.includes("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE")) {
return;
}
this.textElement.innerHTML = html;
} else {
this.textElement.replaceChildren(html);
}
this.element.style.display = "flex";
}
app.ui.dialog.show = dialog_show_wrapper;
function nodeFeedbackHandler(event) {
let nodes = app.graph._nodes_by_id;
let node = nodes[event.detail.node_id];
if(node) {
const w = node.widgets.find((w) => event.detail.widget_name === w.name);
if(w) {
w.value = event.detail.value;
}
}
}
api.addEventListener("impact-node-feedback", nodeFeedbackHandler);
function setMuteState(event) {
let nodes = app.graph._nodes_by_id;
let node = nodes[event.detail.node_id];
if(node) {
if(event.detail.is_active)
node.mode = 0;
else
node.mode = 2;
}
}
api.addEventListener("impact-node-mute-state", setMuteState);
async function bridgeContinue(event) {
let nodes = app.graph._nodes_by_id;
let node = nodes[event.detail.node_id];
if(node) {
const mutes = new Set(event.detail.mutes);
const actives = new Set(event.detail.actives);
const bypasses = new Set(event.detail.bypasses);
for(let i in app.graph._nodes_by_id) {
let this_node = app.graph._nodes_by_id[i];
if(mutes.has(i)) {
this_node.mode = 2;
}
else if(actives.has(i)) {
this_node.mode = 0;
}
else if(bypasses.has(i)) {
this_node.mode = 4;
}
}
await app.queuePrompt(0, 1);
}
}
api.addEventListener("impact-bridge-continue", bridgeContinue);
function addQueue(event) {
app.queuePrompt(0, 1);
}
api.addEventListener("impact-add-queue", addQueue);
function refreshPreview(event) {
let node_id = event.detail.node_id;
let item = event.detail.item;
let img = new Image();
img.src = `/view?filename=${item.filename}&subfolder=${item.subfolder}&type=${item.type}&no-cache=${Date.now()}`;
let node = app.graph._nodes_by_id[node_id];
if(node)
node.imgs = [img];
}
api.addEventListener("impact-preview", refreshPreview);
@@ -1,229 +0,0 @@
import { ComfyApp, app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
function load_image(str) {
let base64String = canvas.toDataURL('image/png');
let img = new Image();
img.src = base64String;
}
function getFileItem(baseType, path) {
try {
let pathType = baseType;
if (path.endsWith("[output]")) {
pathType = "output";
path = path.slice(0, -9);
} else if (path.endsWith("[input]")) {
pathType = "input";
path = path.slice(0, -8);
} else if (path.endsWith("[temp]")) {
pathType = "temp";
path = path.slice(0, -7);
}
const subfolder = path.substring(0, path.lastIndexOf('/'));
const filename = path.substring(path.lastIndexOf('/') + 1);
return {
filename: filename,
subfolder: subfolder,
type: pathType
};
}
catch(exception) {
return null;
}
}
async function loadImageFromUrl(image, node_id, v, need_to_load) {
let item = getFileItem('temp', v);
if(item) {
let params = `?node_id=${node_id}&filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`;
let res = await api.fetchApi('/impact/set/pb_id_image'+params, { cache: "no-store" });
if(res.status == 200) {
let pb_id = await res.text();
if(need_to_load) {;
image.src = `view?filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`;
}
return pb_id;
}
else {
return `$${node_id}-0`;
}
}
else {
return `$${node_id}-0`;
}
}
async function loadImageFromId(image, v) {
let res = await api.fetchApi('/impact/get/pb_id_image?id='+v, { cache: "no-store" });
if(res.status == 200) {
let item = await res.json();
image.src = `view?filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`;
return true;
}
return false;
}
app.registerExtension({
name: "Comfy.Impact.img",
nodeCreated(node, app) {
if(node.comfyClass == "PreviewBridge" || node.comfyClass == "PreviewBridgeLatent") {
let w = node.widgets.find(obj => obj.name === 'image');
node._imgs = [new Image()];
node.imageIndex = 0;
Object.defineProperty(w, 'value', {
async set(v) {
if(w._lock)
return;
const stackTrace = new Error().stack;
if(stackTrace.includes('presetText.js'))
return;
var image = new Image();
if(v && v.constructor == String && v.startsWith('$')) {
// from node feedback
let need_to_load = node._imgs[0].src == '';
if(await loadImageFromId(image, v, need_to_load)) {
w._value = v;
if(node._imgs[0].src == '') {
node._imgs = [image];
}
}
else {
w._value = `$${node.id}-0`;
}
}
else {
// from clipspace
w._lock = true;
w._value = await loadImageFromUrl(image, node.id, v, false);
w._lock = false;
}
},
get() {
if(w._value == undefined) {
w._value = `$${node.id}-0`;
}
return w._value;
}
});
Object.defineProperty(node, 'imgs', {
set(v) {
const stackTrace = new Error().stack;
if(v && v.length == 0)
return;
else if(stackTrace.includes('pasteFromClipspace')) {
let sp = new URLSearchParams(v[0].src.split("?")[1]);
let str = "";
if(sp.get('subfolder')) {
str += sp.get('subfolder') + '/';
}
str += `${sp.get("filename")} [${sp.get("type")}]`;
w.value = str;
}
node._imgs = v;
},
get() {
return node._imgs;
}
});
}
if(node.comfyClass == "ImageReceiver") {
let path_widget = node.widgets.find(obj => obj.name === 'image');
let w = node.widgets.find(obj => obj.name === 'image_data');
let stw_widget = node.widgets.find(obj => obj.name === 'save_to_workflow');
w._value = "";
Object.defineProperty(w, 'value', {
set(v) {
if(v != '[IMAGE DATA]')
w._value = v;
},
get() {
const stackTrace = new Error().stack;
if(!stackTrace.includes('draw') && !stackTrace.includes('graphToPrompt') && stackTrace.includes('app.js')) {
return "[IMAGE DATA]";
}
else {
if(stw_widget.value)
return w._value;
else
return "";
}
}
});
let set_img_act = (v) => {
node._img = v;
var canvas = document.createElement('canvas');
canvas.width = v[0].width;
canvas.height = v[0].height;
var context = canvas.getContext('2d');
context.drawImage(v[0], 0, 0, v[0].width, v[0].height);
var base64Image = canvas.toDataURL('image/png');
w.value = base64Image;
};
Object.defineProperty(node, 'imgs', {
set(v) {
if (!v[0].complete) {
let orig_onload = v[0].onload;
v[0].onload = function(v2) {
if(orig_onload)
orig_onload();
set_img_act(v);
};
}
else {
set_img_act(v);
}
},
get() {
if(this._img == undefined && w.value != '') {
this._img = [new Image()];
if(stw_widget.value && w.value != '[IMAGE DATA]')
this._img[0].src = w.value;
}
else if(this._img == undefined && path_widget.value) {
let image = new Image();
image.src = path_widget.value;
try {
let item = getFileItem('temp', path_widget.value);
let params = `?filename=${item.filename}&type=${item.type}&subfolder=${item.subfolder}`;
let res = api.fetchApi('/view/validate'+params, { cache: "no-store" }).then(response => response);
if(res.status == 200) {
image.src = 'view'+params;
}
this._img = [new Image()]; // placeholder
image.onload = function(v) {
set_img_act([image]);
};
}
catch {
}
}
return this._img;
}
});
}
}
})
@@ -1,795 +0,0 @@
import { ComfyApp, app } from "../../scripts/app.js";
import { ComfyDialog, $el } from "../../scripts/ui.js";
import { api } from "../../scripts/api.js";
let wildcards_list = [];
async function load_wildcards() {
let res = await api.fetchApi('/impact/wildcards/list');
let data = await res.json();
wildcards_list = data.data;
}
load_wildcards();
export function get_wildcards_list() {
return wildcards_list;
}
// temporary implementation (copying from https://github.com/pythongosssss/ComfyUI-WD14-Tagger)
// I think this should be included into master!!
class ImpactProgressBadge {
constructor() {
if (!window.__progress_badge__) {
window.__progress_badge__ = Symbol("__impact_progress_badge__");
}
this.symbol = window.__progress_badge__;
}
getState(node) {
return node[this.symbol] || {};
}
setState(node, state) {
node[this.symbol] = state;
app.canvas.setDirty(true);
}
addStatusHandler(nodeType) {
if (nodeType[this.symbol]?.statusTagHandler) {
return;
}
if (!nodeType[this.symbol]) {
nodeType[this.symbol] = {};
}
nodeType[this.symbol] = {
statusTagHandler: true,
};
api.addEventListener("impact/update_status", ({ detail }) => {
let { node, progress, text } = detail;
const n = app.graph.getNodeById(+(node || app.runningNodeId));
if (!n) return;
const state = this.getState(n);
state.status = Object.assign(state.status || {}, { progress: text ? progress : null, text: text || null });
this.setState(n, state);
});
const self = this;
const onDrawForeground = nodeType.prototype.onDrawForeground;
nodeType.prototype.onDrawForeground = function (ctx) {
const r = onDrawForeground?.apply?.(this, arguments);
const state = self.getState(this);
if (!state?.status?.text) {
return r;
}
const { fgColor, bgColor, text, progress, progressColor } = { ...state.status };
ctx.save();
ctx.font = "12px sans-serif";
const sz = ctx.measureText(text);
ctx.fillStyle = bgColor || "dodgerblue";
ctx.beginPath();
ctx.roundRect(0, -LiteGraph.NODE_TITLE_HEIGHT - 20, sz.width + 12, 20, 5);
ctx.fill();
if (progress) {
ctx.fillStyle = progressColor || "green";
ctx.beginPath();
ctx.roundRect(0, -LiteGraph.NODE_TITLE_HEIGHT - 20, (sz.width + 12) * progress, 20, 5);
ctx.fill();
}
ctx.fillStyle = fgColor || "#fff";
ctx.fillText(text, 6, -LiteGraph.NODE_TITLE_HEIGHT - 6);
ctx.restore();
return r;
};
}
}
const input_tracking = {};
const input_dirty = {};
const output_tracking = {};
function progressExecuteHandler(event) {
if(event.detail.output.aux){
const id = event.detail.node;
if(input_tracking.hasOwnProperty(id)) {
if(input_tracking.hasOwnProperty(id) && input_tracking[id][0] != event.detail.output.aux[0]) {
input_dirty[id] = true;
}
else{
}
}
input_tracking[id] = event.detail.output.aux;
}
}
function imgSendHandler(event) {
if(event.detail.images.length > 0){
let data = event.detail.images[0];
let filename = `${data.filename} [${data.type}]`;
let nodes = app.graph._nodes;
for(let i in nodes) {
if(nodes[i].type == 'ImageReceiver') {
if(nodes[i].widgets[1].value == event.detail.link_id) {
if(data.subfolder)
nodes[i].widgets[0].value = `${data.subfolder}/${data.filename} [${data.type}]`;
else
nodes[i].widgets[0].value = `${data.filename} [${data.type}]`;
let img = new Image();
img.onload = (event) => {
nodes[i].imgs = [img];
nodes[i].size[1] = Math.max(200, nodes[i].size[1]);
app.canvas.setDirty(true);
};
img.src = `/view?filename=${data.filename}&type=${data.type}&subfolder=${data.subfolder}`+app.getPreviewFormatParam();
}
}
}
}
}
function latentSendHandler(event) {
if(event.detail.images.length > 0){
let data = event.detail.images[0];
let filename = `${data.filename} [${data.type}]`;
let nodes = app.graph._nodes;
for(let i in nodes) {
if(nodes[i].type == 'LatentReceiver') {
if(nodes[i].widgets[1].value == event.detail.link_id) {
if(data.subfolder)
nodes[i].widgets[0].value = `${data.subfolder}/${data.filename} [${data.type}]`;
else
nodes[i].widgets[0].value = `${data.filename} [${data.type}]`;
let img = new Image();
img.src = `/view?filename=${data.filename}&type=${data.type}&subfolder=${data.subfolder}`+app.getPreviewFormatParam();
nodes[i].imgs = [img];
nodes[i].size[1] = Math.max(200, nodes[i].size[1]);
}
}
}
}
}
function valueSendHandler(event) {
let nodes = app.graph._nodes;
for(let i in nodes) {
if(nodes[i].type == 'ImpactValueReceiver') {
if(nodes[i].widgets[2].value == event.detail.link_id) {
nodes[i].widgets[1].value = event.detail.value;
let typ = typeof event.detail.value;
if(typ == 'string') {
nodes[i].widgets[0].value = "STRING";
}
else if(typ == "boolean") {
nodes[i].widgets[0].value = "BOOLEAN";
}
else if(typ != "number") {
nodes[i].widgets[0].value = typeof event.detail.value;
}
else if(Number.isInteger(event.detail.value)) {
nodes[i].widgets[0].value = "INT";
}
else {
nodes[i].widgets[0].value = "FLOAT";
}
}
}
}
}
const impactProgressBadge = new ImpactProgressBadge();
api.addEventListener("stop-iteration", () => {
document.getElementById("autoQueueCheckbox").checked = false;
});
api.addEventListener("value-send", valueSendHandler);
api.addEventListener("img-send", imgSendHandler);
api.addEventListener("latent-send", latentSendHandler);
api.addEventListener("executed", progressExecuteHandler);
app.registerExtension({
name: "Comfy.Impack",
loadedGraphNode(node, app) {
if (node.comfyClass == "MaskPainter") {
input_dirty[node.id + ""] = true;
}
},
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name == "IterativeLatentUpscale" || nodeData.name == "IterativeImageUpscale"
|| nodeData.name == "RegionalSampler"|| nodeData.name == "RegionalSamplerAdvanced") {
impactProgressBadge.addStatusHandler(nodeType);
}
if(nodeData.name == "ImpactControlBridge") {
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
if(!link_info || this.inputs[0].type != '*')
return;
// assign type
let slot_type = '*';
if(type == 2) {
slot_type = link_info.type;
}
else {
const node = app.graph.getNodeById(link_info.origin_id);
slot_type = node.outputs[link_info.origin_slot].type;
}
this.inputs[0].type = slot_type;
this.outputs[0].type = slot_type;
this.outputs[0].label = slot_type;
}
}
if(nodeData.name == "ImpactConditionalBranch" || nodeData.name == "ImpactConditionalBranchSelMode") {
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
if(!link_info || this.inputs[0].type != '*')
return;
if(index >= 2)
return;
// assign type
let slot_type = '*';
if(type == 2) {
slot_type = link_info.type;
}
else {
const node = app.graph.getNodeById(link_info.origin_id);
slot_type = node.outputs[link_info.origin_slot].type;
}
this.inputs[0].type = slot_type;
this.inputs[1].type = slot_type;
this.outputs[0].type = slot_type;
this.outputs[0].label = slot_type;
}
}
if(nodeData.name == "ImpactCompare") {
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
if(!link_info || this.inputs[0].type != '*' || type == 2)
return;
// assign type
const node = app.graph.getNodeById(link_info.origin_id);
let slot_type = node.outputs[link_info.origin_slot].type;
this.inputs[0].type = slot_type;
this.inputs[1].type = slot_type;
}
}
if(nodeData.name === 'ImpactInversedSwitch') {
nodeData.output = ['*'];
nodeData.output_is_list = [false];
nodeData.output_name = ['output1'];
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
if(!link_info)
return;
if(type == 2) {
// connect output
if(connected){
if(app.graph._nodes_by_id[link_info.target_id].type == 'Reroute') {
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
}
if(this.outputs[0].type == '*'){
if(link_info.type == '*') {
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
}
else {
// propagate type
this.outputs[0].type = link_info.type;
this.outputs[0].name = link_info.type;
for(let i in this.inputs) {
if(this.inputs[i].name != 'select')
this.inputs[i].type = link_info.type;
}
}
}
}
}
else {
if(app.graph._nodes_by_id[link_info.origin_id].type == 'Reroute')
this.disconnectInput(link_info.target_slot);
// connect input
if(this.inputs[0].type == '*'){
const node = app.graph.getNodeById(link_info.origin_id);
let origin_type = node.outputs[link_info.origin_slot].type;
if(origin_type == '*') {
this.disconnectInput(link_info.target_slot);
return;
}
for(let i in this.inputs) {
if(this.inputs[i].name != 'select')
this.inputs[i].type = origin_type;
}
this.outputs[0].type = origin_type;
this.outputs[0].name = origin_type;
}
return;
}
if (!connected && this.outputs.length > 1) {
const stackTrace = new Error().stack;
if(
!stackTrace.includes('LGraphNode.prototype.connect') && // for touch device
!stackTrace.includes('LGraphNode.connect') && // for mouse device
!stackTrace.includes('loadGraphData')) {
if(this.outputs[link_info.origin_slot].links.length == 0)
this.removeOutput(link_info.origin_slot);
}
}
let slot_i = 1;
for (let i = 0; i < this.outputs.length; i++) {
this.outputs[i].name = `output${slot_i}`
slot_i++;
}
let last_slot = this.outputs[this.outputs.length - 1];
if (last_slot.slot_index == link_info.origin_slot) {
this.addOutput(`output${slot_i}`, this.outputs[0].type);
}
let select_slot = this.inputs.find(x => x.name == "select");
if(this.widgets) {
this.widgets[0].options.max = select_slot?this.outputs.length-1:this.outputs.length;
this.widgets[0].value = Math.min(this.widgets[0].value, this.widgets[0].options.max);
if(this.widgets[0].options.max > 0 && this.widgets[0].value == 0)
this.widgets[0].value = 1;
}
}
}
if (nodeData.name === 'ImpactMakeImageList' || nodeData.name === 'ImpactMakeImageBatch' ||
nodeData.name === 'CombineRegionalPrompts' ||
nodeData.name === 'ImpactCombineConditionings' || nodeData.name === 'ImpactConcatConditionings' ||
nodeData.name === 'ImpactSEGSConcat' ||
nodeData.name === 'ImpactSwitch' || nodeData.name === 'LatentSwitch' || nodeData.name == 'SEGSSwitch') {
var input_name = "input";
switch(nodeData.name) {
case 'ImpactMakeImageList':
case 'ImpactMakeImageBatch':
input_name = "image";
break;
case 'ImpactSEGSConcat':
input_name = "segs";
break;
case 'CombineRegionalPrompts':
input_name = "regional_prompts";
break;
case 'ImpactCombineConditionings':
case 'ImpactConcatConditionings':
input_name = "conditioning";
break;
case 'LatentSwitch':
input_name = "input";
break;
case 'SEGSSwitch':
input_name = "input";
break;
case 'ImpactSwitch':
input_name = "input";
}
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
if(!link_info)
return;
if(type == 2) {
// connect output
if(connected && index == 0){
if(nodeData.name == 'ImpactSwitch' && app.graph._nodes_by_id[link_info.target_id]?.type == 'Reroute') {
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
}
if(this.outputs[0].type == '*'){
if(link_info.type == '*') {
app.graph._nodes_by_id[link_info.target_id].disconnectInput(link_info.target_slot);
}
else {
// propagate type
this.outputs[0].type = link_info.type;
this.outputs[0].label = link_info.type;
this.outputs[0].name = link_info.type;
for(let i in this.inputs) {
let input_i = this.inputs[i];
if(input_i.name != 'select' && input_i.name != 'sel_mode')
input_i.type = link_info.type;
}
}
}
}
return;
}
else {
if(nodeData.name == 'ImpactSwitch' && app.graph._nodes_by_id[link_info.origin_id].type == 'Reroute')
this.disconnectInput(link_info.target_slot);
// connect input
if(this.inputs[index].name == 'select' || this.inputs[index].name == 'sel_mode')
return;
if(this.inputs[0].type == '*'){
const node = app.graph.getNodeById(link_info.origin_id);
let origin_type = node.outputs[link_info.origin_slot].type;
if(origin_type == '*') {
this.disconnectInput(link_info.target_slot);
return;
}
for(let i in this.inputs) {
let input_i = this.inputs[i];
if(input_i.name != 'select' && input_i.name != 'sel_mode')
input_i.type = origin_type;
}
this.outputs[0].type = origin_type;
this.outputs[0].label = origin_type;
this.outputs[0].name = origin_type;
}
}
let select_slot = this.inputs.find(x => x.name == "select");
let mode_slot = this.inputs.find(x => x.name == "sel_mode");
let converted_count = 0;
converted_count += select_slot?1:0;
converted_count += mode_slot?1:0;
if (!connected && (this.inputs.length > 1+converted_count)) {
const stackTrace = new Error().stack;
if(
!stackTrace.includes('LGraphNode.prototype.connect') && // for touch device
!stackTrace.includes('LGraphNode.connect') && // for mouse device
!stackTrace.includes('loadGraphData') &&
this.inputs[index].name != 'select') {
this.removeInput(index);
}
}
let slot_i = 1;
for (let i = 0; i < this.inputs.length; i++) {
let input_i = this.inputs[i];
if(input_i.name != 'select'&& input_i.name != 'sel_mode') {
input_i.name = `${input_name}${slot_i}`
slot_i++;
}
}
let last_slot = this.inputs[this.inputs.length - 1];
if (
(last_slot.name == 'select' && last_slot.name != 'sel_mode' && this.inputs[this.inputs.length - 2].link != undefined)
|| (last_slot.name != 'select' && last_slot.name != 'sel_mode' && last_slot.link != undefined)) {
this.addInput(`${input_name}${slot_i}`, this.outputs[0].type);
}
if(this.widgets) {
this.widgets[0].options.max = select_slot?this.inputs.length-1:this.inputs.length;
this.widgets[0].value = Math.min(this.widgets[0].value, this.widgets[0].options.max);
if(this.widgets[0].options.max > 0 && this.widgets[0].value == 0)
this.widgets[0].value = 1;
}
}
}
},
nodeCreated(node, app) {
if(node.comfyClass == "MaskPainter") {
node.addWidget("button", "Edit mask", null, () => {
ComfyApp.copyToClipspace(node);
ComfyApp.clipspace_return_node = node;
ComfyApp.open_maskeditor();
});
}
switch(node.comfyClass) {
case "ToDetailerPipe":
case "ToDetailerPipeSDXL":
case "BasicPipeToDetailerPipe":
case "BasicPipeToDetailerPipeSDXL":
case "EditDetailerPipe":
case "FaceDetailer":
case "DetailerForEach":
case "DetailerForEachDebug":
case "DetailerForEachPipe":
case "DetailerForEachDebugPipe":
{
for(let i in node.widgets) {
let widget = node.widgets[i];
if(widget.type === "customtext") {
widget.dynamicPrompts = false;
widget.inputEl.placeholder = "wildcard spec: if kept empty, this option will be ignored";
widget.serializeValue = () => {
return node.widgets[i].value;
};
}
}
}
break;
}
if(node.comfyClass == "ImpactSEGSLabelFilter" || node.comfyClass == "SEGSLabelFilterDetailerHookProvider") {
Object.defineProperty(node.widgets[0], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(node.widgets[1].value.trim() != "" && !node.widgets[1].value.trim().endsWith(","))
node.widgets[1].value += ", "
node.widgets[1].value += value;
node.widgets_values[1] = node.widgets[1].value;
}
node._value = value;
},
get: () => {
return node._value;
}
});
}
if(node.comfyClass == "UltralyticsDetectorProvider") {
let model_name_widget = node.widgets.find((w) => w.name === "model_name");
let orig_draw = node.onDrawForeground;
node.onDrawForeground = function (ctx) {
const r = orig_draw?.apply?.(this, arguments);
let is_seg = model_name_widget.value.startsWith('segm/') || model_name_widget.value.includes('-seg');
if(!is_seg) {
var slot_pos = new Float32Array(2);
var pos = node.getConnectionPos(false, 1, slot_pos);
pos[0] -= node.pos[0] - 10;
pos[1] -= node.pos[1];
ctx.beginPath();
ctx.strokeStyle = "red";
ctx.lineWidth = 4;
ctx.moveTo(pos[0] - 5, pos[1] - 5);
ctx.lineTo(pos[0] + 5, pos[1] + 5);
ctx.moveTo(pos[0] + 5, pos[1] - 5);
ctx.lineTo(pos[0] - 5, pos[1] + 5);
ctx.stroke();
}
}
}
if(
node.comfyClass == "ImpactWildcardEncode" || node.comfyClass == "ImpactWildcardProcessor"
|| node.comfyClass == "ToDetailerPipe" || node.comfyClass == "ToDetailerPipeSDXL"
|| node.comfyClass == "EditDetailerPipe" || node.comfyClass == "EditDetailerPipeSDXL"
|| node.comfyClass == "BasicPipeToDetailerPipe" || node.comfyClass == "BasicPipeToDetailerPipeSDXL") {
node._value = "Select the LoRA to add to the text";
node._wvalue = "Select the Wildcard to add to the text";
var tbox_id = 0;
var combo_id = 3;
var has_lora = true;
switch(node.comfyClass){
case "ImpactWildcardEncode":
tbox_id = 0;
combo_id = 3;
break;
case "ImpactWildcardProcessor":
tbox_id = 0;
combo_id = 4;
has_lora = false;
break;
case "ToDetailerPipe":
case "ToDetailerPipeSDXL":
case "EditDetailerPipe":
case "EditDetailerPipeSDXL":
case "BasicPipeToDetailerPipe":
case "BasicPipeToDetailerPipeSDXL":
tbox_id = 0;
combo_id = 1;
break;
}
Object.defineProperty(node.widgets[combo_id+1], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(value != "Select the Wildcard to add to the text") {
if(node.widgets[tbox_id].value != '')
node.widgets[tbox_id].value += ', '
node.widgets[tbox_id].value += value;
}
}
},
get: () => { return "Select the Wildcard to add to the text"; }
});
Object.defineProperty(node.widgets[combo_id+1].options, "values", {
set: (x) => {},
get: () => {
return wildcards_list;
}
});
if(has_lora) {
Object.defineProperty(node.widgets[combo_id], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(value != "Select the LoRA to add to the text") {
let lora_name = value;
if (lora_name.endsWith('.safetensors')) {
lora_name = lora_name.slice(0, -12);
}
node.widgets[tbox_id].value += `<lora:${lora_name}>`;
if(node.widgets_values) {
node.widgets_values[tbox_id] = node.widgets[tbox_id].value;
}
}
}
node._value = value;
},
get: () => { return "Select the LoRA to add to the text"; }
});
}
// Preventing validation errors from occurring in any situation.
if(has_lora) {
node.widgets[combo_id].serializeValue = () => { return "Select the LoRA to add to the text"; }
}
node.widgets[combo_id+1].serializeValue = () => { return "Select the Wildcard to add to the text"; }
}
if(node.comfyClass == "ImpactWildcardProcessor" || node.comfyClass == "ImpactWildcardEncode") {
node.widgets[0].inputEl.placeholder = "Wildcard Prompt (User input)";
node.widgets[1].inputEl.placeholder = "Populated Prompt (Will be generated automatically)";
node.widgets[1].inputEl.disabled = true;
const populated_text_widget = node.widgets.find((w) => w.name == 'populated_text');
const mode_widget = node.widgets.find((w) => w.name == 'mode');
// mode combo
Object.defineProperty(mode_widget, "value", {
set: (value) => {
node._mode_value = value == true || value == "Populate";
populated_text_widget.inputEl.disabled = value == true || value == "Populate";
},
get: () => {
if(node._mode_value != undefined)
return node._mode_value;
else
return true;
}
});
}
if (node.comfyClass == "MaskPainter") {
node.widgets[0].value = '#placeholder';
Object.defineProperty(node, "images", {
set: function(value) {
node._images = value;
},
get: function() {
const id = node.id+"";
if(node.widgets[0].value != '#placeholder') {
var need_invalidate = false;
if(input_dirty.hasOwnProperty(id) && input_dirty[id]) {
node.widgets[0].value = {...input_tracking[id][1]};
input_dirty[id] = false;
need_invalidate = true
this._images = app.nodeOutputs[id].images;
}
let filename = app.nodeOutputs[id]['aux'][1][0]['filename'];
let subfolder = app.nodeOutputs[id]['aux'][1][0]['subfolder'];
let type = app.nodeOutputs[id]['aux'][1][0]['type'];
let item =
{
image_hash: app.nodeOutputs[id]['aux'][0],
forward_filename: app.nodeOutputs[id]['aux'][1][0]['filename'],
forward_subfolder: app.nodeOutputs[id]['aux'][1][0]['subfolder'],
forward_type: app.nodeOutputs[id]['aux'][1][0]['type']
};
if(node._images) {
app.nodeOutputs[id].images = [{
...node._images[0],
...item
}];
node.widgets[0].value =
{
...node._images[0],
...item
};
}
else {
app.nodeOutputs[id].images = [{
...item
}];
node.widgets[0].value =
{
...item
};
}
if(need_invalidate) {
Promise.all(
app.nodeOutputs[id].images.map((src) => {
return new Promise((r) => {
const img = new Image();
img.onload = () => r(img);
img.onerror = () => r(null);
img.src = "/view?" + new URLSearchParams(src).toString();
});
})
).then((imgs) => {
this.imgs = imgs.filter(Boolean);
this.setSizeForImage?.();
app.graph.setDirtyCanvas(true);
});
app.nodeOutputs[id].images[0] = { ...node.widgets[0].value };
}
return app.nodeOutputs[id].images;
}
else {
return node._images;
}
}
});
}
}
});
@@ -1,636 +0,0 @@
import { app } from "../../scripts/app.js";
import { ComfyDialog, $el } from "../../scripts/ui.js";
import { ComfyApp } from "../../scripts/app.js";
import { ClipspaceDialog } from "../../extensions/core/clipspace.js";
function addMenuHandler(nodeType, cb) {
const getOpts = nodeType.prototype.getExtraMenuOptions;
nodeType.prototype.getExtraMenuOptions = function () {
const r = getOpts.apply(this, arguments);
cb.apply(this, arguments);
return r;
};
}
// Helper function to convert a data URL to a Blob object
function dataURLToBlob(dataURL) {
const parts = dataURL.split(';base64,');
const contentType = parts[0].split(':')[1];
const byteString = atob(parts[1]);
const arrayBuffer = new ArrayBuffer(byteString.length);
const uint8Array = new Uint8Array(arrayBuffer);
for (let i = 0; i < byteString.length; i++) {
uint8Array[i] = byteString.charCodeAt(i);
}
return new Blob([arrayBuffer], { type: contentType });
}
function loadedImageToBlob(image) {
const canvas = document.createElement('canvas');
canvas.width = image.width;
canvas.height = image.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0);
const dataURL = canvas.toDataURL('image/png', 1);
const blob = dataURLToBlob(dataURL);
return blob;
}
async function uploadMask(filepath, formData) {
await fetch('/upload/mask', {
method: 'POST',
body: formData
}).then(response => {}).catch(error => {
console.error('Error:', error);
});
ComfyApp.clipspace.imgs[ComfyApp.clipspace['selectedIndex']] = new Image();
ComfyApp.clipspace.imgs[ComfyApp.clipspace['selectedIndex']].src = `view?filename=${filepath.filename}&type=${filepath.type}`;
if(ComfyApp.clipspace.images)
ComfyApp.clipspace.images[ComfyApp.clipspace['selectedIndex']] = filepath;
ClipspaceDialog.invalidatePreview();
}
class ImpactSamEditorDialog extends ComfyDialog {
static instance = null;
static getInstance() {
if(!ImpactSamEditorDialog.instance) {
ImpactSamEditorDialog.instance = new ImpactSamEditorDialog();
}
return ImpactSamEditorDialog.instance;
}
constructor() {
super();
this.element = $el("div.comfy-modal", { parent: document.body },
[ $el("div.comfy-modal-content",
[...this.createButtons()]),
]);
}
createButtons() {
return [];
}
createButton(name, callback) {
var button = document.createElement("button");
button.innerText = name;
button.addEventListener("click", callback);
return button;
}
createLeftButton(name, callback) {
var button = this.createButton(name, callback);
button.style.cssFloat = "left";
button.style.marginRight = "4px";
return button;
}
createRightButton(name, callback) {
var button = this.createButton(name, callback);
button.style.cssFloat = "right";
button.style.marginLeft = "4px";
return button;
}
createLeftSlider(self, name, callback) {
const divElement = document.createElement('div');
divElement.id = "sam-confidence-slider";
divElement.style.cssFloat = "left";
divElement.style.fontFamily = "sans-serif";
divElement.style.marginRight = "4px";
divElement.style.color = "var(--input-text)";
divElement.style.backgroundColor = "var(--comfy-input-bg)";
divElement.style.borderRadius = "8px";
divElement.style.borderColor = "var(--border-color)";
divElement.style.borderStyle = "solid";
divElement.style.fontSize = "15px";
divElement.style.height = "21px";
divElement.style.padding = "1px 6px";
divElement.style.display = "flex";
divElement.style.position = "relative";
divElement.style.top = "2px";
self.confidence_slider_input = document.createElement('input');
self.confidence_slider_input.setAttribute('type', 'range');
self.confidence_slider_input.setAttribute('min', '0');
self.confidence_slider_input.setAttribute('max', '100');
self.confidence_slider_input.setAttribute('value', '70');
const labelElement = document.createElement("label");
labelElement.textContent = name;
divElement.appendChild(labelElement);
divElement.appendChild(self.confidence_slider_input);
self.confidence_slider_input.addEventListener("change", callback);
return divElement;
}
async detect_and_invalidate_mask_canvas(self) {
const mask_img = await self.detect(self);
const canvas = self.maskCtx.canvas;
const ctx = self.maskCtx;
ctx.clearRect(0, 0, canvas.width, canvas.height);
await new Promise((resolve, reject) => {
self.mask_image = new Image();
self.mask_image.onload = function() {
ctx.drawImage(self.mask_image, 0, 0, canvas.width, canvas.height);
resolve();
};
self.mask_image.onerror = reject;
self.mask_image.src = mask_img.src;
});
}
setlayout(imgCanvas, maskCanvas, pointsCanvas) {
const self = this;
// If it is specified as relative, using it only as a hidden placeholder for padding is recommended
// to prevent anomalies where it exceeds a certain size and goes outside of the window.
var placeholder = document.createElement("div");
placeholder.style.position = "relative";
placeholder.style.height = "50px";
var bottom_panel = document.createElement("div");
bottom_panel.style.position = "absolute";
bottom_panel.style.bottom = "0px";
bottom_panel.style.left = "20px";
bottom_panel.style.right = "20px";
bottom_panel.style.height = "50px";
var brush = document.createElement("div");
brush.id = "sam-brush";
brush.style.backgroundColor = "blue";
brush.style.outline = "2px solid pink";
brush.style.borderRadius = "50%";
brush.style.MozBorderRadius = "50%";
brush.style.WebkitBorderRadius = "50%";
brush.style.position = "absolute";
brush.style.zIndex = 100;
brush.style.pointerEvents = "none";
this.brush = brush;
this.element.appendChild(imgCanvas);
this.element.appendChild(maskCanvas);
this.element.appendChild(pointsCanvas);
this.element.appendChild(placeholder); // must below z-index than bottom_panel to avoid covering button
this.element.appendChild(bottom_panel);
document.body.appendChild(brush);
this.brush_size = 5;
var confidence_slider = this.createLeftSlider(self, "Confidence", (event) => {
self.confidence = event.target.value;
});
var clearButton = this.createLeftButton("Clear", () => {
self.maskCtx.clearRect(0, 0, self.maskCanvas.width, self.maskCanvas.height);
self.pointsCtx.clearRect(0, 0, self.pointsCanvas.width, self.pointsCanvas.height);
self.prompt_points = [];
self.invalidatePointsCanvas(self);
});
var detectButton = this.createLeftButton("Detect", () => self.detect_and_invalidate_mask_canvas(self));
var cancelButton = this.createRightButton("Cancel", () => {
document.removeEventListener("mouseup", ImpactSamEditorDialog.handleMouseUp);
document.removeEventListener("keydown", ImpactSamEditorDialog.handleKeyDown);
self.close();
});
self.saveButton = this.createRightButton("Save", () => {
document.removeEventListener("mouseup", ImpactSamEditorDialog.handleMouseUp);
document.removeEventListener("keydown", ImpactSamEditorDialog.handleKeyDown);
self.save(self);
});
var undoButton = this.createLeftButton("Undo", () => {
if(self.prompt_points.length > 0) {
self.prompt_points.pop();
self.pointsCtx.clearRect(0, 0, self.pointsCanvas.width, self.pointsCanvas.height);
self.invalidatePointsCanvas(self);
}
});
bottom_panel.appendChild(clearButton);
bottom_panel.appendChild(detectButton);
bottom_panel.appendChild(self.saveButton);
bottom_panel.appendChild(cancelButton);
bottom_panel.appendChild(confidence_slider);
bottom_panel.appendChild(undoButton);
imgCanvas.style.position = "relative";
imgCanvas.style.top = "200";
imgCanvas.style.left = "0";
maskCanvas.style.position = "absolute";
maskCanvas.style.opacity = 0.5;
pointsCanvas.style.position = "absolute";
}
show() {
this.mask_image = null;
self.prompt_points = [];
this.message_box = $el("p", ["Please wait a moment while the SAM model and the image are being loaded."]);
this.element.appendChild(this.message_box);
if(self.imgCtx) {
self.imgCtx.clearRect(0, 0, self.imageCanvas.width, self.imageCanvas.height);
}
const target_image_path = ComfyApp.clipspace.imgs[ComfyApp.clipspace['selectedIndex']].src;
this.load_sam(target_image_path);
if(!this.is_layout_created) {
// layout
const imgCanvas = document.createElement('canvas');
const maskCanvas = document.createElement('canvas');
const pointsCanvas = document.createElement('canvas');
imgCanvas.id = "imageCanvas";
maskCanvas.id = "maskCanvas";
pointsCanvas.id = "pointsCanvas";
this.setlayout(imgCanvas, maskCanvas, pointsCanvas);
// prepare content
this.imgCanvas = imgCanvas;
this.maskCanvas = maskCanvas;
this.pointsCanvas = pointsCanvas;
this.maskCtx = maskCanvas.getContext('2d');
this.pointsCtx = pointsCanvas.getContext('2d');
this.is_layout_created = true;
// replacement of onClose hook since close is not real close
const self = this;
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
if(self.last_display_style && self.last_display_style != 'none' && self.element.style.display == 'none') {
ComfyApp.onClipspaceEditorClosed();
}
self.last_display_style = self.element.style.display;
}
});
});
const config = { attributes: true };
observer.observe(this.element, config);
}
this.setImages(target_image_path, this.imgCanvas, this.pointsCanvas);
if(ComfyApp.clipspace_return_node) {
this.saveButton.innerText = "Save to node";
}
else {
this.saveButton.innerText = "Save";
}
this.saveButton.disabled = true;
this.element.style.display = "block";
this.element.style.zIndex = 8888; // NOTE: alert dialog must be high priority.
}
updateBrushPreview(self, event) {
event.preventDefault();
const centerX = event.pageX;
const centerY = event.pageY;
const brush = self.brush;
brush.style.width = self.brush_size * 2 + "px";
brush.style.height = self.brush_size * 2 + "px";
brush.style.left = (centerX - self.brush_size) + "px";
brush.style.top = (centerY - self.brush_size) + "px";
}
setImages(target_image_path, imgCanvas, pointsCanvas) {
const imgCtx = imgCanvas.getContext('2d');
const maskCtx = this.maskCtx;
const maskCanvas = this.maskCanvas;
const self = this;
// image load
const orig_image = new Image();
window.addEventListener("resize", () => {
// repositioning
imgCanvas.width = window.innerWidth - 250;
imgCanvas.height = window.innerHeight - 200;
// redraw image
let drawWidth = orig_image.width;
let drawHeight = orig_image.height;
if (orig_image.width > imgCanvas.width) {
drawWidth = imgCanvas.width;
drawHeight = (drawWidth / orig_image.width) * orig_image.height;
}
if (drawHeight > imgCanvas.height) {
drawHeight = imgCanvas.height;
drawWidth = (drawHeight / orig_image.height) * orig_image.width;
}
imgCtx.drawImage(orig_image, 0, 0, drawWidth, drawHeight);
// update mask
pointsCanvas.width = drawWidth;
pointsCanvas.height = drawHeight;
pointsCanvas.style.top = imgCanvas.offsetTop + "px";
pointsCanvas.style.left = imgCanvas.offsetLeft + "px";
maskCanvas.width = drawWidth;
maskCanvas.height = drawHeight;
maskCanvas.style.top = imgCanvas.offsetTop + "px";
maskCanvas.style.left = imgCanvas.offsetLeft + "px";
self.invalidateMaskCanvas(self);
self.invalidatePointsCanvas(self);
});
// original image load
orig_image.onload = () => self.onLoaded(self);
const rgb_url = new URL(target_image_path);
rgb_url.searchParams.delete('channel');
rgb_url.searchParams.set('channel', 'rgb');
orig_image.src = rgb_url;
self.image = orig_image;
}
onLoaded(self) {
if(self.message_box) {
self.element.removeChild(self.message_box);
self.message_box = null;
}
window.dispatchEvent(new Event('resize'));
self.setEventHandler(pointsCanvas);
self.saveButton.disabled = false;
}
setEventHandler(targetCanvas) {
targetCanvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
const self = this;
targetCanvas.addEventListener('pointermove', (event) => this.updateBrushPreview(self,event));
targetCanvas.addEventListener('pointerdown', (event) => this.handlePointerDown(self,event));
targetCanvas.addEventListener('pointerover', (event) => { this.brush.style.display = "block"; });
targetCanvas.addEventListener('pointerleave', (event) => { this.brush.style.display = "none"; });
document.addEventListener('keydown', ImpactSamEditorDialog.handleKeyDown);
}
static handleKeyDown(event) {
const self = ImpactSamEditorDialog.instance;
if (event.key === '=') { // positive
brush.style.backgroundColor = "blue";
brush.style.outline = "2px solid pink";
self.is_positive_mode = true;
} else if (event.key === '-') { // negative
brush.style.backgroundColor = "red";
brush.style.outline = "2px solid skyblue";
self.is_positive_mode = false;
}
}
is_positive_mode = true;
prompt_points = [];
confidence = 70;
invalidatePointsCanvas(self) {
const ctx = self.pointsCtx;
for (const i in self.prompt_points) {
const [is_positive, x, y] = self.prompt_points[i];
const scaledX = x * ctx.canvas.width / self.image.width;
const scaledY = y * ctx.canvas.height / self.image.height;
if(is_positive)
ctx.fillStyle = "blue";
else
ctx.fillStyle = "red";
ctx.beginPath();
ctx.arc(scaledX, scaledY, 3, 0, 3 * Math.PI);
ctx.fill();
}
}줘
invalidateMaskCanvas(self) {
if(self.mask_image) {
self.maskCtx.clearRect(0, 0, self.maskCanvas.width, self.maskCanvas.height);
self.maskCtx.drawImage(self.mask_image, 0, 0, self.maskCanvas.width, self.maskCanvas.height);
}
}
async load_sam(url) {
const parsedUrl = new URL(url);
const searchParams = new URLSearchParams(parsedUrl.search);
const filename = searchParams.get("filename") || "";
const fileType = searchParams.get("type") || "";
const subfolder = searchParams.get("subfolder") || "";
const data = {
sam_model_name: "auto",
filename: filename,
type: fileType,
subfolder: subfolder
};
fetch('/sam/prepare', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
}
async detect(self) {
const positive_points = [];
const negative_points = [];
for(const i in self.prompt_points) {
const [is_positive, x, y] = self.prompt_points[i];
const point = [x,y];
if(is_positive)
positive_points.push(point);
else
negative_points.push(point);
}
const data = {
positive_points: positive_points,
negative_points: negative_points,
threshold: self.confidence/100
};
const response = await fetch('/sam/detect', {
method: 'POST',
headers: { 'Content-Type': 'image/png' },
body: JSON.stringify(data)
});
const blob = await response.blob();
const url = URL.createObjectURL(blob);
return new Promise((resolve, reject) => {
const image = new Image();
image.onload = () => resolve(image);
image.onerror = reject;
image.src = url;
});
}
handlePointerDown(self, event) {
if ([0, 2, 5].includes(event.button)) {
event.preventDefault();
const x = event.offsetX || event.targetTouches[0].clientX - maskRect.left;
const y = event.offsetY || event.targetTouches[0].clientY - maskRect.top;
const originalX = x * self.image.width / self.pointsCanvas.width;
const originalY = y * self.image.height / self.pointsCanvas.height;
var point = null;
if (event.button == 0) {
// positive
point = [true, originalX, originalY];
} else {
// negative
point = [false, originalX, originalY];
}
self.prompt_points.push(point);
self.invalidatePointsCanvas(self);
}
}
async save(self) {
if(!self.mask_image) {
this.close();
return;
}
const save_canvas = document.createElement('canvas');
const save_ctx = save_canvas.getContext('2d', {willReadFrequently:true});
save_canvas.width = self.mask_image.width;
save_canvas.height = self.mask_image.height;
save_ctx.drawImage(self.mask_image, 0, 0, save_canvas.width, save_canvas.height);
const save_data = save_ctx.getImageData(0, 0, save_canvas.width, save_canvas.height);
// refine mask image
for (let i = 0; i < save_data.data.length; i += 4) {
if(save_data.data[i]) {
save_data.data[i+3] = 0;
}
else {
save_data.data[i+3] = 255;
}
save_data.data[i] = 0;
save_data.data[i+1] = 0;
save_data.data[i+2] = 0;
}
save_ctx.globalCompositeOperation = 'source-over';
save_ctx.putImageData(save_data, 0, 0);
const formData = new FormData();
const filename = "clipspace-mask-" + performance.now() + ".png";
const item =
{
"filename": filename,
"subfolder": "",
"type": "temp",
};
if(ComfyApp.clipspace.images)
ComfyApp.clipspace.images[0] = item;
if(ComfyApp.clipspace.widgets) {
const index = ComfyApp.clipspace.widgets.findIndex(obj => obj.name === 'image');
if(index >= 0)
ComfyApp.clipspace.widgets[index].value = `${filename} [temp]`;
}
const dataURL = save_canvas.toDataURL();
const blob = dataURLToBlob(dataURL);
let original_url = new URL(this.image.src);
const original_ref = { filename: original_url.searchParams.get('filename') };
let original_subfolder = original_url.searchParams.get("subfolder");
if(original_subfolder)
original_ref.subfolder = original_subfolder;
let original_type = original_url.searchParams.get("type");
if(original_type)
original_ref.type = original_type;
formData.append('image', blob, filename);
formData.append('original_ref', JSON.stringify(original_ref));
formData.append('type', "temp");
await uploadMask(item, formData);
ComfyApp.onClipspaceEditorSave();
this.close();
}
}
app.registerExtension({
name: "Comfy.Impact.SAMEditor",
init(app) {
const callback =
function () {
let dlg = ImpactSamEditorDialog.getInstance();
dlg.show();
};
const context_predicate = () => ComfyApp.clipspace && ComfyApp.clipspace.imgs && ComfyApp.clipspace.imgs.length > 0
ClipspaceDialog.registerButton("Impact SAM Detector", context_predicate, callback);
},
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (Array.isArray(nodeData.output) && (nodeData.output.includes("MASK") || nodeData.output.includes("IMAGE"))) {
addMenuHandler(nodeType, function (_, options) {
options.unshift({
content: "Open in SAM Detector",
callback: () => {
ComfyApp.copyToClipspace(this);
ComfyApp.clipspace_return_node = this;
let dlg = ImpactSamEditorDialog.getInstance();
dlg.show();
},
});
});
}
}
});
@@ -1,182 +0,0 @@
import { ComfyApp, app } from "../../scripts/app.js";
import { ComfyDialog, $el } from "../../scripts/ui.js";
import { api } from "../../scripts/api.js";
async function open_picker(node) {
const resp = await api.fetchApi(`/impact/segs/picker/count?id=${node.id}`);
const body = await resp.text();
let cnt = parseInt(body);
var existingPicker = document.getElementById('impact-picker');
if (existingPicker) {
existingPicker.parentNode.removeChild(existingPicker);
}
var gallery = document.createElement('div');
gallery.id = 'impact-picker';
gallery.style.position = "absolute";
gallery.style.height = "80%";
gallery.style.width = "80%";
gallery.style.top = "10%";
gallery.style.left = "10%";
gallery.style.display = 'flex';
gallery.style.flexWrap = 'wrap';
gallery.style.maxHeight = '600px';
gallery.style.overflow = 'auto';
gallery.style.backgroundColor = 'rgba(0,0,0,0.3)';
gallery.style.padding = '20px';
gallery.draggable = false;
gallery.style.zIndex = 5000;
var doneButton = document.createElement('button');
doneButton.textContent = 'Done';
doneButton.style.padding = '10px 10px';
doneButton.style.border = 'none';
doneButton.style.borderRadius = '5px';
doneButton.style.fontFamily = 'Arial, sans-serif';
doneButton.style.fontSize = '16px';
doneButton.style.fontWeight = 'bold';
doneButton.style.color = '#fff';
doneButton.style.background = 'linear-gradient(to bottom, #0070B8, #003D66)';
doneButton.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.4)';
doneButton.style.margin = "20px";
doneButton.style.height = "40px";
var cancelButton = document.createElement('button');
cancelButton.textContent = 'Cancel';
cancelButton.style.padding = '10px 10px';
cancelButton.style.border = 'none';
cancelButton.style.borderRadius = '5px';
cancelButton.style.fontFamily = 'Arial, sans-serif';
cancelButton.style.fontSize = '16px';
cancelButton.style.fontWeight = 'bold';
cancelButton.style.color = '#fff';
cancelButton.style.background = 'linear-gradient(to bottom, #ff70B8, #ff3D66)';
cancelButton.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.4)';
cancelButton.style.margin = "20px";
cancelButton.style.height = "40px";
const w = node.widgets.find((w) => w.name == 'picks');
let prev_selected = w.value.split(',').map(function(item) {
return parseInt(item, 10);
});
let images = [];
doneButton.onclick = () => {
var result = '';
for(let i in images) {
if(images[i].isSelected) {
if(result != '')
result += ', ';
result += (parseInt(i)+1);
}
}
w.value = result;
gallery.parentNode.removeChild(gallery);
}
cancelButton.onclick = () => {
gallery.parentNode.removeChild(gallery);
}
var panel = document.createElement('div');
panel.style.clear = 'both';
panel.style.width = '100%';
panel.style.height = '40px';
panel.style.justifyContent = 'center';
panel.style.alignItems = 'center';
panel.style.display = 'flex';
panel.appendChild(doneButton);
panel.appendChild(cancelButton);
gallery.appendChild(panel);
var hint = document.createElement('label');
hint.style.position = 'absolute';
hint.innerHTML = 'Click: Toggle Selection<BR>Ctrl-click: Single Selection';
gallery.appendChild(hint);
let max_size = 300;
for(let i=0; i<cnt; i++) {
let image = new Image();
image.src = `/impact/segs/picker/view?id=${node.id}&idx=${i}`;
image.style.margin = '10px';
image.draggable = false;
images.push(image);
image.isSelected = prev_selected.includes(i + 1);
if(image.isSelected) {
image.style.border = '2px solid #006699';
}
image.onload = function() {
var ratio = 1.0;
if(image.naturalWidth > image.naturalHeight) {
ratio = max_size/image.naturalWidth;
}
else {
ratio = max_size/image.naturalHeight;
}
let width = image.naturalWidth * ratio;
let height = image.naturalHeight * ratio;
if(width < height) {
this.style.marginLeft = (200-width)/2+"px";
}
else{
this.style.marginTop = (200-height)/2+"px";
}
this.style.width = width+"px";
this.style.height = height+"px";
this.style.objectFit = 'cover';
}
image.addEventListener('click', function(event) {
if(event.ctrlKey) {
for(let i in images) {
if(images[i].isSelected) {
images[i].style.border = 'none';
images[i].isSelected = false;
}
}
image.style.border = '2px solid #006699';
image.isSelected = true;
return;
}
if(image.isSelected) {
image.style.border = 'none';
image.isSelected = false;
}
else {
image.style.border = '2px solid #006699';
image.isSelected = true;
}
});
gallery.appendChild(image);
}
document.body.appendChild(gallery);
}
app.registerExtension({
name: "Comfy.Impack.Picker",
nodeCreated(node, app) {
if(node.comfyClass == "ImpactSEGSPicker") {
node.addWidget("button", "pick", "image", () => {
open_picker(node);
});
}
}
});
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

@@ -1,12 +0,0 @@
import sys
import subprocess
def ensure_onnx_package():
try:
import onnxruntime
except Exception:
if "python_embeded" in sys.executable or "python_embedded" in sys.executable:
subprocess.check_call([sys.executable, '-s', '-m', 'pip', 'install', 'onnxruntime'])
else:
subprocess.check_call([sys.executable, '-s', '-m', 'pip', 'install', 'onnxruntime'])
@@ -1,160 +0,0 @@
from nodes import MAX_RESOLUTION
from impact.utils import *
import impact.core as core
from impact.core import SEG
from impact.segs_nodes import SEGSPaste
class SEGSDetailerForAnimateDiff:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"image_frames": ("IMAGE", ),
"segs": ("SEGS", ),
"guide_size": ("FLOAT", {"default": 256, "min": 64, "max": MAX_RESOLUTION, "step": 8}),
"guide_size_for": ("BOOLEAN", {"default": True, "label_on": "bbox", "label_off": "crop_region"}),
"max_size": ("FLOAT", {"default": 768, "min": 64, "max": MAX_RESOLUTION, "step": 8}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
"denoise": ("FLOAT", {"default": 0.5, "min": 0.0001, "max": 1.0, "step": 0.01}),
"basic_pipe": ("BASIC_PIPE",),
"refiner_ratio": ("FLOAT", {"default": 0.2, "min": 0.0, "max": 1.0})
},
"optional": {
"refiner_basic_pipe_opt": ("BASIC_PIPE",),
# TODO: "inpaint_model": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
# TODO: "noise_mask_feather": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
}
}
RETURN_TYPES = ("SEGS", "IMAGE")
RETURN_NAMES = ("segs", "cnet_images")
OUTPUT_IS_LIST = (False, True)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detailer"
@staticmethod
def do_detail(image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
denoise, basic_pipe, refiner_ratio=None, refiner_basic_pipe_opt=None, inpaint_model=False, noise_mask_feather=0):
model, clip, vae, positive, negative = basic_pipe
if refiner_basic_pipe_opt is None:
refiner_model, refiner_clip, refiner_positive, refiner_negative = None, None, None, None
else:
refiner_model, refiner_clip, _, refiner_positive, refiner_negative = refiner_basic_pipe_opt
segs = core.segs_scale_match(segs, image_frames.shape)
new_segs = []
cnet_image_list = []
for seg in segs[1]:
cropped_image_frames = None
for image in image_frames:
image = image.unsqueeze(0)
cropped_image = seg.cropped_image if seg.cropped_image is not None else crop_tensor4(image, seg.crop_region)
cropped_image = to_tensor(cropped_image)
if cropped_image_frames is None:
cropped_image_frames = cropped_image
else:
cropped_image_frames = torch.concat((cropped_image_frames, cropped_image), dim=0)
cropped_image_frames = cropped_image_frames.cpu().numpy()
enhanced_image_tensor, cnet_images = core.enhance_detail_for_animatediff(cropped_image_frames, model, clip, vae, guide_size, guide_size_for, max_size,
seg.bbox, seed, steps, cfg, sampler_name, scheduler,
positive, negative, denoise, seg.cropped_mask,
refiner_ratio=refiner_ratio, refiner_model=refiner_model,
refiner_clip=refiner_clip, refiner_positive=refiner_positive,
refiner_negative=refiner_negative, control_net_wrapper=seg.control_net_wrapper,
inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
if cnet_images is not None:
cnet_image_list.extend(cnet_images)
if enhanced_image_tensor is None:
new_cropped_image = cropped_image_frames
else:
new_cropped_image = enhanced_image_tensor.cpu().numpy()
new_seg = SEG(new_cropped_image, seg.cropped_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, None)
new_segs.append(new_seg)
return (segs[0], new_segs), cnet_image_list
def doit(self, image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
denoise, basic_pipe, refiner_ratio=None, refiner_basic_pipe_opt=None, inpaint_model=False, noise_mask_feather=0):
segs, cnet_images = SEGSDetailerForAnimateDiff.do_detail(image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name,
scheduler, denoise, basic_pipe, refiner_ratio, refiner_basic_pipe_opt,
inpaint_model=inpaint_model, noise_mask_feather=noise_mask_feather)
if len(cnet_images) == 0:
cnet_images = [empty_pil_tensor()]
return (segs, cnet_images)
class DetailerForEachPipeForAnimateDiff:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"image_frames": ("IMAGE", ),
"segs": ("SEGS", ),
"guide_size": ("FLOAT", {"default": 384, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
"guide_size_for": ("BOOLEAN", {"default": True, "label_on": "bbox", "label_off": "crop_region"}),
"max_size": ("FLOAT", {"default": 1024, "min": 64, "max": nodes.MAX_RESOLUTION, "step": 8}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
"denoise": ("FLOAT", {"default": 0.5, "min": 0.0001, "max": 1.0, "step": 0.01}),
"feather": ("INT", {"default": 5, "min": 0, "max": 100, "step": 1}),
"basic_pipe": ("BASIC_PIPE", ),
"refiner_ratio": ("FLOAT", {"default": 0.2, "min": 0.0, "max": 1.0}),
},
"optional": {
"detailer_hook": ("DETAILER_HOOK",),
"refiner_basic_pipe_opt": ("BASIC_PIPE",),
# "inpaint_model": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
# "noise_mask_feather": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
}
}
RETURN_TYPES = ("IMAGE", "SEGS", "BASIC_PIPE", "IMAGE")
RETURN_NAMES = ("image", "segs", "basic_pipe", "cnet_images")
OUTPUT_IS_LIST = (False, False, False, True)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detailer"
@staticmethod
def doit(image_frames, segs, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
denoise, feather, basic_pipe, refiner_ratio=None, detailer_hook=None, refiner_basic_pipe_opt=None,
inpaint_model=False, noise_mask_feather=0):
enhanced_segs = []
cnet_image_list = []
for sub_seg in segs[1]:
single_seg = segs[0], [sub_seg]
enhanced_seg, cnet_images = SEGSDetailerForAnimateDiff().do_detail(image_frames, single_seg, guide_size, guide_size_for, max_size, seed, steps, cfg, sampler_name, scheduler,
denoise, basic_pipe, refiner_ratio, refiner_basic_pipe_opt, inpaint_model, noise_mask_feather)
image_frames = SEGSPaste.doit(image_frames, enhanced_seg, feather, alpha=255)[0]
if cnet_images is not None:
cnet_image_list.extend(cnet_images)
if detailer_hook is not None:
detailer_hook.post_paste(image_frames)
enhanced_segs += enhanced_seg[1]
new_segs = segs[0], enhanced_segs
return image_frames, new_segs, basic_pipe, cnet_image_list
@@ -1,258 +0,0 @@
import os
from PIL import ImageOps
from impact.utils import *
from . import core
import random
class PreviewBridge:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"images": ("IMAGE",),
"image": ("STRING", {"default": ""}),
},
"hidden": {"unique_id": "UNIQUE_ID"},
}
RETURN_TYPES = ("IMAGE", "MASK", )
FUNCTION = "doit"
OUTPUT_NODE = True
CATEGORY = "ImpactPack/Util"
def __init__(self):
super().__init__()
self.output_dir = folder_paths.get_temp_directory()
self.type = "temp"
self.prev_hash = None
@staticmethod
def load_image(pb_id):
is_fail = False
if pb_id not in core.preview_bridge_image_id_map:
is_fail = True
image_path, ui_item = core.preview_bridge_image_id_map[pb_id]
if not os.path.isfile(image_path):
is_fail = True
if not is_fail:
i = Image.open(image_path)
i = ImageOps.exif_transpose(i)
image = i.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
if 'A' in i.getbands():
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
mask = 1. - torch.from_numpy(mask)
else:
mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
else:
image = empty_pil_tensor()
mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
ui_item = {
"filename": 'empty.png',
"subfolder": '',
"type": 'temp'
}
return image, mask.unsqueeze(0), ui_item
def doit(self, images, image, unique_id):
need_refresh = False
if unique_id not in core.preview_bridge_cache:
need_refresh = True
elif core.preview_bridge_cache[unique_id][0] is not images:
need_refresh = True
if not need_refresh:
pixels, mask, path_item = PreviewBridge.load_image(image)
image = [path_item]
else:
res = nodes.PreviewImage().save_images(images, filename_prefix="PreviewBridge/PB-")
image2 = res['ui']['images']
pixels = images
mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
path = os.path.join(folder_paths.get_temp_directory(), 'PreviewBridge', image2[0]['filename'])
core.set_previewbridge_image(unique_id, path, image2[0])
core.preview_bridge_image_id_map[image] = (path, image2[0])
core.preview_bridge_image_name_map[unique_id, path] = (image, image2[0])
core.preview_bridge_cache[unique_id] = (images, image2)
image = image2
return {
"ui": {"images": image},
"result": (pixels, mask, ),
}
def decode_latent(latent_tensor, preview_method, vae_opt=None):
if vae_opt is not None:
image = nodes.VAEDecode().decode(vae_opt, latent_tensor)[0]
return image
from comfy.cli_args import LatentPreviewMethod
import comfy.latent_formats as latent_formats
if preview_method.startswith("TAE"):
if preview_method == "TAESD15":
decoder_name = "taesd"
else:
decoder_name = "taesdxl"
vae = nodes.VAELoader().load_vae(decoder_name)[0]
image = nodes.VAEDecode().decode(vae, latent_tensor)[0]
return image
else:
if preview_method == "Latent2RGB-SD15":
latent_format = latent_formats.SD15()
method = LatentPreviewMethod.Latent2RGB
else: # preview_method == "Latent2RGB-SDXL"
latent_format = latent_formats.SDXL()
method = LatentPreviewMethod.Latent2RGB
previewer = core.get_previewer("cpu", latent_format=latent_format, force=True, method=method)
pil_image = previewer.decode_latent_to_preview(latent_tensor['samples'])
pixels_size = pil_image.size[0]*8, pil_image.size[1]*8
resized_image = pil_image.resize(pixels_size, Image.NONE)
return to_tensor(resized_image).unsqueeze(0)
class PreviewBridgeLatent:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"latent": ("LATENT",),
"image": ("STRING", {"default": ""}),
"preview_method": (["Latent2RGB-SDXL", "Latent2RGB-SD15", "TAESDXL", "TAESD15"],),
},
"optional": {
"vae_opt": ("VAE", )
},
"hidden": {"unique_id": "UNIQUE_ID"},
}
RETURN_TYPES = ("LATENT", "MASK", )
FUNCTION = "doit"
OUTPUT_NODE = True
CATEGORY = "ImpactPack/Util"
def __init__(self):
super().__init__()
self.output_dir = folder_paths.get_temp_directory()
self.type = "temp"
self.prev_hash = None
self.prefix_append = "_temp_" + ''.join(random.choice("abcdefghijklmnopqrstupvxyz") for x in range(5))
@staticmethod
def load_image(pb_id):
is_fail = False
if pb_id not in core.preview_bridge_image_id_map:
is_fail = True
image_path, ui_item = core.preview_bridge_image_id_map[pb_id]
if not os.path.isfile(image_path):
is_fail = True
if not is_fail:
i = Image.open(image_path)
i = ImageOps.exif_transpose(i)
image = i.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
if 'A' in i.getbands():
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
mask = 1. - torch.from_numpy(mask)
else:
mask = None
else:
image = empty_pil_tensor()
mask = None
ui_item = {
"filename": 'empty.png',
"subfolder": '',
"type": 'temp'
}
return image, mask, ui_item
def doit(self, latent, image, preview_method, vae_opt=None, unique_id=None):
need_refresh = False
if unique_id not in core.preview_bridge_cache:
need_refresh = True
elif (core.preview_bridge_cache[unique_id][0] is not latent
or (vae_opt is None and core.preview_bridge_cache[unique_id][2] is not None)
or (vae_opt is None and core.preview_bridge_cache[unique_id][1] != preview_method)
or (vae_opt is not None and core.preview_bridge_cache[unique_id][2] is not vae_opt)):
need_refresh = True
if not need_refresh:
pixels, mask, path_item = PreviewBridge.load_image(image)
if mask is None:
mask = torch.ones(latent['samples'].shape[2:], dtype=torch.float32, device="cpu").unsqueeze(0)
if 'noise_mask' in latent:
res_latent = latent.copy()
del res_latent['noise_mask']
else:
res_latent = latent
else:
res_latent = latent.copy()
res_latent['noise_mask'] = mask
res_image = [path_item]
else:
decoded_image = decode_latent(latent, preview_method, vae_opt)
if 'noise_mask' in latent:
mask = latent['noise_mask']
decoded_pil = to_pil(decoded_image)
inverted_mask = 1 - mask # invert
resized_mask = resize_mask(inverted_mask, (decoded_image.shape[1], decoded_image.shape[2]))
result_pil = apply_mask_alpha_to_pil(decoded_pil, resized_mask)
full_output_folder, filename, counter, _, _ = folder_paths.get_save_image_path("PreviewBridge/PBL-"+self.prefix_append, folder_paths.get_temp_directory(), result_pil.size[0], result_pil.size[1])
file = f"{filename}_{counter}.png"
result_pil.save(os.path.join(full_output_folder, file), compress_level=4)
res_image = [{
'filename': file,
'subfolder': 'PreviewBridge',
'type': 'temp',
}]
else:
mask = torch.ones(latent['samples'].shape[2:], dtype=torch.float32, device="cpu").unsqueeze(0)
res = nodes.PreviewImage().save_images(decoded_image, filename_prefix="PreviewBridge/PBL-")
res_image = res['ui']['images']
path = os.path.join(folder_paths.get_temp_directory(), 'PreviewBridge', res_image[0]['filename'])
core.set_previewbridge_image(unique_id, path, res_image[0])
core.preview_bridge_image_id_map[image] = (path, res_image[0])
core.preview_bridge_image_name_map[unique_id, path] = (image, res_image[0])
core.preview_bridge_cache[unique_id] = (latent, preview_method, vae_opt, res_image)
res_latent = latent
return {
"ui": {"images": res_image},
"result": (res_latent, mask, ),
}
@@ -1,67 +0,0 @@
import configparser
import os
version_code = [4, 80]
version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
dependency_version = 20
my_path = os.path.dirname(__file__)
old_config_path = os.path.join(my_path, "impact-pack.ini")
config_path = os.path.join(my_path, "..", "..", "impact-pack.ini")
latent_letter_path = os.path.join(my_path, "..", "..", "latent.png")
MAX_RESOLUTION = 8192
def write_config():
config = configparser.ConfigParser()
config['default'] = {
'dependency_version': str(dependency_version),
'mmdet_skip': str(get_config()['mmdet_skip']),
'sam_editor_cpu': str(get_config()['sam_editor_cpu']),
'sam_editor_model': get_config()['sam_editor_model'],
'custom_wildcards': get_config()['custom_wildcards'],
'disable_gpu_opencv': get_config()['disable_gpu_opencv'],
}
with open(config_path, 'w') as configfile:
config.write(configfile)
def read_config():
try:
config = configparser.ConfigParser()
config.read(config_path)
default_conf = config['default']
return {
'dependency_version': int(default_conf['dependency_version']),
'mmdet_skip': default_conf['mmdet_skip'].lower() == 'true' if 'mmdet_skip' in default_conf else True,
'sam_editor_cpu': default_conf['sam_editor_cpu'].lower() == 'true' if 'sam_editor_cpu' in default_conf else False,
'sam_editor_model': 'sam_vit_b_01ec64.pth',
'custom_wildcards': default_conf['custom_wildcards'] if 'custom_wildcards' in default_conf else os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "custom_wildcards")),
'disable_gpu_opencv': default_conf['disable_gpu_opencv'].lower() == 'true' if 'disable_gpu_opencv' in default_conf else True
}
except Exception:
return {
'dependency_version': 0,
'mmdet_skip': True,
'sam_editor_cpu': False,
'sam_editor_model': 'sam_vit_b_01ec64.pth',
'custom_wildcards': os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "custom_wildcards")),
'disable_gpu_opencv': True
}
cached_config = None
def get_config():
global cached_config
if cached_config is None:
cached_config = read_config()
return cached_config
File diff suppressed because it is too large Load Diff
@@ -1,17 +0,0 @@
detection_labels = [
'hand', 'face', 'mouth', 'eyes', 'eyebrows', 'pupils',
'left_eyebrow', 'left_eye', 'left_pupil', 'right_eyebrow', 'right_eye', 'right_pupil',
'short_sleeved_shirt', 'long_sleeved_shirt', 'short_sleeved_outwear', 'long_sleeved_outwear',
'vest', 'sling', 'shorts', 'trousers', 'skirt', 'short_sleeved_dress', 'long_sleeved_dress', 'vest_dress', 'sling_dress',
"person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat",
"traffic light", "fire hydrant", "stop sign", "parking meter", "bench",
"bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe",
"backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard",
"sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard",
"tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl",
"banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza",
"donut", "cake", "chair", "couch", "potted plant", "bed", "dining table", "toilet",
"tv", "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave", "oven",
"toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear",
"hair drier", "toothbrush"
]
@@ -1,464 +0,0 @@
import impact.core as core
from impact.config import MAX_RESOLUTION
import impact.segs_nodes as segs_nodes
import impact.utils as utils
import torch
from impact.core import SEG
class SAMDetectorCombined:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"sam_model": ("SAM_MODEL", ),
"segs": ("SEGS", ),
"image": ("IMAGE", ),
"detection_hint": (["center-1", "horizontal-2", "vertical-2", "rect-4", "diamond-4", "mask-area",
"mask-points", "mask-point-bbox", "none"],),
"dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"threshold": ("FLOAT", {"default": 0.93, "min": 0.0, "max": 1.0, "step": 0.01}),
"bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
"mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
"mask_hint_use_negative": (["False", "Small", "Outter"], )
}
}
RETURN_TYPES = ("MASK",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detector"
def doit(self, sam_model, segs, image, detection_hint, dilation,
threshold, bbox_expansion, mask_hint_threshold, mask_hint_use_negative):
return (core.make_sam_mask(sam_model, segs, image, detection_hint, dilation,
threshold, bbox_expansion, mask_hint_threshold, mask_hint_use_negative), )
class SAMDetectorSegmented:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"sam_model": ("SAM_MODEL", ),
"segs": ("SEGS", ),
"image": ("IMAGE", ),
"detection_hint": (["center-1", "horizontal-2", "vertical-2", "rect-4", "diamond-4", "mask-area",
"mask-points", "mask-point-bbox", "none"],),
"dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"threshold": ("FLOAT", {"default": 0.93, "min": 0.0, "max": 1.0, "step": 0.01}),
"bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
"mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
"mask_hint_use_negative": (["False", "Small", "Outter"], )
}
}
RETURN_TYPES = ("MASK", "MASK")
RETURN_NAMES = ("combined_mask", "batch_masks")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detector"
def doit(self, sam_model, segs, image, detection_hint, dilation,
threshold, bbox_expansion, mask_hint_threshold, mask_hint_use_negative):
combined_mask, batch_masks = core.make_sam_mask_segmented(sam_model, segs, image, detection_hint, dilation,
threshold, bbox_expansion, mask_hint_threshold,
mask_hint_use_negative)
return (combined_mask, batch_masks, )
class BboxDetectorForEach:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"bbox_detector": ("BBOX_DETECTOR", ),
"image": ("IMAGE", ),
"threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"dilation": ("INT", {"default": 10, "min": -512, "max": 512, "step": 1}),
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}),
"drop_size": ("INT", {"min": 1, "max": MAX_RESOLUTION, "step": 1, "default": 10}),
"labels": ("STRING", {"multiline": True, "default": "all", "placeholder": "List the types of segments to be allowed, separated by commas"}),
},
"optional": {"detailer_hook": ("DETAILER_HOOK",), }
}
RETURN_TYPES = ("SEGS", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detector"
def doit(self, bbox_detector, image, threshold, dilation, crop_factor, drop_size, labels=None, detailer_hook=None):
if len(image) > 1:
raise Exception('[Impact Pack] ERROR: BboxDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
segs = bbox_detector.detect(image, threshold, dilation, crop_factor, drop_size, detailer_hook)
if labels is not None and labels != '':
labels = labels.split(',')
if len(labels) > 0:
segs, _ = segs_nodes.SEGSLabelFilter.filter(segs, labels)
return (segs, )
class SegmDetectorForEach:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"segm_detector": ("SEGM_DETECTOR", ),
"image": ("IMAGE", ),
"threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"dilation": ("INT", {"default": 10, "min": -512, "max": 512, "step": 1}),
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}),
"drop_size": ("INT", {"min": 1, "max": MAX_RESOLUTION, "step": 1, "default": 10}),
"labels": ("STRING", {"multiline": True, "default": "all", "placeholder": "List the types of segments to be allowed, separated by commas"}),
},
"optional": {"detailer_hook": ("DETAILER_HOOK",), }
}
RETURN_TYPES = ("SEGS", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detector"
def doit(self, segm_detector, image, threshold, dilation, crop_factor, drop_size, labels=None, detailer_hook=None):
if len(image) > 1:
raise Exception('[Impact Pack] ERROR: SegmDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
segs = segm_detector.detect(image, threshold, dilation, crop_factor, drop_size, detailer_hook)
if labels is not None and labels != '':
labels = labels.split(',')
if len(labels) > 0:
segs, _ = segs_nodes.SEGSLabelFilter.filter(segs, labels)
return (segs, )
class SegmDetectorCombined:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"segm_detector": ("SEGM_DETECTOR", ),
"image": ("IMAGE", ),
"threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
}
}
RETURN_TYPES = ("MASK",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detector"
def doit(self, segm_detector, image, threshold, dilation):
mask = segm_detector.detect_combined(image, threshold, dilation)
return (mask,)
class BboxDetectorCombined(SegmDetectorCombined):
@classmethod
def INPUT_TYPES(s):
return {"required": {
"bbox_detector": ("BBOX_DETECTOR", ),
"image": ("IMAGE", ),
"threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"dilation": ("INT", {"default": 4, "min": -512, "max": 512, "step": 1}),
}
}
def doit(self, bbox_detector, image, threshold, dilation):
mask = bbox_detector.detect_combined(image, threshold, dilation)
return (mask,)
class SimpleDetectorForEach:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"bbox_detector": ("BBOX_DETECTOR", ),
"image": ("IMAGE", ),
"bbox_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"bbox_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}),
"drop_size": ("INT", {"min": 1, "max": MAX_RESOLUTION, "step": 1, "default": 10}),
"sub_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"sub_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"sub_bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
"sam_mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
},
"optional": {
"post_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"sam_model_opt": ("SAM_MODEL", ),
"segm_detector_opt": ("SEGM_DETECTOR", ),
}
}
RETURN_TYPES = ("SEGS",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detector"
@staticmethod
def detect(bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, post_dilation=0, sam_model_opt=None, segm_detector_opt=None,
detailer_hook=None):
if len(image) > 1:
raise Exception('[Impact Pack] ERROR: SimpleDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
if segm_detector_opt is not None and hasattr(segm_detector_opt, 'bbox_detector') and segm_detector_opt.bbox_detector == bbox_detector:
# Better segm support for YOLO-World detector
segs = segm_detector_opt.detect(image, sub_threshold, sub_dilation, crop_factor, drop_size, detailer_hook=detailer_hook)
else:
segs = bbox_detector.detect(image, bbox_threshold, bbox_dilation, crop_factor, drop_size, detailer_hook=detailer_hook)
if sam_model_opt is not None:
mask = core.make_sam_mask(sam_model_opt, segs, image, "center-1", sub_dilation,
sub_threshold, sub_bbox_expansion, sam_mask_hint_threshold, False)
segs = core.segs_bitwise_and_mask(segs, mask)
elif segm_detector_opt is not None:
segm_segs = segm_detector_opt.detect(image, sub_threshold, sub_dilation, crop_factor, drop_size, detailer_hook=detailer_hook)
mask = core.segs_to_combined_mask(segm_segs)
segs = core.segs_bitwise_and_mask(segs, mask)
segs = core.dilate_segs(segs, post_dilation)
return (segs,)
def doit(self, bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, post_dilation=0, sam_model_opt=None, segm_detector_opt=None):
return SimpleDetectorForEach.detect(bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, post_dilation=post_dilation,
sam_model_opt=sam_model_opt, segm_detector_opt=segm_detector_opt)
class SimpleDetectorForEachPipe:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"detailer_pipe": ("DETAILER_PIPE", ),
"image": ("IMAGE", ),
"bbox_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"bbox_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}),
"drop_size": ("INT", {"min": 1, "max": MAX_RESOLUTION, "step": 1, "default": 10}),
"sub_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"sub_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
"sub_bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
"sam_mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
},
"optional": {
"post_dilation": ("INT", {"default": 0, "min": -512, "max": 512, "step": 1}),
}
}
RETURN_TYPES = ("SEGS",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detector"
def doit(self, detailer_pipe, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold, post_dilation=0):
if len(image) > 1:
raise Exception('[Impact Pack] ERROR: SimpleDetectorForEach does not allow image batches.\nPlease refer to https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/batching-detailer.md for more information.')
model, clip, vae, positive, negative, wildcard, bbox_detector, segm_detector_opt, sam_model_opt, detailer_hook, refiner_model, refiner_clip, refiner_positive, refiner_negative = detailer_pipe
return SimpleDetectorForEach.detect(bbox_detector, image, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion,
sam_mask_hint_threshold, post_dilation=post_dilation, sam_model_opt=sam_model_opt, segm_detector_opt=segm_detector_opt,
detailer_hook=detailer_hook)
class SimpleDetectorForAnimateDiff:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"bbox_detector": ("BBOX_DETECTOR", ),
"image_frames": ("IMAGE", ),
"bbox_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"bbox_dilation": ("INT", {"default": 0, "min": -255, "max": 255, "step": 1}),
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}),
"drop_size": ("INT", {"min": 1, "max": MAX_RESOLUTION, "step": 1, "default": 10}),
"sub_threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"sub_dilation": ("INT", {"default": 0, "min": -255, "max": 255, "step": 1}),
"sub_bbox_expansion": ("INT", {"default": 0, "min": 0, "max": 1000, "step": 1}),
"sam_mask_hint_threshold": ("FLOAT", {"default": 0.7, "min": 0.0, "max": 1.0, "step": 0.01}),
},
"optional": {
"masking_mode": (["Pivot SEGS", "Combine neighboring frames", "Don't combine"],),
"segs_pivot": (["Combined mask", "1st frame mask"],),
"sam_model_opt": ("SAM_MODEL", ),
"segm_detector_opt": ("SEGM_DETECTOR", ),
}
}
RETURN_TYPES = ("SEGS",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Detector"
@staticmethod
def detect(bbox_detector, image_frames, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold,
masking_mode="Pivot SEGS", segs_pivot="Combined mask", sam_model_opt=None, segm_detector_opt=None):
h = image_frames.shape[1]
w = image_frames.shape[2]
# gather segs for all frames
segs_by_frames = []
for image in image_frames:
image = image.unsqueeze(0)
segs = bbox_detector.detect(image, bbox_threshold, bbox_dilation, crop_factor, drop_size)
if sam_model_opt is not None:
mask = core.make_sam_mask(sam_model_opt, segs, image, "center-1", sub_dilation,
sub_threshold, sub_bbox_expansion, sam_mask_hint_threshold, False)
segs = core.segs_bitwise_and_mask(segs, mask)
elif segm_detector_opt is not None:
segm_segs = segm_detector_opt.detect(image, sub_threshold, sub_dilation, crop_factor, drop_size)
mask = core.segs_to_combined_mask(segm_segs)
segs = core.segs_bitwise_and_mask(segs, mask)
segs_by_frames.append(segs)
def get_masked_frames():
masks_by_frame = []
for i, segs in enumerate(segs_by_frames):
masks_in_frame = segs_nodes.SEGSToMaskList().doit(segs)[0]
current_frame_mask = (masks_in_frame[0] * 255).to(torch.uint8)
for mask in masks_in_frame[1:]:
current_frame_mask |= (mask * 255).to(torch.uint8)
current_frame_mask = (current_frame_mask/255.0).to(torch.float32)
current_frame_mask = utils.to_binary_mask(current_frame_mask, 0.1)[0]
masks_by_frame.append(current_frame_mask)
return masks_by_frame
def get_empty_mask():
return torch.zeros((h, w), dtype=torch.float32, device="cpu")
def get_neighboring_mask_at(i, masks_by_frame):
prv = masks_by_frame[i-1] if i > 1 else get_empty_mask()
cur = masks_by_frame[i]
nxt = masks_by_frame[i-1] if i > 1 else get_empty_mask()
prv = prv if prv is not None else get_empty_mask()
cur = cur.clone() if cur is not None else get_empty_mask()
nxt = nxt if nxt is not None else get_empty_mask()
return prv, cur, nxt
def get_merged_neighboring_mask(masks_by_frame):
if len(masks_by_frame) <= 1:
return masks_by_frame
result = []
for i in range(0, len(masks_by_frame)):
prv, cur, nxt = get_neighboring_mask_at(i, masks_by_frame)
cur = (cur * 255).to(torch.uint8)
cur |= (prv * 255).to(torch.uint8)
cur |= (nxt * 255).to(torch.uint8)
cur = (cur / 255.0).to(torch.float32)
cur = utils.to_binary_mask(cur, 0.1)[0]
result.append(cur)
return result
def get_whole_merged_mask():
all_masks = []
for segs in segs_by_frames:
all_masks += segs_nodes.SEGSToMaskList().doit(segs)[0]
merged_mask = (all_masks[0] * 255).to(torch.uint8)
for mask in all_masks[1:]:
merged_mask |= (mask * 255).to(torch.uint8)
merged_mask = (merged_mask / 255.0).to(torch.float32)
merged_mask = utils.to_binary_mask(merged_mask, 0.1)[0]
return merged_mask
def get_pivot_segs():
if segs_pivot == "1st frame mask":
return segs_by_frames[0][1]
else:
merged_mask = get_whole_merged_mask()
return segs_nodes.MaskToSEGS().doit(merged_mask, False, crop_factor, False, drop_size, contour_fill=True)[0]
def get_merged_neighboring_segs():
pivot_segs = get_pivot_segs()
masks_by_frame = get_masked_frames()
masks_by_frame = get_merged_neighboring_mask(masks_by_frame)
new_segs = []
for seg in pivot_segs[1]:
cropped_mask = torch.zeros(seg.cropped_mask.shape, dtype=torch.float32, device="cpu").unsqueeze(0)
pivot_mask = torch.from_numpy(seg.cropped_mask)
x1, y1, x2, y2 = seg.crop_region
for mask in masks_by_frame:
cropped_mask_at_frame = (mask[y1:y2, x1:x2] * pivot_mask).unsqueeze(0)
cropped_mask = torch.cat((cropped_mask, cropped_mask_at_frame), dim=0)
if len(cropped_mask) > 1:
cropped_mask = cropped_mask[1:]
new_seg = SEG(seg.cropped_image, cropped_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, seg.control_net_wrapper)
new_segs.append(new_seg)
return pivot_segs[0], new_segs
def get_separated_segs():
pivot_segs = get_pivot_segs()
masks_by_frame = get_masked_frames()
new_segs = []
for seg in pivot_segs[1]:
cropped_mask = torch.zeros(seg.cropped_mask.shape, dtype=torch.float32, device="cpu").unsqueeze(0)
x1, y1, x2, y2 = seg.crop_region
for mask in masks_by_frame:
cropped_mask_at_frame = mask[y1:y2, x1:x2]
cropped_mask = torch.cat((cropped_mask, cropped_mask_at_frame), dim=0)
new_seg = SEG(seg.cropped_image, cropped_mask, seg.confidence, seg.crop_region, seg.bbox, seg.label, seg.control_net_wrapper)
new_segs.append(new_seg)
return pivot_segs[0], new_segs
# create result mask
if masking_mode == "Pivot SEGS":
return (get_pivot_segs(), )
elif masking_mode == "Combine neighboring frames":
return (get_merged_neighboring_segs(), )
else: # elif masking_mode == "Don't combine":
return (get_separated_segs(), )
def doit(self, bbox_detector, image_frames, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold,
masking_mode="Pivot SEGS", segs_pivot="Combined mask", sam_model_opt=None, segm_detector_opt=None):
return SimpleDetectorForAnimateDiff.detect(bbox_detector, image_frames, bbox_threshold, bbox_dilation, crop_factor, drop_size,
sub_threshold, sub_dilation, sub_bbox_expansion, sam_mask_hint_threshold,
masking_mode, segs_pivot, sam_model_opt, segm_detector_opt)
@@ -1,183 +0,0 @@
import comfy
import re
from impact.utils import *
hf_transformer_model_urls = [
"rizvandwiki/gender-classification-2",
"NTQAI/pedestrian_gender_recognition",
"Leilab/gender_class",
"ProjectPersonal/GenderClassifier",
"crangana/trained-gender",
"cledoux42/GenderNew_v002",
"ivensamdh/genderage2"
]
class HF_TransformersClassifierProvider:
@classmethod
def INPUT_TYPES(s):
global hf_transformer_model_urls
return {"required": {
"preset_repo_id": (hf_transformer_model_urls + ['Manual repo id'],),
"manual_repo_id": ("STRING", {"multiline": False}),
"device_mode": (["AUTO", "Prefer GPU", "CPU"],),
},
}
RETURN_TYPES = ("TRANSFORMERS_CLASSIFIER",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/HuggingFace"
def doit(self, preset_repo_id, manual_repo_id, device_mode):
from transformers import pipeline
if preset_repo_id == 'Manual repo id':
url = manual_repo_id
else:
url = preset_repo_id
if device_mode != 'CPU':
device = comfy.model_management.get_torch_device()
else:
device = "cpu"
classifier = pipeline(model=url, device=device)
return (classifier,)
preset_classify_expr = [
'#Female > #Male',
'#Female < #Male',
'female > 0.5',
'male > 0.5',
'Age16to25 > 0.1',
'Age50to69 > 0.1',
]
symbolic_label_map = {
'#Female': {'female', 'Female', 'Human Female', 'woman', 'women', 'girl'},
'#Male': {'male', 'Male', 'Human Male', 'man', 'men', 'boy'}
}
def is_numeric_string(input_str):
return re.match(r'^-?\d+(\.\d+)?$', input_str) is not None
classify_expr_pattern = r'([^><= ]+)\s*(>|<|>=|<=|=)\s*([^><= ]+)'
class SEGS_Classify:
@classmethod
def INPUT_TYPES(s):
global preset_classify_expr
return {"required": {
"classifier": ("TRANSFORMERS_CLASSIFIER",),
"segs": ("SEGS",),
"preset_expr": (preset_classify_expr + ['Manual expr'],),
"manual_expr": ("STRING", {"multiline": False}),
},
"optional": {
"ref_image_opt": ("IMAGE", ),
}
}
RETURN_TYPES = ("SEGS", "SEGS",)
RETURN_NAMES = ("filtered_SEGS", "remained_SEGS",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/HuggingFace"
@staticmethod
def lookup_classified_label_score(score_infos, label):
global symbolic_label_map
if label.startswith('#'):
if label not in symbolic_label_map:
return None
else:
label = symbolic_label_map[label]
else:
label = {label}
for x in score_infos:
if x['label'] in label:
return x['score']
return None
def doit(self, classifier, segs, preset_expr, manual_expr, ref_image_opt=None):
if preset_expr == 'Manual expr':
expr_str = manual_expr
else:
expr_str = preset_expr
match = re.match(classify_expr_pattern, expr_str)
if match is None:
return ((segs[0], []), segs)
a = match.group(1)
op = match.group(2)
b = match.group(3)
a_is_lab = not is_numeric_string(a)
b_is_lab = not is_numeric_string(b)
classified = []
remained_SEGS = []
for seg in segs[1]:
cropped_image = None
if seg.cropped_image is not None:
cropped_image = seg.cropped_image
elif ref_image_opt is not None:
# take from original image
cropped_image = crop_image(ref_image_opt, seg.crop_region)
if cropped_image is not None:
cropped_image = to_pil(cropped_image)
res = classifier(cropped_image)
classified.append((seg, res))
else:
remained_SEGS.append(seg)
filtered_SEGS = []
for seg, res in classified:
if a_is_lab:
avalue = SEGS_Classify.lookup_classified_label_score(res, a)
else:
avalue = a
if b_is_lab:
bvalue = SEGS_Classify.lookup_classified_label_score(res, b)
else:
bvalue = b
if avalue is None or bvalue is None:
remained_SEGS.append(seg)
continue
avalue = float(avalue)
bvalue = float(bvalue)
if op == '>':
cond = avalue > bvalue
elif op == '<':
cond = avalue < bvalue
elif op == '>=':
cond = avalue >= bvalue
elif op == '<=':
cond = avalue <= bvalue
else:
cond = avalue == bvalue
if cond:
filtered_SEGS.append(seg)
else:
remained_SEGS.append(seg)
return ((segs[0], filtered_SEGS), (segs[0], remained_SEGS))
@@ -1,83 +0,0 @@
import sys
from . import hooks
from . import defs
class SEGSOrderedFilterDetailerHookProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"target": (["area(=w*h)", "width", "height", "x1", "y1", "x2", "y2"],),
"order": ("BOOLEAN", {"default": True, "label_on": "descending", "label_off": "ascending"}),
"take_start": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
"take_count": ("INT", {"default": 1, "min": 0, "max": sys.maxsize, "step": 1}),
},
}
RETURN_TYPES = ("DETAILER_HOOK", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, target, order, take_start, take_count):
hook = hooks.SEGSOrderedFilterDetailerHook(target, order, take_start, take_count)
return (hook, )
class SEGSRangeFilterDetailerHookProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"target": (["area(=w*h)", "width", "height", "x1", "y1", "x2", "y2", "length_percent"],),
"mode": ("BOOLEAN", {"default": True, "label_on": "inside", "label_off": "outside"}),
"min_value": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
"max_value": ("INT", {"default": 67108864, "min": 0, "max": sys.maxsize, "step": 1}),
},
}
RETURN_TYPES = ("DETAILER_HOOK", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, target, mode, min_value, max_value):
hook = hooks.SEGSRangeFilterDetailerHook(target, mode, min_value, max_value)
return (hook, )
class SEGSLabelFilterDetailerHookProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"segs": ("SEGS", ),
"preset": (['all'] + defs.detection_labels,),
"labels": ("STRING", {"multiline": True, "placeholder": "List the types of segments to be allowed, separated by commas"}),
},
}
RETURN_TYPES = ("DETAILER_HOOK", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, preset, labels):
hook = hooks.SEGSLabelFilterDetailerHook(labels)
return (hook, )
class PreviewDetailerHookProvider:
@classmethod
def INPUT_TYPES(s):
return {
"required": {"quality": ("INT", {"default": 95, "min": 20, "max": 100})},
"hidden": {"unique_id": "UNIQUE_ID"},
}
RETURN_TYPES = ("DETAILER_HOOK", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, quality, unique_id):
hook = hooks.PreviewDetailerHook(unique_id, quality)
return (hook, )
@@ -1,477 +0,0 @@
import copy
import nodes
from impact import utils
from . import segs_nodes
from thirdparty import noise_nodes
from server import PromptServer
import asyncio
import folder_paths
import os
class PixelKSampleHook:
cur_step = 0
total_step = 0
def __init__(self):
pass
def set_steps(self, info):
self.cur_step, self.total_step = info
def post_decode(self, pixels):
return pixels
def post_upscale(self, pixels):
return pixels
def post_encode(self, samples):
return samples
def pre_decode(self, samples):
return samples
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent,
denoise):
return model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise
def post_crop_region(self, w, h, item_bbox, crop_region):
return crop_region
def touch_scaled_size(self, w, h):
return w, h
class PixelKSampleHookCombine(PixelKSampleHook):
hook1 = None
hook2 = None
def __init__(self, hook1, hook2):
super().__init__()
self.hook1 = hook1
self.hook2 = hook2
def set_steps(self, info):
self.hook1.set_steps(info)
self.hook2.set_steps(info)
def pre_decode(self, samples):
return self.hook2.pre_decode(self.hook1.pre_decode(samples))
def post_decode(self, pixels):
return self.hook2.post_decode(self.hook1.post_decode(pixels))
def post_upscale(self, pixels):
return self.hook2.post_upscale(self.hook1.post_upscale(pixels))
def post_encode(self, samples):
return self.hook2.post_encode(self.hook1.post_encode(samples))
def post_crop_region(self, w, h, item_bbox, crop_region):
crop_region = self.hook1.post_crop_region(w, h, item_bbox, crop_region)
return self.hook2.post_crop_region(w, h, item_bbox, crop_region)
def touch_scaled_size(self, w, h):
w, h = self.hook1.touch_scaled_size(w, h)
return self.hook2.touch_scaled_size(w, h)
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent,
denoise):
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise = \
self.hook1.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
upscaled_latent, denoise)
return self.hook2.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative,
upscaled_latent, denoise)
class DetailerHookCombine(PixelKSampleHookCombine):
def cycle_latent(self, latent):
latent = self.hook1.cycle_latent(latent)
latent = self.hook2.cycle_latent(latent)
return latent
def post_detection(self, segs):
segs = self.hook1.post_detection(segs)
segs = self.hook2.post_detection(segs)
return segs
def post_paste(self, image):
image = self.hook1.post_paste(image)
image = self.hook2.post_paste(image)
return image
class SimpleCfgScheduleHook(PixelKSampleHook):
target_cfg = 0
def __init__(self, target_cfg):
super().__init__()
self.target_cfg = target_cfg
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise):
if self.total_step > 1:
progress = self.cur_step / (self.total_step - 1)
gap = self.target_cfg - cfg
current_cfg = int(cfg + gap * progress)
else:
current_cfg = self.target_cfg
return model, seed, steps, current_cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise
class SimpleDenoiseScheduleHook(PixelKSampleHook):
def __init__(self, target_denoise):
super().__init__()
self.target_denoise = target_denoise
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise):
if self.total_step > 1:
progress = self.cur_step / (self.total_step - 1)
gap = self.target_denoise - denoise
current_denoise = denoise + gap * progress
else:
current_denoise = self.target_denoise
return model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, current_denoise
class SimpleStepsScheduleHook(PixelKSampleHook):
def __init__(self, target_steps):
super().__init__()
self.target_steps = target_steps
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise):
if self.total_step > 1:
progress = self.cur_step / (self.total_step - 1)
gap = self.target_steps - steps
current_steps = int(steps + gap * progress)
else:
current_steps = self.target_steps
return model, seed, current_steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise
class DetailerHook(PixelKSampleHook):
def cycle_latent(self, latent):
return latent
def post_detection(self, segs):
return segs
def post_paste(self, image):
return image
class SimpleDetailerDenoiseSchedulerHook(DetailerHook):
def __init__(self, target_denoise):
super().__init__()
self.target_denoise = target_denoise
def pre_ksample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent, denoise):
if self.total_step > 1:
progress = self.cur_step / (self.total_step - 1)
gap = self.target_denoise - denoise
current_denoise = denoise + gap * progress
else:
# ignore hook if total cycle <= 1
current_denoise = denoise
return model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent, current_denoise
class CoreMLHook(DetailerHook):
def __init__(self, mode):
super().__init__()
resolution = mode.split('x')
self.w = int(resolution[0])
self.h = int(resolution[1])
self.override_bbox_by_segm = False
def pre_decode(self, samples):
new_samples = copy.deepcopy(samples)
new_samples['samples'] = samples['samples'][0].unsqueeze(0)
return new_samples
def post_encode(self, samples):
new_samples = copy.deepcopy(samples)
new_samples['samples'] = samples['samples'].repeat(2, 1, 1, 1)
return new_samples
def post_crop_region(self, w, h, item_bbox, crop_region):
x1, y1, x2, y2 = crop_region
bx1, by1, bx2, by2 = item_bbox
crop_w = x2-x1
crop_h = y2-y1
crop_ratio = crop_w/crop_h
target_ratio = self.w/self.h
if crop_ratio < target_ratio:
# shrink height
top_gap = by1 - y1
bottom_gap = y2 - by2
gap_ratio = top_gap / bottom_gap
target_height = 1/target_ratio*crop_w
delta_height = crop_h - target_height
new_y1 = int(y1 + delta_height*gap_ratio)
new_y2 = int(new_y1 + target_height)
crop_region = x1, new_y1, x2, new_y2
elif crop_ratio > target_ratio:
# shrink width
left_gap = bx1 - x1
right_gap = x2 - bx2
gap_ratio = left_gap / right_gap
target_width = target_ratio*crop_h
delta_width = crop_w - target_width
new_x1 = int(x1 + delta_width*gap_ratio)
new_x2 = int(new_x1 + target_width)
crop_region = new_x1, y1, new_x2, y2
return crop_region
def touch_scaled_size(self, w, h):
return self.w, self.h
# REQUIREMENTS: BlenderNeko/ComfyUI Noise
class InjectNoiseHook(PixelKSampleHook):
def __init__(self, source, seed, start_strength, end_strength):
super().__init__()
self.source = source
self.seed = seed
self.start_strength = start_strength
self.end_strength = end_strength
def post_encode(self, samples):
cur_step = self.cur_step
size = samples['samples'].shape
seed = cur_step + self.seed + cur_step
if "BNK_NoisyLatentImage" in nodes.NODE_CLASS_MAPPINGS and "BNK_InjectNoise" in nodes.NODE_CLASS_MAPPINGS:
NoisyLatentImage = nodes.NODE_CLASS_MAPPINGS["BNK_NoisyLatentImage"]
InjectNoise = nodes.NODE_CLASS_MAPPINGS["BNK_InjectNoise"]
else:
utils.try_install_custom_node('https://github.com/BlenderNeko/ComfyUI_Noise',
"To use 'NoiseInjectionHookProvider', 'ComfyUI Noise' extension is required.")
raise Exception("'BNK_NoisyLatentImage', 'BNK_InjectNoise' nodes are not installed.")
noise = NoisyLatentImage().create_noisy_latents(self.source, seed, size[3] * 8, size[2] * 8, size[0])[0]
# inj noise
mask = None
if 'noise_mask' in samples:
mask = samples['noise_mask']
strength = self.start_strength + (self.end_strength - self.start_strength) * cur_step / self.total_step
samples = InjectNoise().inject_noise(samples, strength, noise, mask)[0]
print(f"[Impact Pack] InjectNoiseHook: strength = {strength}")
if mask is not None:
samples['noise_mask'] = mask
return samples
class UnsamplerHook(PixelKSampleHook):
def __init__(self, model, steps, start_end_at_step, end_end_at_step, cfg, sampler_name,
scheduler, normalize, positive, negative):
super().__init__()
self.model = model
self.cfg = cfg
self.sampler_name = sampler_name
self.steps = steps
self.start_end_at_step = start_end_at_step
self.end_end_at_step = end_end_at_step
self.scheduler = scheduler
self.normalize = normalize
self.positive = positive
self.negative = negative
def post_encode(self, samples):
cur_step = self.cur_step
Unsampler = noise_nodes.Unsampler
end_at_step = self.start_end_at_step + (self.end_end_at_step - self.start_end_at_step) * cur_step / self.total_step
end_at_step = int(end_at_step)
print(f"[Impact Pack] UnsamplerHook: end_at_step = {end_at_step}")
# inj noise
mask = None
if 'noise_mask' in samples:
mask = samples['noise_mask']
samples = Unsampler().unsampler(self.model, self.cfg, self.sampler_name, self.steps, end_at_step,
self.scheduler, self.normalize, self.positive, self.negative, samples)[0]
if mask is not None:
samples['noise_mask'] = mask
return samples
class InjectNoiseHookForDetailer(DetailerHook):
def __init__(self, source, seed, start_strength, end_strength, from_start=False):
super().__init__()
self.source = source
self.seed = seed
self.start_strength = start_strength
self.end_strength = end_strength
self.from_start = from_start
def inject_noise(self, samples):
cur_step = self.cur_step if self.from_start else self.cur_step - 1
total_step = self.total_step if self.from_start else self.total_step - 1
size = samples['samples'].shape
seed = cur_step + self.seed + cur_step
if "BNK_NoisyLatentImage" in nodes.NODE_CLASS_MAPPINGS and "BNK_InjectNoise" in nodes.NODE_CLASS_MAPPINGS:
NoisyLatentImage = nodes.NODE_CLASS_MAPPINGS["BNK_NoisyLatentImage"]
InjectNoise = nodes.NODE_CLASS_MAPPINGS["BNK_InjectNoise"]
else:
utils.try_install_custom_node('https://github.com/BlenderNeko/ComfyUI_Noise',
"To use 'NoiseInjectionDetailerHookProvider', 'ComfyUI Noise' extension is required.")
raise Exception("'BNK_NoisyLatentImage', 'BNK_InjectNoise' nodes are not installed.")
noise = NoisyLatentImage().create_noisy_latents(self.source, seed, size[3] * 8, size[2] * 8, size[0])[0]
# inj noise
mask = None
if 'noise_mask' in samples:
mask = samples['noise_mask']
strength = self.start_strength + (self.end_strength - self.start_strength) * cur_step / total_step
samples = InjectNoise().inject_noise(samples, strength, noise, mask)[0]
if mask is not None:
samples['noise_mask'] = mask
return samples
def cycle_latent(self, latent):
if self.cur_step == 0 and not self.from_start:
return latent
else:
return self.inject_noise(latent)
class UnsamplerDetailerHook(DetailerHook):
def __init__(self, model, steps, start_end_at_step, end_end_at_step, cfg, sampler_name,
scheduler, normalize, positive, negative, from_start=False):
super().__init__()
self.model = model
self.cfg = cfg
self.sampler_name = sampler_name
self.steps = steps
self.start_end_at_step = start_end_at_step
self.end_end_at_step = end_end_at_step
self.scheduler = scheduler
self.normalize = normalize
self.positive = positive
self.negative = negative
self.from_start = from_start
def unsample(self, samples):
cur_step = self.cur_step if self.from_start else self.cur_step - 1
total_step = self.total_step if self.from_start else self.total_step - 1
Unsampler = noise_nodes.Unsampler
end_at_step = self.start_end_at_step + (self.end_end_at_step - self.start_end_at_step) * cur_step / total_step
end_at_step = int(end_at_step)
# inj noise
mask = None
if 'noise_mask' in samples:
mask = samples['noise_mask']
samples = Unsampler().unsampler(self.model, self.cfg, self.sampler_name, self.steps, end_at_step,
self.scheduler, self.normalize, self.positive, self.negative, samples)[0]
if mask is not None:
samples['noise_mask'] = mask
return samples
def cycle_latent(self, latent):
if self.cur_step == 0 and not self.from_start:
return latent
else:
return self.unsample(latent)
class SEGSOrderedFilterDetailerHook(DetailerHook):
def __init__(self, target, order, take_start, take_count):
super().__init__()
self.target = target
self.order = order
self.take_start = take_start
self.take_count = take_count
def post_detection(self, segs):
return segs_nodes.SEGSOrderedFilter().doit(segs, self.target, self.order, self.take_start, self.take_count)[0]
class SEGSRangeFilterDetailerHook(DetailerHook):
def __init__(self, target, mode, min_value, max_value):
super().__init__()
self.target = target
self.mode = mode
self.min_value = min_value
self.max_value = max_value
def post_detection(self, segs):
return segs_nodes.SEGSRangeFilter().doit(segs, self.target, self.mode, self.min_value, self.max_value)[0]
class SEGSLabelFilterDetailerHook(DetailerHook):
def __init__(self, labels):
super().__init__()
self.labels = labels
def post_detection(self, segs):
return segs_nodes.SEGSLabelFilter().doit(segs, "", self.labels)[0]
class PreviewDetailerHook(DetailerHook):
def __init__(self, node_id, quality):
super().__init__()
self.node_id = node_id
self.quality = quality
async def send(self, image):
if len(image) > 0:
image = image[0].unsqueeze(0)
img = utils.tensor2pil(image)
temp_path = os.path.join(folder_paths.get_temp_directory(), 'pvhook')
if not os.path.exists(temp_path):
os.makedirs(temp_path)
fullpath = os.path.join(temp_path, f"{self.node_id}.webp")
img.save(fullpath, quality=self.quality)
item = {
"filename": f"{self.node_id}.webp",
"subfolder": 'pvhook',
"type": 'temp'
}
PromptServer.instance.send_sync("impact-preview", {'node_id': self.node_id, 'item': item})
def post_paste(self, image):
asyncio.run(self.send(image))
return image
@@ -1,232 +0,0 @@
import nodes
from comfy.k_diffusion import sampling as k_diffusion_sampling
from comfy import samplers
from comfy_extras import nodes_custom_sampler
import torch
import math
def calculate_sigmas(model, sampler, scheduler, steps):
discard_penultimate_sigma = False
if sampler in ['dpm_2', 'dpm_2_ancestral', 'uni_pc', 'uni_pc_bh2']:
steps += 1
discard_penultimate_sigma = True
sigmas = samplers.calculate_sigmas_scheduler(model.model, scheduler, steps)
if discard_penultimate_sigma:
sigmas = torch.cat([sigmas[:-2], sigmas[-1:]])
return sigmas
def get_noise_sampler(x, cpu, total_sigmas, **kwargs):
if 'extra_args' in kwargs and 'seed' in kwargs['extra_args']:
sigma_min, sigma_max = total_sigmas[total_sigmas > 0].min(), total_sigmas.max()
seed = kwargs['extra_args'].get("seed", None)
return k_diffusion_sampling.BrownianTreeNoiseSampler(x, sigma_min, sigma_max, seed=seed, cpu=cpu)
return None
def ksampler(sampler_name, total_sigmas, extra_options={}, inpaint_options={}):
if sampler_name == "dpmpp_sde":
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
noise_sampler = get_noise_sampler(x, True, total_sigmas, **kwargs)
if noise_sampler is not None:
kwargs['noise_sampler'] = noise_sampler
return k_diffusion_sampling.sample_dpmpp_sde(model, x, sigmas, **kwargs)
sampler_function = sample_dpmpp_sde
elif sampler_name == "dpmpp_sde_gpu":
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
noise_sampler = get_noise_sampler(x, False, total_sigmas, **kwargs)
if noise_sampler is not None:
kwargs['noise_sampler'] = noise_sampler
return k_diffusion_sampling.sample_dpmpp_sde_gpu(model, x, sigmas, **kwargs)
sampler_function = sample_dpmpp_sde
elif sampler_name == "dpmpp_2m_sde":
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
noise_sampler = get_noise_sampler(x, True, total_sigmas, **kwargs)
if noise_sampler is not None:
kwargs['noise_sampler'] = noise_sampler
return k_diffusion_sampling.sample_dpmpp_2m_sde(model, x, sigmas, **kwargs)
sampler_function = sample_dpmpp_sde
elif sampler_name == "dpmpp_2m_sde_gpu":
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
noise_sampler = get_noise_sampler(x, False, total_sigmas, **kwargs)
if noise_sampler is not None:
kwargs['noise_sampler'] = noise_sampler
return k_diffusion_sampling.sample_dpmpp_2m_sde_gpu(model, x, sigmas, **kwargs)
sampler_function = sample_dpmpp_sde
elif sampler_name == "dpmpp_3m_sde":
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
noise_sampler = get_noise_sampler(x, True, total_sigmas, **kwargs)
if noise_sampler is not None:
kwargs['noise_sampler'] = noise_sampler
return k_diffusion_sampling.sample_dpmpp_2m_sde(model, x, sigmas, **kwargs)
sampler_function = sample_dpmpp_sde
elif sampler_name == "dpmpp_3m_sde_gpu":
def sample_dpmpp_sde(model, x, sigmas, **kwargs):
noise_sampler = get_noise_sampler(x, False, total_sigmas, **kwargs)
if noise_sampler is not None:
kwargs['noise_sampler'] = noise_sampler
return k_diffusion_sampling.sample_dpmpp_2m_sde_gpu(model, x, sigmas, **kwargs)
sampler_function = sample_dpmpp_sde
else:
return samplers.ksampler(sampler_name, extra_options, inpaint_options)
return samplers.KSAMPLER(sampler_function, extra_options, inpaint_options)
def separated_sample(model, add_noise, seed, steps, cfg, sampler_name, scheduler, positive, negative,
latent_image, start_at_step, end_at_step, return_with_leftover_noise, sigma_ratio=1.0, sampler_opt=None):
if sampler_opt is None:
total_sigmas = calculate_sigmas(model, sampler_name, scheduler, steps)
else:
total_sigmas = calculate_sigmas(model, "", scheduler, steps)
sigmas = total_sigmas[start_at_step:end_at_step+1] * sigma_ratio
if sampler_opt is None:
impact_sampler = ksampler(sampler_name, total_sigmas)
else:
impact_sampler = sampler_opt
if len(sigmas) == 0 or (len(sigmas) == 1 and sigmas[0] == 0):
return latent_image
res = nodes_custom_sampler.SamplerCustom().sample(model, add_noise, seed, cfg, positive, negative, impact_sampler, sigmas, latent_image)
if return_with_leftover_noise:
return res[0]
else:
return res[1]
def ksampler_wrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise,
refiner_ratio=None, refiner_model=None, refiner_clip=None, refiner_positive=None, refiner_negative=None, sigma_factor=1.0):
if refiner_ratio is None or refiner_model is None or refiner_clip is None or refiner_positive is None or refiner_negative is None:
refined_latent = nodes.KSampler().sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise * sigma_factor)[0]
else:
advanced_steps = math.floor(steps / denoise)
start_at_step = advanced_steps - steps
end_at_step = start_at_step + math.floor(steps * (1.0 - refiner_ratio))
# print(f"pre: {start_at_step} .. {end_at_step} / {advanced_steps}")
temp_latent = separated_sample(model, True, seed, advanced_steps, cfg, sampler_name, scheduler,
positive, negative, latent_image, start_at_step, end_at_step, True, sigma_ratio=sigma_factor)
if 'noise_mask' in latent_image:
# noise_latent = \
# impact_sampling.separated_sample(refiner_model, "enable", seed, advanced_steps, cfg, sampler_name,
# scheduler, refiner_positive, refiner_negative, latent_image, end_at_step,
# end_at_step, "enable")
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
temp_latent = latent_compositor.composite(latent_image, temp_latent, 0, 0, False, latent_image['noise_mask'])[0]
# print(f"post: {end_at_step} .. {advanced_steps + 1} / {advanced_steps}")
refined_latent = separated_sample(refiner_model, False, seed, advanced_steps, cfg, sampler_name, scheduler,
refiner_positive, refiner_negative, temp_latent, end_at_step, advanced_steps + 1, False, sigma_ratio=sigma_factor)
return refined_latent
class KSamplerAdvancedWrapper:
params = None
def __init__(self, model, cfg, sampler_name, scheduler, positive, negative, sampler_opt=None, sigma_factor=1.0):
self.params = model, cfg, sampler_name, scheduler, positive, negative, sigma_factor
self.sampler_opt = sampler_opt
def clone_with_conditionings(self, positive, negative):
model, cfg, sampler_name, scheduler, _, _, _ = self.params
return KSamplerAdvancedWrapper(model, cfg, sampler_name, scheduler, positive, negative, self.sampler_opt)
def sample_advanced(self, add_noise, seed, steps, latent_image, start_at_step, end_at_step, return_with_leftover_noise, hook=None,
recovery_mode="ratio additional", recovery_sampler="AUTO", recovery_sigma_ratio=1.0):
model, cfg, sampler_name, scheduler, positive, negative, sigma_factor = self.params
# steps, start_at_step, end_at_step = self.compensate_denoise(steps, start_at_step, end_at_step)
if hook is not None:
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent = hook.pre_ksample_advanced(model, add_noise, seed, steps, cfg, sampler_name, scheduler,
positive, negative, latent_image, start_at_step, end_at_step,
return_with_leftover_noise)
if recovery_mode != 'DISABLE' and sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu']:
base_image = latent_image.copy()
if recovery_mode == "ratio between":
sigma_ratio = 1.0 - recovery_sigma_ratio
else:
sigma_ratio = 1.0
else:
base_image = None
sigma_ratio = 1.0
try:
if sigma_ratio > 0:
latent_image = separated_sample(model, add_noise, seed, steps, cfg, sampler_name, scheduler,
positive, negative, latent_image, start_at_step, end_at_step,
return_with_leftover_noise, sigma_ratio=sigma_ratio * sigma_factor, sampler_opt=self.sampler_opt)
except ValueError as e:
if str(e) == 'sigma_min and sigma_max must not be 0':
print(f"\nWARN: sampling skipped - sigma_min and sigma_max are 0")
return latent_image
if (recovery_sigma_ratio > 0 and recovery_mode != 'DISABLE' and
sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu']):
compensate = 0 if sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu'] else 2
if recovery_sampler == "AUTO":
recovery_sampler = 'dpm_fast' if sampler_name in ['uni_pc', 'uni_pc_bh2', 'dpmpp_sde', 'dpmpp_sde_gpu'] else 'dpmpp_2m'
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
noise_mask = latent_image['noise_mask']
if len(noise_mask.shape) == 4:
noise_mask = noise_mask.squeeze(0).squeeze(0)
latent_image = latent_compositor.composite(base_image, latent_image, 0, 0, False, noise_mask)[0]
try:
latent_image = separated_sample(model, add_noise, seed, steps, cfg, recovery_sampler, scheduler,
positive, negative, latent_image, start_at_step-compensate, end_at_step,
return_with_leftover_noise, sigma_ratio=recovery_sigma_ratio * sigma_factor, sampler_opt=self.sampler_opt)
except ValueError as e:
if str(e) == 'sigma_min and sigma_max must not be 0':
print(f"\nWARN: sampling skipped - sigma_min and sigma_max are 0")
return latent_image
class KSamplerWrapper:
params = None
def __init__(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise):
self.params = model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise
def sample(self, latent_image, hook=None):
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise = self.params
if hook is not None:
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, upscaled_latent, denoise = \
hook.pre_ksample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)
return nodes.common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)[0]
@@ -1,556 +0,0 @@
import os
import threading
import traceback
from aiohttp import web
import impact
import server
import folder_paths
import torchvision
import impact.core as core
import impact.impact_pack as impact_pack
from impact.utils import to_tensor
from segment_anything import SamPredictor, sam_model_registry
import numpy as np
import nodes
from PIL import Image
import io
import impact.wildcards as wildcards
import comfy
from io import BytesIO
import random
@server.PromptServer.instance.routes.post("/upload/temp")
async def upload_image(request):
upload_dir = folder_paths.get_temp_directory()
if not os.path.exists(upload_dir):
os.makedirs(upload_dir)
post = await request.post()
image = post.get("image")
if image and image.file:
filename = image.filename
if not filename:
return web.Response(status=400)
split = os.path.splitext(filename)
i = 1
while os.path.exists(os.path.join(upload_dir, filename)):
filename = f"{split[0]} ({i}){split[1]}"
i += 1
filepath = os.path.join(upload_dir, filename)
with open(filepath, "wb") as f:
f.write(image.file.read())
return web.json_response({"name": filename})
else:
return web.Response(status=400)
sam_predictor = None
default_sam_model_name = os.path.join(impact_pack.model_path, "sams", "sam_vit_b_01ec64.pth")
sam_lock = threading.Condition()
last_prepare_data = None
def async_prepare_sam(image_dir, model_name, filename):
with sam_lock:
global sam_predictor
if 'vit_h' in model_name:
model_kind = 'vit_h'
elif 'vit_l' in model_name:
model_kind = 'vit_l'
else:
model_kind = 'vit_b'
sam_model = sam_model_registry[model_kind](checkpoint=model_name)
sam_predictor = SamPredictor(sam_model)
image_path = os.path.join(image_dir, filename)
image = nodes.LoadImage().load_image(image_path)[0]
image = np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)
if impact.config.get_config()['sam_editor_cpu']:
device = 'cpu'
else:
device = comfy.model_management.get_torch_device()
sam_predictor.model.to(device=device)
sam_predictor.set_image(image, "RGB")
sam_predictor.model.cpu()
@server.PromptServer.instance.routes.post("/sam/prepare")
async def sam_prepare(request):
global sam_predictor
global last_prepare_data
data = await request.json()
with sam_lock:
if last_prepare_data is not None and last_prepare_data == data:
# already loaded: skip -- prevent redundant loading
return web.Response(status=200)
last_prepare_data = data
model_name = 'sam_vit_b_01ec64.pth'
if data['sam_model_name'] == 'auto':
model_name = impact.config.get_config()['sam_editor_model']
model_name = os.path.join(impact_pack.model_path, "sams", model_name)
print(f"[INFO] ComfyUI-Impact-Pack: Loading SAM model '{impact_pack.model_path}'")
filename, image_dir = folder_paths.annotated_filepath(data["filename"])
if image_dir is None:
typ = data['type'] if data['type'] != '' else 'output'
image_dir = folder_paths.get_directory_by_type(typ)
if data['subfolder'] is not None and data['subfolder'] != '':
image_dir += f"/{data['subfolder']}"
if image_dir is None:
return web.Response(status=400)
thread = threading.Thread(target=async_prepare_sam, args=(image_dir, model_name, filename,))
thread.start()
print(f"[INFO] ComfyUI-Impact-Pack: SAM model loaded. ")
@server.PromptServer.instance.routes.post("/sam/release")
async def release_sam(request):
global sam_predictor
with sam_lock:
del sam_predictor
sam_predictor = None
print(f"[INFO] ComfyUI-Impact-Pack: unloading SAM model")
@server.PromptServer.instance.routes.post("/sam/detect")
async def sam_detect(request):
global sam_predictor
with sam_lock:
if sam_predictor is not None:
if impact.config.get_config()['sam_editor_cpu']:
device = 'cpu'
else:
device = comfy.model_management.get_torch_device()
sam_predictor.model.to(device=device)
try:
data = await request.json()
positive_points = data['positive_points']
negative_points = data['negative_points']
threshold = data['threshold']
points = []
plabs = []
for p in positive_points:
points.append(p)
plabs.append(1)
for p in negative_points:
points.append(p)
plabs.append(0)
detected_masks = core.sam_predict(sam_predictor, points, plabs, None, threshold)
mask = core.combine_masks2(detected_masks)
if mask is None:
return web.Response(status=400)
image = mask.reshape((-1, 1, mask.shape[-2], mask.shape[-1])).movedim(1, -1).expand(-1, -1, -1, 3)
i = 255. * image.cpu().numpy()
img = Image.fromarray(np.clip(i[0], 0, 255).astype(np.uint8))
img_buffer = io.BytesIO()
img.save(img_buffer, format='png')
headers = {'Content-Type': 'image/png'}
finally:
sam_predictor.model.to(device="cpu")
return web.Response(body=img_buffer.getvalue(), headers=headers)
else:
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/wildcards/list")
async def wildcards_list(request):
data = {'data': impact.wildcards.get_wildcard_list()}
return web.json_response(data)
@server.PromptServer.instance.routes.post("/impact/wildcards")
async def populate_wildcards(request):
data = await request.json()
populated = wildcards.process(data['text'], data.get('seed', None))
return web.json_response({"text": populated})
segs_picker_map = {}
@server.PromptServer.instance.routes.get("/impact/segs/picker/count")
async def segs_picker_count(request):
node_id = request.rel_url.query.get('id', '')
if node_id in segs_picker_map:
res = len(segs_picker_map[node_id])
return web.Response(status=200, text=str(res))
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/segs/picker/view")
async def segs_picker(request):
node_id = request.rel_url.query.get('id', '')
idx = int(request.rel_url.query.get('idx', ''))
if node_id in segs_picker_map and idx < len(segs_picker_map[node_id]):
img = to_tensor(segs_picker_map[node_id][idx]).permute(0, 3, 1, 2).squeeze(0)
pil = torchvision.transforms.ToPILImage('RGB')(img)
image_bytes = BytesIO()
pil.save(image_bytes, format="PNG")
image_bytes.seek(0)
return web.Response(status=200, body=image_bytes, content_type='image/png', headers={"Content-Disposition": f"filename={node_id}{idx}.png"})
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/view/validate")
async def view_validate(request):
if "filename" in request.rel_url.query:
filename = request.rel_url.query["filename"]
subfolder = request.rel_url.query["subfolder"]
filename, base_dir = folder_paths.annotated_filepath(filename)
if filename == '' or filename[0] == '/' or '..' in filename:
return web.Response(status=400)
if base_dir is None:
base_dir = folder_paths.get_input_directory()
file = os.path.join(base_dir, subfolder, filename)
if os.path.isfile(file):
return web.Response(status=200)
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/validate/pb_id_image")
async def view_validate(request):
if "id" in request.rel_url.query:
pb_id = request.rel_url.query["id"]
if pb_id not in core.preview_bridge_image_id_map:
return web.Response(status=400)
file = core.preview_bridge_image_id_map[pb_id]
if os.path.isfile(file):
return web.Response(status=200)
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/set/pb_id_image")
async def set_previewbridge_image(request):
try:
if "filename" in request.rel_url.query:
node_id = request.rel_url.query["node_id"]
filename = request.rel_url.query["filename"]
path_type = request.rel_url.query["type"]
subfolder = request.rel_url.query["subfolder"]
filename, output_dir = folder_paths.annotated_filepath(filename)
if filename == '' or filename[0] == '/' or '..' in filename:
return web.Response(status=400)
if output_dir is None:
if path_type == 'input':
output_dir = folder_paths.get_input_directory()
elif path_type == 'output':
output_dir = folder_paths.get_output_directory()
else:
output_dir = folder_paths.get_temp_directory()
file = os.path.join(output_dir, subfolder, filename)
item = {
'filename': filename,
'type': path_type,
'subfolder': subfolder,
}
pb_id = core.set_previewbridge_image(node_id, file, item)
return web.Response(status=200, text=pb_id)
except Exception:
traceback.print_exc()
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/get/pb_id_image")
async def get_previewbridge_image(request):
if "id" in request.rel_url.query:
pb_id = request.rel_url.query["id"]
if pb_id in core.preview_bridge_image_id_map:
_, path_item = core.preview_bridge_image_id_map[pb_id]
return web.json_response(path_item)
return web.Response(status=400)
@server.PromptServer.instance.routes.get("/impact/view/pb_id_image")
async def view_previewbridge_image(request):
if "id" in request.rel_url.query:
pb_id = request.rel_url.query["id"]
if pb_id in core.preview_bridge_image_id_map:
file = core.preview_bridge_image_id_map[pb_id]
with Image.open(file) as img:
filename = os.path.basename(file)
return web.FileResponse(file, headers={"Content-Disposition": f"filename=\"{filename}\""})
return web.Response(status=400)
def onprompt_for_switch(json_data):
inversed_switch_info = {}
onprompt_switch_info = {}
onprompt_cond_branch_info = {}
for k, v in json_data['prompt'].items():
if 'class_type' not in v:
continue
cls = v['class_type']
if cls == 'ImpactInversedSwitch':
select_input = v['inputs']['select']
if isinstance(select_input, list) and len(select_input) == 2:
input_node = json_data['prompt'][select_input[0]]
if input_node['class_type'] == 'ImpactInt' and 'inputs' in input_node and 'value' in input_node['inputs']:
inversed_switch_info[k] = input_node['inputs']['value']
else:
inversed_switch_info[k] = select_input
elif cls in ['ImpactSwitch', 'LatentSwitch', 'SEGSSwitch', 'ImpactMakeImageList']:
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode'] and 'select' in v['inputs']:
select_input = v['inputs']['select']
if isinstance(select_input, list) and len(select_input) == 2:
input_node = json_data['prompt'][select_input[0]]
if input_node['class_type'] == 'ImpactInt' and 'inputs' in input_node and 'value' in input_node['inputs']:
onprompt_switch_info[k] = input_node['inputs']['value']
if input_node['class_type'] == 'ImpactSwitch' and 'inputs' in input_node and 'select' in input_node['inputs']:
if isinstance(input_node['inputs']['select'], int):
onprompt_switch_info[k] = input_node['inputs']['select']
else:
print(f"\n##### ##### #####\n[WARN] {cls}: For the 'select' operation, only 'select_index' of the 'ImpactSwitch', which is not an input, or 'ImpactInt' and 'Primitive' are allowed as inputs.\n##### ##### #####\n")
else:
onprompt_switch_info[k] = select_input
elif cls == 'ImpactConditionalBranchSelMode':
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode'] and 'cond' in v['inputs']:
cond_input = v['inputs']['cond']
if isinstance(cond_input, list) and len(cond_input) == 2:
input_node = json_data['prompt'][cond_input[0]]
if (input_node['class_type'] == 'ImpactValueReceiver' and 'inputs' in input_node
and 'value' in input_node['inputs'] and 'typ' in input_node['inputs']):
if 'BOOLEAN' == input_node['inputs']['typ']:
try:
onprompt_cond_branch_info[k] = input_node['inputs']['value'].lower() == "true"
except:
pass
else:
onprompt_cond_branch_info[k] = cond_input
for k, v in json_data['prompt'].items():
disable_targets = set()
for kk, vv in v['inputs'].items():
if isinstance(vv, list) and len(vv) == 2:
if vv[0] in inversed_switch_info:
if vv[1] + 1 != inversed_switch_info[vv[0]]:
disable_targets.add(kk)
if k in onprompt_switch_info:
selected_slot_name = f"input{onprompt_switch_info[k]}"
for kk, vv in v['inputs'].items():
if kk != selected_slot_name and kk.startswith('input'):
disable_targets.add(kk)
if k in onprompt_cond_branch_info:
selected_slot_name = "tt_value" if onprompt_cond_branch_info[k] else "ff_value"
for kk, vv in v['inputs'].items():
if kk in ['tt_value', 'ff_value'] and kk != selected_slot_name:
disable_targets.add(kk)
for kk in disable_targets:
del v['inputs'][kk]
def onprompt_for_pickers(json_data):
detected_pickers = set()
for k, v in json_data['prompt'].items():
if 'class_type' not in v:
continue
cls = v['class_type']
if cls == 'ImpactSEGSPicker':
detected_pickers.add(k)
# garbage collection
keys_to_remove = [key for key in segs_picker_map if key not in detected_pickers]
for key in keys_to_remove:
del segs_picker_map[key]
def gc_preview_bridge_cache(json_data):
prompt_keys = json_data['prompt'].keys()
for key in list(core.preview_bridge_cache.keys()):
if key not in prompt_keys:
print(f"key deleted: {key}")
del core.preview_bridge_cache[key]
def workflow_imagereceiver_update(json_data):
prompt = json_data['prompt']
for v in prompt.values():
if 'class_type' in v and v['class_type'] == 'ImageReceiver':
if v['inputs']['save_to_workflow']:
v['inputs']['image'] = "#DATA"
def regional_sampler_seed_update(json_data):
prompt = json_data['prompt']
for k, v in prompt.items():
if 'class_type' in v and v['class_type'] == 'RegionalSampler':
seed_2nd_mode = v['inputs']['seed_2nd_mode']
new_seed = None
if seed_2nd_mode == 'increment':
new_seed = v['inputs']['seed_2nd']+1
if new_seed > 1125899906842624:
new_seed = 0
elif seed_2nd_mode == 'decrement':
new_seed = v['inputs']['seed_2nd']-1
if new_seed < 0:
new_seed = 1125899906842624
elif seed_2nd_mode == 'randomize':
new_seed = random.randint(0, 1125899906842624)
if new_seed is not None:
server.PromptServer.instance.send_sync("impact-node-feedback", {"node_id": k, "widget_name": "seed_2nd", "type": "INT", "value": new_seed})
def onprompt_populate_wildcards(json_data):
prompt = json_data['prompt']
updated_widget_values = {}
for k, v in prompt.items():
if 'class_type' in v and (v['class_type'] == 'ImpactWildcardEncode' or v['class_type'] == 'ImpactWildcardProcessor'):
inputs = v['inputs']
if inputs['mode'] and isinstance(inputs['populated_text'], str):
if isinstance(inputs['seed'], list):
try:
input_node = prompt[inputs['seed'][0]]
if input_node['class_type'] == 'ImpactInt':
input_seed = int(input_node['inputs']['value'])
if not isinstance(input_seed, int):
continue
if input_node['class_type'] == 'Seed (rgthree)':
input_seed = int(input_node['inputs']['seed'])
if not isinstance(input_seed, int):
continue
else:
print(f"[Impact Pack] Only `ImpactInt`, `Seed (rgthree)` and `Primitive` Node are allowed as the seed for '{v['class_type']}'. It will be ignored. ")
continue
except:
continue
else:
input_seed = int(inputs['seed'])
inputs['populated_text'] = wildcards.process(inputs['wildcard_text'], input_seed)
inputs['mode'] = False
server.PromptServer.instance.send_sync("impact-node-feedback", {"node_id": k, "widget_name": "populated_text", "type": "STRING", "value": inputs['populated_text']})
updated_widget_values[k] = inputs['populated_text']
if 'extra_data' in json_data and 'extra_pnginfo' in json_data['extra_data']:
for node in json_data['extra_data']['extra_pnginfo']['workflow']['nodes']:
key = str(node['id'])
if key in updated_widget_values:
node['widgets_values'][1] = updated_widget_values[key]
node['widgets_values'][2] = False
def onprompt_for_remote(json_data):
prompt = json_data['prompt']
for v in prompt.values():
if 'class_type' in v:
cls = v['class_type']
if cls == 'ImpactRemoteBoolean' or cls == 'ImpactRemoteInt':
inputs = v['inputs']
node_id = str(inputs['node_id'])
if node_id not in prompt:
continue
target_inputs = prompt[node_id]['inputs']
widget_name = inputs['widget_name']
if widget_name in target_inputs:
widget_type = None
if cls == 'ImpactRemoteBoolean' and isinstance(target_inputs[widget_name], bool):
widget_type = 'BOOLEAN'
elif cls == 'ImpactRemoteInt' and (isinstance(target_inputs[widget_name], int) or isinstance(target_inputs[widget_name], float)):
widget_type = 'INT'
if widget_type is None:
break
target_inputs[widget_name] = inputs['value']
server.PromptServer.instance.send_sync("impact-node-feedback", {"node_id": node_id, "widget_name": widget_name, "type": widget_type, "value": inputs['value']})
def onprompt(json_data):
try:
onprompt_for_remote(json_data) # NOTE: top priority
onprompt_for_switch(json_data)
onprompt_for_pickers(json_data)
onprompt_populate_wildcards(json_data)
gc_preview_bridge_cache(json_data)
workflow_imagereceiver_update(json_data)
regional_sampler_seed_update(json_data)
except Exception as e:
print(f"[WARN] ComfyUI-Impact-Pack: Error on prompt - several features will not work.\n{e}")
return json_data
server.PromptServer.instance.add_on_prompt_handler(onprompt)
@@ -1,273 +0,0 @@
import folder_paths
import impact.mmdet_nodes as mmdet_nodes
from impact.utils import *
from impact.core import SEG
import impact.core as core
import nodes
class NO_BBOX_MODEL:
pass
class NO_SEGM_MODEL:
pass
class MMDetLoader:
@classmethod
def INPUT_TYPES(s):
bboxs = ["bbox/"+x for x in folder_paths.get_filename_list("mmdets_bbox")]
segms = ["segm/"+x for x in folder_paths.get_filename_list("mmdets_segm")]
return {"required": {"model_name": (bboxs + segms, )}}
RETURN_TYPES = ("BBOX_MODEL", "SEGM_MODEL")
FUNCTION = "load_mmdet"
CATEGORY = "ImpactPack/Legacy"
def load_mmdet(self, model_name):
mmdet_path = folder_paths.get_full_path("mmdets", model_name)
model = mmdet_nodes.load_mmdet(mmdet_path)
if model_name.startswith("bbox"):
return model, NO_SEGM_MODEL()
else:
return NO_BBOX_MODEL(), model
class BboxDetectorForEach:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"bbox_model": ("BBOX_MODEL", ),
"image": ("IMAGE", ),
"threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"dilation": ("INT", {"default": 10, "min": 0, "max": 255, "step": 1}),
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}),
}
}
RETURN_TYPES = ("SEGS", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Legacy"
@staticmethod
def detect(bbox_model, image, threshold, dilation, crop_factor, drop_size=1, detailer_hook=None):
mmdet_results = mmdet_nodes.inference_bbox(bbox_model, image, threshold)
segmasks = core.create_segmasks(mmdet_results)
if dilation > 0:
segmasks = dilate_masks(segmasks, dilation)
items = []
h = image.shape[1]
w = image.shape[2]
for x in segmasks:
item_bbox = x[0]
item_mask = x[1]
y1, x1, y2, x2 = item_bbox
if x2 - x1 > drop_size and y2 - y1 > drop_size:
crop_region = make_crop_region(w, h, item_bbox, crop_factor)
cropped_image = crop_image(image, crop_region)
cropped_mask = crop_ndarray2(item_mask, crop_region)
confidence = x[2]
# bbox_size = (item_bbox[2]-item_bbox[0],item_bbox[3]-item_bbox[1]) # (w,h)
item = SEG(cropped_image, cropped_mask, confidence, crop_region, item_bbox, None, None)
items.append(item)
shape = h, w
return shape, items
def doit(self, bbox_model, image, threshold, dilation, crop_factor):
return (BboxDetectorForEach.detect(bbox_model, image, threshold, dilation, crop_factor), )
class SegmDetectorCombined:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"segm_model": ("SEGM_MODEL", ),
"image": ("IMAGE", ),
"threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"dilation": ("INT", {"default": 0, "min": 0, "max": 255, "step": 1}),
}
}
RETURN_TYPES = ("MASK",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Legacy"
def doit(self, segm_model, image, threshold, dilation):
mmdet_results = mmdet_nodes.inference_segm(image, segm_model, threshold)
segmasks = core.create_segmasks(mmdet_results)
if dilation > 0:
segmasks = dilate_masks(segmasks, dilation)
mask = combine_masks(segmasks)
return (mask,)
class BboxDetectorCombined(SegmDetectorCombined):
@classmethod
def INPUT_TYPES(s):
return {"required": {
"bbox_model": ("BBOX_MODEL", ),
"image": ("IMAGE", ),
"threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"dilation": ("INT", {"default": 4, "min": 0, "max": 255, "step": 1}),
}
}
def doit(self, bbox_model, image, threshold, dilation):
mmdet_results = mmdet_nodes.inference_bbox(bbox_model, image, threshold)
segmasks = core.create_segmasks(mmdet_results)
if dilation > 0:
segmasks = dilate_masks(segmasks, dilation)
mask = combine_masks(segmasks)
return (mask,)
class SegmDetectorForEach:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"segm_model": ("SEGM_MODEL", ),
"image": ("IMAGE", ),
"threshold": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"dilation": ("INT", {"default": 10, "min": 0, "max": 255, "step": 1}),
"crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}),
}
}
RETURN_TYPES = ("SEGS", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Legacy"
def doit(self, segm_model, image, threshold, dilation, crop_factor):
mmdet_results = mmdet_nodes.inference_segm(image, segm_model, threshold)
segmasks = core.create_segmasks(mmdet_results)
if dilation > 0:
segmasks = dilate_masks(segmasks, dilation)
items = []
h = image.shape[1]
w = image.shape[2]
for x in segmasks:
item_bbox = x[0]
item_mask = x[1]
crop_region = make_crop_region(w, h, item_bbox, crop_factor)
cropped_image = crop_image(image, crop_region)
cropped_mask = crop_ndarray2(item_mask, crop_region)
confidence = x[2]
item = SEG(cropped_image, cropped_mask, confidence, crop_region, item_bbox, None, None)
items.append(item)
shape = h,w
return ((shape, items), )
class SegsMaskCombine:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"segs": ("SEGS", ),
"image": ("IMAGE", ),
}
}
RETURN_TYPES = ("MASK",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Legacy"
@staticmethod
def combine(segs, image):
h = image.shape[1]
w = image.shape[2]
mask = np.zeros((h, w), dtype=np.uint8)
for seg in segs[1]:
cropped_mask = seg.cropped_mask
crop_region = seg.crop_region
mask[crop_region[1]:crop_region[3], crop_region[0]:crop_region[2]] |= (cropped_mask * 255).astype(np.uint8)
return torch.from_numpy(mask.astype(np.float32) / 255.0)
def doit(self, segs, image):
return (SegsMaskCombine.combine(segs, image), )
class MaskPainter(nodes.PreviewImage):
@classmethod
def INPUT_TYPES(s):
return {"required": {"images": ("IMAGE",), },
"hidden": {
"prompt": "PROMPT",
"extra_pnginfo": "EXTRA_PNGINFO",
},
"optional": {"mask_image": ("IMAGE_PATH",), },
"optional": {"image": (["#placeholder"], )},
}
RETURN_TYPES = ("MASK",)
FUNCTION = "save_painted_images"
CATEGORY = "ImpactPack/Legacy"
def save_painted_images(self, images, filename_prefix="impact-mask",
prompt=None, extra_pnginfo=None, mask_image=None, image=None):
if image == "#placeholder" or image['image_hash'] != id(images):
# new input image
res = self.save_images(images, filename_prefix, prompt, extra_pnginfo)
item = res['ui']['images'][0]
if not item['filename'].endswith(']'):
filepath = f"{item['filename']} [{item['type']}]"
else:
filepath = item['filename']
_, mask = nodes.LoadImage().load_image(filepath)
res['ui']['aux'] = [id(images), res['ui']['images']]
res['result'] = (mask, )
return res
else:
# new mask
if '0' in image: # fallback
image = image['0']
forward = {'filename': image['forward_filename'],
'subfolder': image['forward_subfolder'],
'type': image['forward_type'], }
res = {'ui': {'images': [forward]}}
imgpath = ""
if 'subfolder' in image and image['subfolder'] != "":
imgpath = image['subfolder'] + "/"
imgpath += f"{image['filename']}"
if 'type' in image and image['type'] != "":
imgpath += f" [{image['type']}]"
res['ui']['aux'] = [id(images), [forward]]
_, mask = nodes.LoadImage().load_image(imgpath)
res['result'] = (mask, )
return res
@@ -1,704 +0,0 @@
import sys
import time
import execution
import folder_paths
import impact.impact_server
from server import PromptServer
from impact.utils import any_typ
import impact.core as core
import re
class ImpactCompare:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"cmp": (['a = b', 'a <> b', 'a > b', 'a < b', 'a >= b', 'a <= b', 'tt', 'ff'],),
"a": (any_typ, ),
"b": (any_typ, ),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = ("BOOLEAN", )
def doit(self, cmp, a, b):
if cmp == "a = b":
return (a == b, )
elif cmp == "a <> b":
return (a != b, )
elif cmp == "a > b":
return (a > b, )
elif cmp == "a < b":
return (a < b, )
elif cmp == "a >= b":
return (a >= b, )
elif cmp == "a <= b":
return (a <= b, )
elif cmp == 'tt':
return (True, )
else:
return (False, )
class ImpactNotEmptySEGS:
@classmethod
def INPUT_TYPES(cls):
return {"required": {"segs": ("SEGS",)}}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = ("BOOLEAN", )
def doit(self, segs):
return (segs[1] != [], )
class ImpactConditionalBranch:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"cond": ("BOOLEAN",),
"tt_value": (any_typ,),
"ff_value": (any_typ,),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = (any_typ, )
def doit(self, cond, tt_value, ff_value):
if cond:
return (tt_value,)
else:
return (ff_value,)
class ImpactConditionalBranchSelMode:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"cond": ("BOOLEAN",),
"sel_mode": ("BOOLEAN", {"default": True, "label_on": "select_on_prompt", "label_off": "select_on_execution"}),
},
"optional": {
"tt_value": (any_typ,),
"ff_value": (any_typ,),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = (any_typ, )
def doit(self, cond, sel_mode, tt_value=None, ff_value=None):
print(f'tt={tt_value is None}\nff={ff_value is None}')
if cond:
return (tt_value,)
else:
return (ff_value,)
class ImpactConvertDataType:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {"required": {"value": (any_typ,)}}
RETURN_TYPES = ("STRING", "FLOAT", "INT", "BOOLEAN")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
@staticmethod
def is_number(string):
pattern = re.compile(r'^[-+]?[0-9]*\.?[0-9]+$')
return bool(pattern.match(string))
def doit(self, value):
if self.is_number(str(value)):
num = value
else:
if str.lower(str(value)) != "false":
num = 1
else:
num = 0
return (str(value), float(num), int(float(num)), bool(float(num)), )
class ImpactIfNone:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {},
"optional": {"signal": (any_typ,), "any_input": (any_typ,), }
}
RETURN_TYPES = (any_typ, "BOOLEAN", )
RETURN_NAMES = ("signal_opt", "bool")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
def doit(self, signal=None, any_input=None):
if any_input is None:
return (signal, False, )
else:
return (signal, True, )
class ImpactLogicalOperators:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"operator": (['and', 'or', 'xor'],),
"bool_a": ("BOOLEAN", {"forceInput": True}),
"bool_b": ("BOOLEAN", {"forceInput": True}),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = ("BOOLEAN", )
def doit(self, operator, bool_a, bool_b):
if operator == "and":
return (bool_a and bool_b, )
elif operator == "or":
return (bool_a or bool_b, )
else:
return (bool_a != bool_b, )
class ImpactConditionalStopIteration:
@classmethod
def INPUT_TYPES(cls):
return {
"required": { "cond": ("BOOLEAN", {"forceInput": True}), },
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = ()
OUTPUT_NODE = True
def doit(self, cond):
if cond:
PromptServer.instance.send_sync("stop-iteration", {})
return {}
class ImpactNeg:
@classmethod
def INPUT_TYPES(cls):
return {
"required": { "value": ("BOOLEAN", {"forceInput": True}), },
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = ("BOOLEAN", )
def doit(self, value):
return (not value, )
class ImpactInt:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"value": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = ("INT", )
def doit(self, value):
return (value, )
class ImpactFloat:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"value": ("FLOAT", {"default": 1.0, "min": -3.402823466e+38, "max": 3.402823466e+38}),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = ("FLOAT", )
def doit(self, value):
return (value, )
class ImpactValueSender:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"value": (any_typ, ),
"link_id": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
},
"optional": {
"signal_opt": (any_typ,),
}
}
OUTPUT_NODE = True
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = (any_typ, )
RETURN_NAMES = ("signal", )
def doit(self, value, link_id=0, signal_opt=None):
PromptServer.instance.send_sync("value-send", {"link_id": link_id, "value": value})
return (signal_opt, )
class ImpactIntConstSender:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"signal": (any_typ, ),
"value": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
"link_id": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
},
}
OUTPUT_NODE = True
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = ()
def doit(self, signal, value, link_id=0):
PromptServer.instance.send_sync("value-send", {"link_id": link_id, "value": value})
return {}
class ImpactValueReceiver:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"typ": (["STRING", "INT", "FLOAT", "BOOLEAN"], ),
"value": ("STRING", {"default": ""}),
"link_id": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1}),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic"
RETURN_TYPES = (any_typ, )
def doit(self, typ, value, link_id=0):
if typ == "INT":
return (int(value), )
elif typ == "FLOAT":
return (float(value), )
elif typ == "BOOLEAN":
return (value.lower() == "true", )
else:
return (value, )
class ImpactImageInfo:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"value": ("IMAGE", ),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = ("INT", "INT", "INT", "INT")
RETURN_NAMES = ("batch", "height", "width", "channel")
def doit(self, value):
return (value.shape[0], value.shape[1], value.shape[2], value.shape[3])
class ImpactLatentInfo:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"value": ("LATENT", ),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = ("INT", "INT", "INT", "INT")
RETURN_NAMES = ("batch", "height", "width", "channel")
def doit(self, value):
shape = value['samples'].shape
return (shape[0], shape[2] * 8, shape[3] * 8, shape[1])
class ImpactMinMax:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"mode": ("BOOLEAN", {"default": True, "label_on": "max", "label_off": "min"}),
"a": (any_typ,),
"b": (any_typ,),
},
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = ("INT", )
def doit(self, mode, a, b):
if mode:
return (max(a, b), )
else:
return (min(a, b),)
class ImpactQueueTrigger:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"signal": (any_typ,),
"mode": ("BOOLEAN", {"default": True, "label_on": "Trigger", "label_off": "Don't trigger"}),
}
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = (any_typ,)
RETURN_NAMES = ("signal_opt",)
OUTPUT_NODE = True
def doit(self, signal, mode):
if(mode):
PromptServer.instance.send_sync("impact-add-queue", {})
return (signal,)
class ImpactQueueTriggerCountdown:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"count": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"total": ("INT", {"default": 10, "min": 1, "max": 0xffffffffffffffff}),
"mode": ("BOOLEAN", {"default": True, "label_on": "Trigger", "label_off": "Don't trigger"}),
},
"optional": {"signal": (any_typ,),},
"hidden": {"unique_id": "UNIQUE_ID"}
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = (any_typ, "INT", "INT")
RETURN_NAMES = ("signal_opt", "count", "total")
OUTPUT_NODE = True
def doit(self, count, total, mode, unique_id, signal=None):
if (mode):
if count < total - 1:
PromptServer.instance.send_sync("impact-node-feedback",
{"node_id": unique_id, "widget_name": "count", "type": "int", "value": count+1})
PromptServer.instance.send_sync("impact-add-queue", {})
if count >= total - 1:
PromptServer.instance.send_sync("impact-node-feedback",
{"node_id": unique_id, "widget_name": "count", "type": "int", "value": 0})
return (signal, count, total)
class ImpactSetWidgetValue:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"signal": (any_typ,),
"node_id": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"widget_name": ("STRING", {"multiline": False}),
},
"optional": {
"boolean_value": ("BOOLEAN", {"forceInput": True}),
"int_value": ("INT", {"forceInput": True}),
"float_value": ("FLOAT", {"forceInput": True}),
"string_value": ("STRING", {"forceInput": True}),
}
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = (any_typ,)
RETURN_NAMES = ("signal_opt",)
OUTPUT_NODE = True
def doit(self, signal, node_id, widget_name, boolean_value=None, int_value=None, float_value=None, string_value=None, ):
kind = None
if boolean_value is not None:
value = boolean_value
kind = "BOOLEAN"
elif int_value is not None:
value = int_value
kind = "INT"
elif float_value is not None:
value = float_value
kind = "FLOAT"
elif string_value is not None:
value = string_value
kind = "STRING"
else:
value = None
if value is not None:
PromptServer.instance.send_sync("impact-node-feedback",
{"node_id": node_id, "widget_name": widget_name, "type": kind, "value": value})
return (signal,)
class ImpactNodeSetMuteState:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"signal": (any_typ,),
"node_id": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"set_state": ("BOOLEAN", {"default": True, "label_on": "active", "label_off": "mute"}),
}
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = (any_typ,)
RETURN_NAMES = ("signal_opt",)
OUTPUT_NODE = True
def doit(self, signal, node_id, set_state):
PromptServer.instance.send_sync("impact-node-mute-state", {"node_id": node_id, "is_active": set_state})
return (signal,)
class ImpactSleep:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"signal": (any_typ,),
"seconds": ("FLOAT", {"default": 0.5, "min": 0, "max": 3600}),
}
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = (any_typ,)
RETURN_NAMES = ("signal_opt",)
OUTPUT_NODE = True
def doit(self, signal, seconds):
time.sleep(seconds)
return (signal,)
error_skip_flag = False
try:
import cm_global
def filter_message(str):
global error_skip_flag
if "IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE" in str:
return True
elif error_skip_flag and "ERROR:root:!!! Exception during processing !!!\n" == str:
error_skip_flag = False
return True
else:
return False
cm_global.try_call(api='cm.register_message_collapse', f=filter_message)
except Exception as e:
print(f"[WARN] ComfyUI-Impact-Pack: `ComfyUI` or `ComfyUI-Manager` is an outdated version.")
pass
def workflow_to_map(workflow):
nodes = {}
links = {}
for link in workflow['links']:
links[link[0]] = link[1:]
for node in workflow['nodes']:
nodes[str(node['id'])] = node
return nodes, links
class ImpactRemoteBoolean:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"node_id": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"widget_name": ("STRING", {"multiline": False}),
"value": ("BOOLEAN", {"default": True, "label_on": "True", "label_off": "False"}),
}}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = ()
OUTPUT_NODE = True
def doit(self, **kwargs):
return {}
class ImpactRemoteInt:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"node_id": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"widget_name": ("STRING", {"multiline": False}),
"value": ("INT", {"default": 0, "min": -0xffffffffffffffff, "max": 0xffffffffffffffff}),
}}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = ()
OUTPUT_NODE = True
def doit(self, **kwargs):
return {}
class ImpactControlBridge:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"value": (any_typ,),
"mode": ("BOOLEAN", {"default": True, "label_on": "Active", "label_off": "Mute/Bypass"}),
"behavior": ("BOOLEAN", {"default": True, "label_on": "Mute", "label_off": "Bypass"}),
},
"hidden": {"unique_id": "UNIQUE_ID", "prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"}
}
FUNCTION = "doit"
CATEGORY = "ImpactPack/Logic/_for_test"
RETURN_TYPES = (any_typ,)
RETURN_NAMES = ("value",)
OUTPUT_NODE = True
@classmethod
def IS_CHANGED(self, value, mode, behavior=True, unique_id=None, prompt=None, extra_pnginfo=None):
nodes, links = workflow_to_map(extra_pnginfo['workflow'])
next_nodes = []
for link in nodes[unique_id]['outputs'][0]['links']:
node_id = str(links[link][2])
impact.utils.collect_non_reroute_nodes(nodes, links, next_nodes, node_id)
return next_nodes
def doit(self, value, mode, behavior=True, unique_id=None, prompt=None, extra_pnginfo=None):
global error_skip_flag
nodes, links = workflow_to_map(extra_pnginfo['workflow'])
active_nodes = []
mute_nodes = []
bypass_nodes = []
for link in nodes[unique_id]['outputs'][0]['links']:
node_id = str(links[link][2])
next_nodes = []
impact.utils.collect_non_reroute_nodes(nodes, links, next_nodes, node_id)
for next_node_id in next_nodes:
node_mode = nodes[next_node_id]['mode']
if node_mode == 0:
active_nodes.append(next_node_id)
elif node_mode == 2:
mute_nodes.append(next_node_id)
elif node_mode == 4:
bypass_nodes.append(next_node_id)
if mode:
# active
should_be_active_nodes = mute_nodes + bypass_nodes
if len(should_be_active_nodes) > 0:
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'actives': list(should_be_active_nodes)})
error_skip_flag = True
raise Exception("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it.")
elif behavior:
# mute
should_be_mute_nodes = active_nodes + bypass_nodes
if len(should_be_mute_nodes) > 0:
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'mutes': list(should_be_mute_nodes)})
error_skip_flag = True
raise Exception("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it.")
else:
# bypass
should_be_bypass_nodes = active_nodes + mute_nodes
if len(should_be_bypass_nodes) > 0:
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, 'bypasses': list(should_be_bypass_nodes)})
error_skip_flag = True
raise Exception("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it.")
return (value, )
original_handle_execution = execution.PromptExecutor.handle_execution_error
def handle_execution_error(**kwargs):
print(f" handled")
execution.PromptExecutor.handle_execution_error(**kwargs)
@@ -1,219 +0,0 @@
import folder_paths
from impact.core import *
import os
import mmcv
from mmdet.apis import (inference_detector, init_detector)
from mmdet.evaluation import get_classes
def load_mmdet(model_path):
model_config = os.path.splitext(model_path)[0] + ".py"
model = init_detector(model_config, model_path, device="cpu")
return model
def inference_segm_old(model, image, conf_threshold):
image = image.numpy()[0] * 255
mmdet_results = inference_detector(model, image)
bbox_results, segm_results = mmdet_results
label = "A"
classes = get_classes("coco")
labels = [
np.full(bbox.shape[0], i, dtype=np.int32)
for i, bbox in enumerate(bbox_results)
]
n, m = bbox_results[0].shape
if n == 0:
return [[], [], []]
labels = np.concatenate(labels)
bboxes = np.vstack(bbox_results)
segms = mmcv.concat_list(segm_results)
filter_idxs = np.where(bboxes[:, -1] > conf_threshold)[0]
results = [[], [], []]
for i in filter_idxs:
results[0].append(label + "-" + classes[labels[i]])
results[1].append(bboxes[i])
results[2].append(segms[i])
return results
def inference_segm(image, modelname, conf_thres, lab="A"):
image = image.numpy()[0] * 255
mmdet_results = inference_detector(modelname, image).pred_instances
bboxes = mmdet_results.bboxes.numpy()
segms = mmdet_results.masks.numpy()
scores = mmdet_results.scores.numpy()
classes = get_classes("coco")
n, m = bboxes.shape
if n == 0:
return [[], [], [], []]
labels = mmdet_results.labels
filter_inds = np.where(mmdet_results.scores > conf_thres)[0]
results = [[], [], [], []]
for i in filter_inds:
results[0].append(lab + "-" + classes[labels[i]])
results[1].append(bboxes[i])
results[2].append(segms[i])
results[3].append(scores[i])
return results
def inference_bbox(modelname, image, conf_threshold):
image = image.numpy()[0] * 255
label = "A"
output = inference_detector(modelname, image).pred_instances
cv2_image = np.array(image)
cv2_image = cv2_image[:, :, ::-1].copy()
cv2_gray = cv2.cvtColor(cv2_image, cv2.COLOR_BGR2GRAY)
segms = []
for x0, y0, x1, y1 in output.bboxes:
cv2_mask = np.zeros(cv2_gray.shape, np.uint8)
cv2.rectangle(cv2_mask, (int(x0), int(y0)), (int(x1), int(y1)), 255, -1)
cv2_mask_bool = cv2_mask.astype(bool)
segms.append(cv2_mask_bool)
n, m = output.bboxes.shape
if n == 0:
return [[], [], [], []]
bboxes = output.bboxes.numpy()
scores = output.scores.numpy()
filter_idxs = np.where(scores > conf_threshold)[0]
results = [[], [], [], []]
for i in filter_idxs:
results[0].append(label)
results[1].append(bboxes[i])
results[2].append(segms[i])
results[3].append(scores[i])
return results
class BBoxDetector:
bbox_model = None
def __init__(self, bbox_model):
self.bbox_model = bbox_model
def detect(self, image, threshold, dilation, crop_factor, drop_size=1, detailer_hook=None):
drop_size = max(drop_size, 1)
mmdet_results = inference_bbox(self.bbox_model, image, threshold)
segmasks = create_segmasks(mmdet_results)
if dilation > 0:
segmasks = dilate_masks(segmasks, dilation)
items = []
h = image.shape[1]
w = image.shape[2]
for x in segmasks:
item_bbox = x[0]
item_mask = x[1]
y1, x1, y2, x2 = item_bbox
if x2 - x1 > drop_size and y2 - y1 > drop_size: # minimum dimension must be (2,2) to avoid squeeze issue
crop_region = make_crop_region(w, h, item_bbox, crop_factor)
cropped_image = crop_image(image, crop_region)
cropped_mask = crop_ndarray2(item_mask, crop_region)
confidence = x[2]
# bbox_size = (item_bbox[2]-item_bbox[0],item_bbox[3]-item_bbox[1]) # (w,h)
item = SEG(cropped_image, cropped_mask, confidence, crop_region, item_bbox, None, None)
items.append(item)
shape = image.shape[1], image.shape[2]
return shape, items
def detect_combined(self, image, threshold, dilation):
mmdet_results = inference_bbox(self.bbox_model, image, threshold)
segmasks = create_segmasks(mmdet_results)
if dilation > 0:
segmasks = dilate_masks(segmasks, dilation)
return combine_masks(segmasks)
def setAux(self, x):
pass
class SegmDetector(BBoxDetector):
segm_model = None
def __init__(self, segm_model):
self.segm_model = segm_model
def detect(self, image, threshold, dilation, crop_factor, drop_size=1, detailer_hook=None):
drop_size = max(drop_size, 1)
mmdet_results = inference_segm(image, self.segm_model, threshold)
segmasks = create_segmasks(mmdet_results)
if dilation > 0:
segmasks = dilate_masks(segmasks, dilation)
items = []
h = image.shape[1]
w = image.shape[2]
for x in segmasks:
item_bbox = x[0]
item_mask = x[1]
y1, x1, y2, x2 = item_bbox
if x2 - x1 > drop_size and y2 - y1 > drop_size: # minimum dimension must be (2,2) to avoid squeeze issue
crop_region = make_crop_region(w, h, item_bbox, crop_factor)
cropped_image = crop_image(image, crop_region)
cropped_mask = crop_ndarray2(item_mask, crop_region)
confidence = x[2]
item = SEG(cropped_image, cropped_mask, confidence, crop_region, item_bbox, None, None)
items.append(item)
segs = image.shape, items
if detailer_hook is not None and hasattr(detailer_hook, "post_detection"):
segs = detailer_hook.post_detection(segs)
return segs
def detect_combined(self, image, threshold, dilation):
mmdet_results = inference_bbox(self.bbox_model, image, threshold)
segmasks = create_segmasks(mmdet_results)
if dilation > 0:
segmasks = dilate_masks(segmasks, dilation)
return combine_masks(segmasks)
def setAux(self, x):
pass
class MMDetDetectorProvider:
@classmethod
def INPUT_TYPES(s):
bboxs = ["bbox/"+x for x in folder_paths.get_filename_list("mmdets_bbox")]
segms = ["segm/"+x for x in folder_paths.get_filename_list("mmdets_segm")]
return {"required": {"model_name": (bboxs + segms, )}}
RETURN_TYPES = ("BBOX_DETECTOR", "SEGM_DETECTOR")
FUNCTION = "load_mmdet"
CATEGORY = "ImpactPack"
def load_mmdet(self, model_name):
mmdet_path = folder_paths.get_full_path("mmdets", model_name)
model = load_mmdet(mmdet_path)
if model_name.startswith("bbox"):
return BBoxDetector(model), NO_SEGM_DETECTOR()
else:
return NO_BBOX_DETECTOR(), model
@@ -1,38 +0,0 @@
import impact.additional_dependencies
from impact.utils import *
impact.additional_dependencies.ensure_onnx_package()
try:
import onnxruntime
def onnx_inference(image, onnx_model):
# prepare image
pil = tensor2pil(image)
image = np.ascontiguousarray(pil)
image = image[:, :, ::-1] # to BGR image
image = image.astype(np.float32)
image -= [103.939, 116.779, 123.68] # 'caffe' mode image preprocessing
# do detection
onnx_model = onnxruntime.InferenceSession(onnx_model, providers=["CPUExecutionProvider"])
outputs = onnx_model.run(
[s_i.name for s_i in onnx_model.get_outputs()],
{onnx_model.get_inputs()[0].name: np.expand_dims(image, axis=0)},
)
labels = [op for op in outputs if op.dtype == "int32"][0]
scores = [op for op in outputs if isinstance(op[0][0], np.float32)][0]
boxes = [op for op in outputs if isinstance(op[0][0], np.ndarray)][0]
# filter-out useless item
idx = np.where(labels[0] == -1)[0][0]
labels = labels[0][:idx]
scores = scores[0][:idx]
boxes = boxes[0][:idx].astype(np.uint32)
return labels, scores, boxes
except Exception as e:
print("[ERROR] ComfyUI-Impact-Pack: 'onnxruntime' package doesn't support 'python 3.11', yet.")
print(f"\t{e}")
@@ -1,422 +0,0 @@
import folder_paths
import impact.wildcards
class ToDetailerPipe:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"model": ("MODEL",),
"clip": ("CLIP",),
"vae": ("VAE",),
"positive": ("CONDITIONING",),
"negative": ("CONDITIONING",),
"bbox_detector": ("BBOX_DETECTOR", ),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"], ),
},
"optional": {
"sam_model_opt": ("SAM_MODEL",),
"segm_detector_opt": ("SEGM_DETECTOR",),
"detailer_hook": ("DETAILER_HOOK",),
}}
RETURN_TYPES = ("DETAILER_PIPE", )
RETURN_NAMES = ("detailer_pipe", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, *args, **kwargs):
pipe = (kwargs['model'], kwargs['clip'], kwargs['vae'], kwargs['positive'], kwargs['negative'], kwargs['wildcard'], kwargs['bbox_detector'],
kwargs.get('segm_detector_opt', None), kwargs.get('sam_model_opt', None), kwargs.get('detailer_hook', None),
kwargs.get('refiner_model', None), kwargs.get('refiner_clip', None),
kwargs.get('refiner_positive', None), kwargs.get('refiner_negative', None))
return (pipe, )
class ToDetailerPipeSDXL(ToDetailerPipe):
@classmethod
def INPUT_TYPES(s):
return {"required": {
"model": ("MODEL",),
"clip": ("CLIP",),
"vae": ("VAE",),
"positive": ("CONDITIONING",),
"negative": ("CONDITIONING",),
"refiner_model": ("MODEL",),
"refiner_clip": ("CLIP",),
"refiner_positive": ("CONDITIONING",),
"refiner_negative": ("CONDITIONING",),
"bbox_detector": ("BBOX_DETECTOR", ),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
},
"optional": {
"sam_model_opt": ("SAM_MODEL",),
"segm_detector_opt": ("SEGM_DETECTOR",),
"detailer_hook": ("DETAILER_HOOK",),
}}
class FromDetailerPipe:
@classmethod
def INPUT_TYPES(s):
return {"required": {"detailer_pipe": ("DETAILER_PIPE",), }, }
RETURN_TYPES = ("MODEL", "CLIP", "VAE", "CONDITIONING", "CONDITIONING", "BBOX_DETECTOR", "SAM_MODEL", "SEGM_DETECTOR", "DETAILER_HOOK")
RETURN_NAMES = ("model", "clip", "vae", "positive", "negative", "bbox_detector", "sam_model_opt", "segm_detector_opt", "detailer_hook")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, detailer_pipe):
model, clip, vae, positive, negative, wildcard, bbox_detector, segm_detector_opt, sam_model_opt, detailer_hook, _, _, _, _ = detailer_pipe
return model, clip, vae, positive, negative, bbox_detector, sam_model_opt, segm_detector_opt, detailer_hook
class FromDetailerPipe_v2:
@classmethod
def INPUT_TYPES(s):
return {"required": {"detailer_pipe": ("DETAILER_PIPE",), }, }
RETURN_TYPES = ("DETAILER_PIPE", "MODEL", "CLIP", "VAE", "CONDITIONING", "CONDITIONING", "BBOX_DETECTOR", "SAM_MODEL", "SEGM_DETECTOR", "DETAILER_HOOK")
RETURN_NAMES = ("detailer_pipe", "model", "clip", "vae", "positive", "negative", "bbox_detector", "sam_model_opt", "segm_detector_opt", "detailer_hook")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, detailer_pipe):
model, clip, vae, positive, negative, wildcard, bbox_detector, segm_detector_opt, sam_model_opt, detailer_hook, _, _, _, _ = detailer_pipe
return detailer_pipe, model, clip, vae, positive, negative, bbox_detector, sam_model_opt, segm_detector_opt, detailer_hook
class FromDetailerPipe_SDXL:
@classmethod
def INPUT_TYPES(s):
return {"required": {"detailer_pipe": ("DETAILER_PIPE",), }, }
RETURN_TYPES = ("DETAILER_PIPE", "MODEL", "CLIP", "VAE", "CONDITIONING", "CONDITIONING", "BBOX_DETECTOR", "SAM_MODEL", "SEGM_DETECTOR", "DETAILER_HOOK", "MODEL", "CLIP", "CONDITIONING", "CONDITIONING")
RETURN_NAMES = ("detailer_pipe", "model", "clip", "vae", "positive", "negative", "bbox_detector", "sam_model_opt", "segm_detector_opt", "detailer_hook", "refiner_model", "refiner_clip", "refiner_positive", "refiner_negative")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, detailer_pipe):
model, clip, vae, positive, negative, wildcard, bbox_detector, segm_detector_opt, sam_model_opt, detailer_hook, refiner_model, refiner_clip, refiner_positive, refiner_negative = detailer_pipe
return detailer_pipe, model, clip, vae, positive, negative, bbox_detector, sam_model_opt, segm_detector_opt, detailer_hook, refiner_model, refiner_clip, refiner_positive, refiner_negative
class ToBasicPipe:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"model": ("MODEL",),
"clip": ("CLIP",),
"vae": ("VAE",),
"positive": ("CONDITIONING",),
"negative": ("CONDITIONING",),
},
}
RETURN_TYPES = ("BASIC_PIPE", )
RETURN_NAMES = ("basic_pipe", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, model, clip, vae, positive, negative):
pipe = (model, clip, vae, positive, negative)
return (pipe, )
class FromBasicPipe:
@classmethod
def INPUT_TYPES(s):
return {"required": {"basic_pipe": ("BASIC_PIPE",), }, }
RETURN_TYPES = ("MODEL", "CLIP", "VAE", "CONDITIONING", "CONDITIONING")
RETURN_NAMES = ("model", "clip", "vae", "positive", "negative")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, basic_pipe):
model, clip, vae, positive, negative = basic_pipe
return model, clip, vae, positive, negative
class FromBasicPipe_v2:
@classmethod
def INPUT_TYPES(s):
return {"required": {"basic_pipe": ("BASIC_PIPE",), }, }
RETURN_TYPES = ("BASIC_PIPE", "MODEL", "CLIP", "VAE", "CONDITIONING", "CONDITIONING")
RETURN_NAMES = ("basic_pipe", "model", "clip", "vae", "positive", "negative")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, basic_pipe):
model, clip, vae, positive, negative = basic_pipe
return basic_pipe, model, clip, vae, positive, negative
class BasicPipeToDetailerPipe:
@classmethod
def INPUT_TYPES(s):
return {"required": {"basic_pipe": ("BASIC_PIPE",),
"bbox_detector": ("BBOX_DETECTOR", ),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
},
"optional": {
"sam_model_opt": ("SAM_MODEL", ),
"segm_detector_opt": ("SEGM_DETECTOR",),
"detailer_hook": ("DETAILER_HOOK",),
},
}
RETURN_TYPES = ("DETAILER_PIPE", )
RETURN_NAMES = ("detailer_pipe", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, *args, **kwargs):
basic_pipe = kwargs['basic_pipe']
bbox_detector = kwargs['bbox_detector']
wildcard = kwargs['wildcard']
sam_model_opt = kwargs.get('sam_model_opt', None)
segm_detector_opt = kwargs.get('segm_detector_opt', None)
detailer_hook = kwargs.get('detailer_hook', None)
model, clip, vae, positive, negative = basic_pipe
pipe = model, clip, vae, positive, negative, wildcard, bbox_detector, segm_detector_opt, sam_model_opt, detailer_hook, None, None, None, None
return (pipe, )
class BasicPipeToDetailerPipeSDXL:
@classmethod
def INPUT_TYPES(s):
return {"required": {"base_basic_pipe": ("BASIC_PIPE",),
"refiner_basic_pipe": ("BASIC_PIPE",),
"bbox_detector": ("BBOX_DETECTOR", ),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
},
"optional": {
"sam_model_opt": ("SAM_MODEL", ),
"segm_detector_opt": ("SEGM_DETECTOR",),
"detailer_hook": ("DETAILER_HOOK",),
},
}
RETURN_TYPES = ("DETAILER_PIPE", )
RETURN_NAMES = ("detailer_pipe", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, *args, **kwargs):
base_basic_pipe = kwargs['base_basic_pipe']
refiner_basic_pipe = kwargs['refiner_basic_pipe']
bbox_detector = kwargs['bbox_detector']
wildcard = kwargs['wildcard']
sam_model_opt = kwargs.get('sam_model_opt', None)
segm_detector_opt = kwargs.get('segm_detector_opt', None)
detailer_hook = kwargs.get('detailer_hook', None)
model, clip, vae, positive, negative = base_basic_pipe
refiner_model, refiner_clip, refiner_vae, refiner_positive, refiner_negative = refiner_basic_pipe
pipe = model, clip, vae, positive, negative, wildcard, bbox_detector, segm_detector_opt, sam_model_opt, detailer_hook, refiner_model, refiner_clip, refiner_positive, refiner_negative
return (pipe, )
class DetailerPipeToBasicPipe:
@classmethod
def INPUT_TYPES(s):
return {"required": {"detailer_pipe": ("DETAILER_PIPE",), }}
RETURN_TYPES = ("BASIC_PIPE", "BASIC_PIPE")
RETURN_NAMES = ("base_basic_pipe", "refiner_basic_pipe")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, detailer_pipe):
model, clip, vae, positive, negative, _, _, _, _, _, refiner_model, refiner_clip, refiner_positive, refiner_negative = detailer_pipe
pipe = model, clip, vae, positive, negative
refiner_pipe = refiner_model, refiner_clip, vae, refiner_positive, refiner_negative
return (pipe, refiner_pipe)
class EditBasicPipe:
@classmethod
def INPUT_TYPES(s):
return {
"required": {"basic_pipe": ("BASIC_PIPE",), },
"optional": {
"model": ("MODEL",),
"clip": ("CLIP",),
"vae": ("VAE",),
"positive": ("CONDITIONING",),
"negative": ("CONDITIONING",),
},
}
RETURN_TYPES = ("BASIC_PIPE", )
RETURN_NAMES = ("basic_pipe", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, basic_pipe, model=None, clip=None, vae=None, positive=None, negative=None):
res_model, res_clip, res_vae, res_positive, res_negative = basic_pipe
if model is not None:
res_model = model
if clip is not None:
res_clip = clip
if vae is not None:
res_vae = vae
if positive is not None:
res_positive = positive
if negative is not None:
res_negative = negative
pipe = res_model, res_clip, res_vae, res_positive, res_negative
return (pipe, )
class EditDetailerPipe:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"detailer_pipe": ("DETAILER_PIPE",),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
},
"optional": {
"model": ("MODEL",),
"clip": ("CLIP",),
"vae": ("VAE",),
"positive": ("CONDITIONING",),
"negative": ("CONDITIONING",),
"bbox_detector": ("BBOX_DETECTOR",),
"sam_model": ("SAM_MODEL",),
"segm_detector": ("SEGM_DETECTOR",),
"detailer_hook": ("DETAILER_HOOK",),
},
}
RETURN_TYPES = ("DETAILER_PIPE",)
RETURN_NAMES = ("detailer_pipe",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Pipe"
def doit(self, *args, **kwargs):
detailer_pipe = kwargs['detailer_pipe']
wildcard = kwargs['wildcard']
model = kwargs.get('model', None)
clip = kwargs.get('clip', None)
vae = kwargs.get('vae', None)
positive = kwargs.get('positive', None)
negative = kwargs.get('negative', None)
bbox_detector = kwargs.get('bbox_detector', None)
sam_model = kwargs.get('sam_model', None)
segm_detector = kwargs.get('segm_detector', None)
detailer_hook = kwargs.get('detailer_hook', None)
refiner_model = kwargs.get('refiner_model', None)
refiner_clip = kwargs.get('refiner_clip', None)
refiner_positive = kwargs.get('refiner_positive', None)
refiner_negative = kwargs.get('refiner_negative', None)
res_model, res_clip, res_vae, res_positive, res_negative, res_wildcard, res_bbox_detector, res_segm_detector, res_sam_model, res_detailer_hook, res_refiner_model, res_refiner_clip, res_refiner_positive, res_refiner_negative = detailer_pipe
if model is not None:
res_model = model
if clip is not None:
res_clip = clip
if vae is not None:
res_vae = vae
if positive is not None:
res_positive = positive
if negative is not None:
res_negative = negative
if bbox_detector is not None:
res_bbox_detector = bbox_detector
if segm_detector is not None:
res_segm_detector = segm_detector
if wildcard != "":
res_wildcard = wildcard
if sam_model is not None:
res_sam_model = sam_model
if detailer_hook is not None:
res_detailer_hook = detailer_hook
if refiner_model is not None:
res_refiner_model = refiner_model
if refiner_clip is not None:
res_refiner_clip = refiner_clip
if refiner_positive is not None:
res_refiner_positive = refiner_positive
if refiner_negative is not None:
res_refiner_negative = refiner_negative
pipe = (res_model, res_clip, res_vae, res_positive, res_negative, res_wildcard,
res_bbox_detector, res_segm_detector, res_sam_model, res_detailer_hook,
res_refiner_model, res_refiner_clip, res_refiner_positive, res_refiner_negative)
return (pipe, )
class EditDetailerPipeSDXL(EditDetailerPipe):
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"detailer_pipe": ("DETAILER_PIPE",),
"wildcard": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"Select to add LoRA": (["Select the LoRA to add to the text"] + folder_paths.get_filename_list("loras"),),
"Select to add Wildcard": (["Select the Wildcard to add to the text"],),
},
"optional": {
"model": ("MODEL",),
"clip": ("CLIP",),
"vae": ("VAE",),
"positive": ("CONDITIONING",),
"negative": ("CONDITIONING",),
"refiner_model": ("MODEL",),
"refiner_clip": ("CLIP",),
"refiner_positive": ("CONDITIONING",),
"refiner_negative": ("CONDITIONING",),
"bbox_detector": ("BBOX_DETECTOR",),
"sam_model": ("SAM_MODEL",),
"segm_detector": ("SEGM_DETECTOR",),
"detailer_hook": ("DETAILER_HOOK",),
},
}
@@ -1,25 +0,0 @@
import comfy.sample
import traceback
original_sample = comfy.sample.sample
def informative_sample(*args, **kwargs):
try:
return original_sample(*args, **kwargs) # This code helps interpret error messages that occur within exceptions but does not have any impact on other operations.
except RuntimeError as e:
is_model_mix_issue = False
try:
if 'mat1 and mat2 shapes cannot be multiplied' in e.args[0]:
if 'torch.nn.functional.linear' in traceback.format_exc().strip().split('\n')[-3]:
is_model_mix_issue = True
except:
pass
if is_model_mix_issue:
raise RuntimeError("\n\n#### It seems that models and clips are mixed and interconnected between SDXL Base, SDXL Refiner, SD1.x, and SD2.x. Please verify. ####\n\n")
else:
raise e
comfy.sample.sample = informative_sample
@@ -1,598 +0,0 @@
import math
import impact.core as core
from impact.utils import *
from nodes import MAX_RESOLUTION
import nodes
from impact.impact_sampling import KSamplerWrapper, KSamplerAdvancedWrapper
class TiledKSamplerProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
"tile_width": ("INT", {"default": 512, "min": 320, "max": MAX_RESOLUTION, "step": 64}),
"tile_height": ("INT", {"default": 512, "min": 320, "max": MAX_RESOLUTION, "step": 64}),
"tiling_strategy": (["random", "padded", 'simple'], ),
"basic_pipe": ("BASIC_PIPE", )
}}
RETURN_TYPES = ("KSAMPLER",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Sampler"
def doit(self, seed, steps, cfg, sampler_name, scheduler, denoise,
tile_width, tile_height, tiling_strategy, basic_pipe):
model, _, _, positive, negative = basic_pipe
sampler = core.TiledKSamplerWrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise,
tile_width, tile_height, tiling_strategy)
return (sampler, )
class KSamplerProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
"basic_pipe": ("BASIC_PIPE", )
},
}
RETURN_TYPES = ("KSAMPLER",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Sampler"
def doit(self, seed, steps, cfg, sampler_name, scheduler, denoise, basic_pipe):
model, _, _, positive, negative = basic_pipe
sampler = KSamplerWrapper(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, denoise)
return (sampler, )
class KSamplerAdvancedProvider:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"sigma_factor": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}),
"basic_pipe": ("BASIC_PIPE", )
},
"optional": {
"sampler_opt": ("SAMPLER", )
}
}
RETURN_TYPES = ("KSAMPLER_ADVANCED",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Sampler"
def doit(self, cfg, sampler_name, scheduler, basic_pipe, sigma_factor=1.0, sampler_opt=None):
model, _, _, positive, negative = basic_pipe
sampler = KSamplerAdvancedWrapper(model, cfg, sampler_name, scheduler, positive, negative, sampler_opt=sampler_opt, sigma_factor=sigma_factor)
return (sampler, )
class TwoSamplersForMask:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"latent_image": ("LATENT", ),
"base_sampler": ("KSAMPLER", ),
"mask_sampler": ("KSAMPLER", ),
"mask": ("MASK", )
},
}
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Sampler"
def doit(self, latent_image, base_sampler, mask_sampler, mask):
inv_mask = torch.where(mask != 1.0, torch.tensor(1.0), torch.tensor(0.0))
latent_image['noise_mask'] = inv_mask
new_latent_image = base_sampler.sample(latent_image)
new_latent_image['noise_mask'] = mask
new_latent_image = mask_sampler.sample(new_latent_image)
del new_latent_image['noise_mask']
return (new_latent_image, )
class TwoAdvancedSamplersForMask:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
"samples": ("LATENT", ),
"base_sampler": ("KSAMPLER_ADVANCED", ),
"mask_sampler": ("KSAMPLER_ADVANCED", ),
"mask": ("MASK", ),
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000})
},
}
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Sampler"
@staticmethod
def mask_erosion(samples, mask, grow_mask_by):
mask = mask.clone()
w = samples['samples'].shape[3]
h = samples['samples'].shape[2]
mask2 = torch.nn.functional.interpolate(mask.reshape((-1, 1, mask.shape[-2], mask.shape[-1])), size=(w, h), mode="bilinear")
if grow_mask_by == 0:
mask_erosion = mask2
else:
kernel_tensor = torch.ones((1, 1, grow_mask_by, grow_mask_by))
padding = math.ceil((grow_mask_by - 1) / 2)
mask_erosion = torch.clamp(torch.nn.functional.conv2d(mask2.round(), kernel_tensor, padding=padding), 0, 1)
return mask_erosion[:, :, :w, :h].round()
def doit(self, seed, steps, denoise, samples, base_sampler, mask_sampler, mask, overlap_factor):
inv_mask = torch.where(mask != 1.0, torch.tensor(1.0), torch.tensor(0.0))
adv_steps = int(steps / denoise)
start_at_step = adv_steps - steps
new_latent_image = samples.copy()
mask_erosion = TwoAdvancedSamplersForMask.mask_erosion(samples, mask, overlap_factor)
for i in range(start_at_step, adv_steps):
add_noise = "enable" if i == start_at_step else "disable"
return_with_leftover_noise = "enable" if i+1 != adv_steps else "disable"
new_latent_image['noise_mask'] = inv_mask
new_latent_image = base_sampler.sample_advanced(add_noise, seed, adv_steps, new_latent_image, i, i + 1, "enable", recovery_mode="ratio additional")
new_latent_image['noise_mask'] = mask_erosion
new_latent_image = mask_sampler.sample_advanced("disable", seed, adv_steps, new_latent_image, i, i + 1, return_with_leftover_noise, recovery_mode="ratio additional")
del new_latent_image['noise_mask']
return (new_latent_image, )
class RegionalPrompt:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"mask": ("MASK", ),
"advanced_sampler": ("KSAMPLER_ADVANCED", ),
},
}
RETURN_TYPES = ("REGIONAL_PROMPTS", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Regional"
def doit(self, mask, advanced_sampler):
regional_prompt = core.REGIONAL_PROMPT(mask, advanced_sampler)
return ([regional_prompt], )
class CombineRegionalPrompts:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"regional_prompts1": ("REGIONAL_PROMPTS", ),
},
}
RETURN_TYPES = ("REGIONAL_PROMPTS", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Regional"
def doit(self, **kwargs):
res = []
for k, v in kwargs.items():
res += v
return (res, )
class CombineConditionings:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"conditioning1": ("CONDITIONING", ),
},
}
RETURN_TYPES = ("CONDITIONING", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, **kwargs):
res = []
for k, v in kwargs.items():
res += v
return (res, )
class ConcatConditionings:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"conditioning1": ("CONDITIONING", ),
},
}
RETURN_TYPES = ("CONDITIONING", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, **kwargs):
conditioning_to = list(kwargs.values())[0]
for k, conditioning_from in list(kwargs.items())[1:]:
out = []
if len(conditioning_from) > 1:
print("Warning: ConcatConditionings {k} contains more than 1 cond, only the first one will actually be applied to conditioning1.")
cond_from = conditioning_from[0][0]
for i in range(len(conditioning_to)):
t1 = conditioning_to[i][0]
tw = torch.cat((t1, cond_from), 1)
n = [tw, conditioning_to[i][1].copy()]
out.append(n)
conditioning_to = out
return (out, )
class RegionalSampler:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"seed_2nd": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"seed_2nd_mode": (["ignore", "fixed", "seed+seed_2nd", "seed-seed_2nd", "increment", "decrement", "randomize"], ),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"base_only_steps": ("INT", {"default": 2, "min": 0, "max": 10000}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
"samples": ("LATENT", ),
"base_sampler": ("KSAMPLER_ADVANCED", ),
"regional_prompts": ("REGIONAL_PROMPTS", ),
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000}),
"restore_latent": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
"additional_mode": (["DISABLE", "ratio additional", "ratio between"], {"default": "ratio between"}),
"additional_sampler": (["AUTO", "euler", "heun", "heunpp2", "dpm_2", "dpm_fast", "dpmpp_2m", "ddpm"],),
"additional_sigma_ratio": ("FLOAT", {"default": 0.3, "min": 0.0, "max": 1.0, "step": 0.01}),
},
"hidden": {"unique_id": "UNIQUE_ID"},
}
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Regional"
@staticmethod
def mask_erosion(samples, mask, grow_mask_by):
mask = mask.clone()
w = samples['samples'].shape[3]
h = samples['samples'].shape[2]
mask2 = torch.nn.functional.interpolate(mask.reshape((-1, 1, mask.shape[-2], mask.shape[-1])), size=(w, h), mode="bilinear")
if grow_mask_by == 0:
mask_erosion = mask2
else:
kernel_tensor = torch.ones((1, 1, grow_mask_by, grow_mask_by))
padding = math.ceil((grow_mask_by - 1) / 2)
mask_erosion = torch.clamp(torch.nn.functional.conv2d(mask2.round(), kernel_tensor, padding=padding), 0, 1)
return mask_erosion[:, :, :w, :h].round()
def doit(self, seed, seed_2nd, seed_2nd_mode, steps, base_only_steps, denoise, samples, base_sampler, regional_prompts, overlap_factor, restore_latent,
additional_mode, additional_sampler, additional_sigma_ratio, unique_id=None):
if restore_latent:
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
else:
latent_compositor = None
masks = [regional_prompt.mask.numpy() for regional_prompt in regional_prompts]
masks = [np.ceil(mask).astype(np.int32) for mask in masks]
combined_mask = torch.from_numpy(np.bitwise_or.reduce(masks))
inv_mask = torch.where(combined_mask == 0, torch.tensor(1.0), torch.tensor(0.0))
adv_steps = int(steps / denoise)
start_at_step = adv_steps - steps
region_len = len(regional_prompts)
total = steps*region_len
leftover_noise = False
if base_only_steps > 0:
if seed_2nd_mode == 'ignore':
leftover_noise = True
samples = base_sampler.sample_advanced(True, seed, adv_steps, samples, start_at_step, start_at_step + base_only_steps, leftover_noise, recovery_mode="DISABLE")
if seed_2nd_mode == "seed+seed_2nd":
seed += seed_2nd
if seed > 1125899906842624:
seed = seed - 1125899906842624
elif seed_2nd_mode == "seed-seed_2nd":
seed -= seed_2nd
if seed < 0:
seed += 1125899906842624
elif seed_2nd_mode != 'ignore':
seed = seed_2nd
new_latent_image = samples.copy()
base_latent_image = None
if not leftover_noise:
add_noise = True
else:
add_noise = False
for i in range(start_at_step+base_only_steps, adv_steps):
core.update_node_status(unique_id, f"{i}/{steps} steps | ", ((i-start_at_step)*region_len)/total)
new_latent_image['noise_mask'] = inv_mask
new_latent_image = base_sampler.sample_advanced(add_noise, seed, adv_steps, new_latent_image, i, i + 1, True,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
if restore_latent:
if 'noise_mask' in new_latent_image:
del new_latent_image['noise_mask']
base_latent_image = new_latent_image.copy()
j = 1
for regional_prompt in regional_prompts:
if restore_latent:
new_latent_image = base_latent_image.copy()
core.update_node_status(unique_id, f"{i}/{steps} steps | {j}/{region_len}", ((i-start_at_step)*region_len + j)/total)
region_mask = regional_prompt.get_mask_erosion(overlap_factor).squeeze(0).squeeze(0)
new_latent_image['noise_mask'] = region_mask
new_latent_image = regional_prompt.sampler.sample_advanced(False, seed, adv_steps, new_latent_image, i, i + 1, True,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
if restore_latent:
del new_latent_image['noise_mask']
base_latent_image = latent_compositor.composite(base_latent_image, new_latent_image, 0, 0, False, region_mask)[0]
new_latent_image = base_latent_image
j += 1
add_noise = False
# finalize
core.update_node_status(unique_id, f"finalize")
if base_latent_image is not None:
new_latent_image = base_latent_image
else:
base_latent_image = new_latent_image
new_latent_image['noise_mask'] = inv_mask
new_latent_image = base_sampler.sample_advanced(False, seed, adv_steps, new_latent_image, adv_steps, adv_steps+1, False,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
core.update_node_status(unique_id, f"{steps}/{steps} steps", total)
core.update_node_status(unique_id, "", None)
if restore_latent:
new_latent_image = base_latent_image
if 'noise_mask' in new_latent_image:
del new_latent_image['noise_mask']
return (new_latent_image, )
class RegionalSamplerAdvanced:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"add_noise": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
"noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"start_at_step": ("INT", {"default": 0, "min": 0, "max": 10000}),
"end_at_step": ("INT", {"default": 10000, "min": 0, "max": 10000}),
"overlap_factor": ("INT", {"default": 10, "min": 0, "max": 10000}),
"restore_latent": ("BOOLEAN", {"default": True, "label_on": "enabled", "label_off": "disabled"}),
"return_with_leftover_noise": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
"latent_image": ("LATENT", ),
"base_sampler": ("KSAMPLER_ADVANCED", ),
"regional_prompts": ("REGIONAL_PROMPTS", ),
"additional_mode": (["DISABLE", "ratio additional", "ratio between"], {"default": "ratio between"}),
"additional_sampler": (["AUTO", "euler", "heun", "heunpp2", "dpm_2", "dpm_fast", "dpmpp_2m", "ddpm"],),
"additional_sigma_ratio": ("FLOAT", {"default": 0.3, "min": 0.0, "max": 1.0, "step": 0.01}),
},
"hidden": {"unique_id": "UNIQUE_ID"},
}
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Regional"
def doit(self, add_noise, noise_seed, steps, start_at_step, end_at_step, overlap_factor, restore_latent, return_with_leftover_noise, latent_image, base_sampler, regional_prompts,
additional_mode, additional_sampler, additional_sigma_ratio, unique_id):
if restore_latent:
latent_compositor = nodes.NODE_CLASS_MAPPINGS['LatentCompositeMasked']()
else:
latent_compositor = None
masks = [regional_prompt.mask.numpy() for regional_prompt in regional_prompts]
masks = [np.ceil(mask).astype(np.int32) for mask in masks]
combined_mask = torch.from_numpy(np.bitwise_or.reduce(masks))
inv_mask = torch.where(combined_mask == 0, torch.tensor(1.0), torch.tensor(0.0))
region_len = len(regional_prompts)
end_at_step = min(steps, end_at_step)
total = (end_at_step - start_at_step) * region_len
new_latent_image = latent_image.copy()
base_latent_image = None
region_masks = {}
for i in range(start_at_step, end_at_step-1):
core.update_node_status(unique_id, f"{start_at_step+i}/{end_at_step} steps | ", ((i-start_at_step)*region_len)/total)
cur_add_noise = True if i == start_at_step and add_noise else False
new_latent_image['noise_mask'] = inv_mask
new_latent_image = base_sampler.sample_advanced(cur_add_noise, noise_seed, steps, new_latent_image, i, i + 1, True,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
if restore_latent:
del new_latent_image['noise_mask']
base_latent_image = new_latent_image.copy()
j = 1
for regional_prompt in regional_prompts:
if restore_latent:
new_latent_image = base_latent_image.copy()
core.update_node_status(unique_id, f"{start_at_step+i}/{end_at_step} steps | {j}/{region_len}", ((i-start_at_step)*region_len + j)/total)
if j not in region_masks:
region_mask = regional_prompt.get_mask_erosion(overlap_factor).squeeze(0).squeeze(0)
region_masks[j] = region_mask
else:
region_mask = region_masks[j]
new_latent_image['noise_mask'] = region_mask
new_latent_image = regional_prompt.sampler.sample_advanced(False, noise_seed, steps, new_latent_image, i, i + 1, True,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
if restore_latent:
del new_latent_image['noise_mask']
base_latent_image = latent_compositor.composite(base_latent_image, new_latent_image, 0, 0, False, region_mask)[0]
new_latent_image = base_latent_image
j += 1
# finalize
core.update_node_status(unique_id, f"finalize")
if base_latent_image is not None:
new_latent_image = base_latent_image
else:
base_latent_image = new_latent_image
new_latent_image['noise_mask'] = inv_mask
new_latent_image = base_sampler.sample_advanced(False, noise_seed, steps, new_latent_image, end_at_step-1, end_at_step, return_with_leftover_noise,
recovery_mode=additional_mode, recovery_sampler=additional_sampler, recovery_sigma_ratio=additional_sigma_ratio)
core.update_node_status(unique_id, f"{end_at_step}/{end_at_step} steps", total)
core.update_node_status(unique_id, "", None)
if restore_latent:
new_latent_image = base_latent_image
if 'noise_mask' in new_latent_image:
del new_latent_image['noise_mask']
return (new_latent_image, )
class KSamplerBasicPipe:
@classmethod
def INPUT_TYPES(s):
return {"required":
{"basic_pipe": ("BASIC_PIPE",),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"latent_image": ("LATENT", ),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
}
}
RETURN_TYPES = ("BASIC_PIPE", "LATENT", "VAE")
FUNCTION = "sample"
CATEGORY = "sampling"
def sample(self, basic_pipe, seed, steps, cfg, sampler_name, scheduler, latent_image, denoise=1.0):
model, clip, vae, positive, negative = basic_pipe
latent = nodes.KSampler().sample(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise)[0]
return basic_pipe, latent, vae
class KSamplerAdvancedBasicPipe:
@classmethod
def INPUT_TYPES(s):
return {"required":
{"basic_pipe": ("BASIC_PIPE",),
"add_noise": ("BOOLEAN", {"default": True, "label_on": "enable", "label_off": "disable"}),
"noise_seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"latent_image": ("LATENT", ),
"start_at_step": ("INT", {"default": 0, "min": 0, "max": 10000}),
"end_at_step": ("INT", {"default": 10000, "min": 0, "max": 10000}),
"return_with_leftover_noise": ("BOOLEAN", {"default": False, "label_on": "enable", "label_off": "disable"}),
}
}
RETURN_TYPES = ("BASIC_PIPE", "LATENT", "VAE")
FUNCTION = "sample"
CATEGORY = "sampling"
def sample(self, basic_pipe, add_noise, noise_seed, steps, cfg, sampler_name, scheduler, latent_image, start_at_step, end_at_step, return_with_leftover_noise, denoise=1.0):
model, clip, vae, positive, negative = basic_pipe
if add_noise:
add_noise = "enable"
else:
add_noise = "disable"
if return_with_leftover_noise:
return_with_leftover_noise = "enable"
else:
return_with_leftover_noise = "disable"
latent = nodes.KSamplerAdvanced().sample(model, add_noise, noise_seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, start_at_step, end_at_step, return_with_leftover_noise, denoise)[0]
return basic_pipe, latent, vae
@@ -1,487 +0,0 @@
from impact.utils import any_typ, ByPassTypeTuple, make_3d_mask
import comfy_extras.nodes_mask
from nodes import MAX_RESOLUTION
import torch
import comfy
import sys
import nodes
class GeneralSwitch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1}),
"sel_mode": ("BOOLEAN", {"default": True, "label_on": "select_on_prompt", "label_off": "select_on_execution", "forceInput": False}),
},
"optional": {
"input1": (any_typ,),
},
"hidden": {"unique_id": "UNIQUE_ID", "extra_pnginfo": "EXTRA_PNGINFO"}
}
RETURN_TYPES = (any_typ, "STRING", "INT")
RETURN_NAMES = ("selected_value", "selected_label", "selected_index")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, *args, **kwargs):
selected_index = int(kwargs['select'])
input_name = f"input{selected_index}"
selected_label = input_name
node_id = kwargs['unique_id']
nodelist = kwargs['extra_pnginfo']['workflow']['nodes']
for node in nodelist:
if str(node['id']) == node_id:
inputs = node['inputs']
for slot in inputs:
if slot['name'] == input_name and 'label' in slot:
selected_label = slot['label']
break
if input_name in kwargs:
return (kwargs[input_name], selected_label, selected_index)
else:
print(f"ImpactSwitch: invalid select index (ignored)")
return (None, "", selected_index)
class LatentSwitch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"select": ("INT", {"default": 1, "min": 1, "max": 99999, "step": 1}),
"latent1": ("LATENT",),
},
}
RETURN_TYPES = ("LATENT", )
OUTPUT_NODE = True
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, *args, **kwargs):
input_name = f"latent{int(kwargs['select'])}"
if input_name in kwargs:
return (kwargs[input_name],)
else:
print(f"LatentSwitch: invalid select index ('latent1' is selected)")
return (kwargs['latent1'],)
class ImageMaskSwitch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"select": ("INT", {"default": 1, "min": 1, "max": 4, "step": 1}),
"images1": ("IMAGE",),
},
"optional": {
"mask1_opt": ("MASK",),
"images2_opt": ("IMAGE",),
"mask2_opt": ("MASK",),
"images3_opt": ("IMAGE",),
"mask3_opt": ("MASK",),
"images4_opt": ("IMAGE",),
"mask4_opt": ("MASK",),
},
}
RETURN_TYPES = ("IMAGE", "MASK",)
OUTPUT_NODE = True
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, select, images1, mask1_opt=None, images2_opt=None, mask2_opt=None, images3_opt=None, mask3_opt=None,
images4_opt=None, mask4_opt=None):
if select == 1:
return images1, mask1_opt,
elif select == 2:
return images2_opt, mask2_opt,
elif select == 3:
return images3_opt, mask3_opt,
else:
return images4_opt, mask4_opt,
class GeneralInversedSwitch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1}),
"input": (any_typ,),
},
"hidden": {"unique_id": "UNIQUE_ID"},
}
RETURN_TYPES = ByPassTypeTuple((any_typ, ))
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, select, input, unique_id):
res = []
for i in range(0, select):
if select == i+1:
res.append(input)
else:
res.append(None)
return res
class RemoveNoiseMask:
@classmethod
def INPUT_TYPES(s):
return {"required": {"samples": ("LATENT",)}}
RETURN_TYPES = ("LATENT",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, samples):
res = {key: value for key, value in samples.items() if key != 'noise_mask'}
return (res, )
class ImagePasteMasked:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"destination": ("IMAGE",),
"source": ("IMAGE",),
"x": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}),
"y": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}),
"resize_source": ("BOOLEAN", {"default": False}),
},
"optional": {
"mask": ("MASK",),
}
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "composite"
CATEGORY = "image"
def composite(self, destination, source, x, y, resize_source, mask = None):
destination = destination.clone().movedim(-1, 1)
output = comfy_extras.nodes_mask.composite(destination, source.movedim(-1, 1), x, y, mask, 1, resize_source).movedim(1, -1)
return (output,)
from impact.utils import any_typ
class ImpactLogger:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"data": (any_typ, ""),
},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
CATEGORY = "ImpactPack/Debug"
OUTPUT_NODE = True
RETURN_TYPES = ()
FUNCTION = "doit"
def doit(self, data, prompt, extra_pnginfo):
shape = ""
if hasattr(data, "shape"):
shape = f"{data.shape} / "
print(f"[IMPACT LOGGER]: {shape}{data}")
print(f" PROMPT: {prompt}")
# for x in prompt:
# if 'inputs' in x and 'populated_text' in x['inputs']:
# print(f"PROMP: {x['10']['inputs']['populated_text']}")
#
# for x in extra_pnginfo['workflow']['nodes']:
# if x['type'] == 'ImpactWildcardProcessor':
# print(f" WV : {x['widgets_values'][1]}\n")
return {}
class ImpactDummyInput:
@classmethod
def INPUT_TYPES(s):
return {"required": {}}
CATEGORY = "ImpactPack/Debug"
RETURN_TYPES = (any_typ,)
FUNCTION = "doit"
def doit(self):
return ("DUMMY",)
class MasksToMaskList:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"masks": ("MASK", ),
}
}
RETURN_TYPES = ("MASK", )
OUTPUT_IS_LIST = (True, )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Operation"
def doit(self, masks):
if masks is None:
empty_mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu")
return ([empty_mask], )
res = []
for mask in masks:
res.append(mask)
print(f"mask len: {len(res)}")
res = [make_3d_mask(x) for x in res]
return (res, )
class MaskListToMaskBatch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"mask": ("MASK", ),
}
}
INPUT_IS_LIST = True
RETURN_TYPES = ("MASK", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Operation"
def doit(self, mask):
if len(mask) == 1:
mask = make_3d_mask(mask[0])
return (mask,)
elif len(mask) > 1:
mask1 = make_3d_mask(mask[0])
for mask2 in mask[1:]:
mask2 = make_3d_mask(mask2)
if mask1.shape[1:] != mask2.shape[1:]:
mask2 = comfy.utils.common_upscale(mask2.movedim(-1, 1), mask1.shape[2], mask1.shape[1], "lanczos", "center").movedim(1, -1)
mask1 = torch.cat((mask1, mask2), dim=0)
return (mask1,)
else:
empty_mask = torch.zeros((1, 64, 64), dtype=torch.float32, device="cpu").unsqueeze(0)
return (empty_mask,)
class ImageListToImageBatch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"images": ("IMAGE", ),
}
}
INPUT_IS_LIST = True
RETURN_TYPES = ("IMAGE", )
FUNCTION = "doit"
CATEGORY = "ImpactPack/Operation"
def doit(self, images):
if len(images) <= 1:
return (images,)
else:
image1 = images[0]
for image2 in images[1:]:
if image1.shape[1:] != image2.shape[1:]:
image2 = comfy.utils.common_upscale(image2.movedim(-1, 1), image1.shape[2], image1.shape[1], "lanczos", "center").movedim(1, -1)
image1 = torch.cat((image1, image2), dim=0)
return (image1,)
class ImageBatchToImageList:
@classmethod
def INPUT_TYPES(s):
return {"required": {"image": ("IMAGE",), }}
RETURN_TYPES = ("IMAGE",)
OUTPUT_IS_LIST = (True,)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, image):
images = [image[i:i + 1, ...] for i in range(image.shape[0])]
return (images, )
class MakeImageList:
@classmethod
def INPUT_TYPES(s):
return {"required": {"image1": ("IMAGE",), }}
RETURN_TYPES = ("IMAGE",)
OUTPUT_IS_LIST = (True,)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, **kwargs):
images = []
for k, v in kwargs.items():
images.append(v)
return (images, )
class MakeImageBatch:
@classmethod
def INPUT_TYPES(s):
return {"required": {"image1": ("IMAGE",), }}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, **kwargs):
image1 = kwargs['image1']
del kwargs['image1']
images = [value for value in kwargs.values()]
if len(images) == 0:
return (image1,)
else:
for image2 in images:
if image1.shape[1:] != image2.shape[1:]:
image2 = comfy.utils.common_upscale(image2.movedim(-1, 1), image1.shape[2], image1.shape[1], "lanczos", "center").movedim(1, -1)
image1 = torch.cat((image1, image2), dim=0)
return (image1,)
class ReencodeLatent:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"samples": ("LATENT", ),
"tile_mode": (["None", "Both", "Decode(input) only", "Encode(output) only"],),
"input_vae": ("VAE", ),
"output_vae": ("VAE", ),
"tile_size": ("INT", {"default": 512, "min": 320, "max": 4096, "step": 64}),
},
}
CATEGORY = "ImpactPack/Util"
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
def doit(self, samples, tile_mode, input_vae, output_vae, tile_size=512):
if tile_mode in ["Both", "Decode(input) only"]:
pixels = nodes.VAEDecodeTiled().decode(input_vae, samples, tile_size)[0]
else:
pixels = nodes.VAEDecode().decode(input_vae, samples)[0]
if tile_mode in ["Both", "Encode(output) only"]:
return nodes.VAEEncodeTiled().encode(output_vae, pixels, tile_size)
else:
return nodes.VAEEncode().encode(output_vae, pixels)
class ReencodeLatentPipe:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"samples": ("LATENT", ),
"tile_mode": (["None", "Both", "Decode(input) only", "Encode(output) only"],),
"input_basic_pipe": ("BASIC_PIPE", ),
"output_basic_pipe": ("BASIC_PIPE", ),
},
}
CATEGORY = "ImpactPack/Util"
RETURN_TYPES = ("LATENT", )
FUNCTION = "doit"
def doit(self, samples, tile_mode, input_basic_pipe, output_basic_pipe):
_, _, input_vae, _, _ = input_basic_pipe
_, _, output_vae, _, _ = output_basic_pipe
return ReencodeLatent().doit(samples, tile_mode, input_vae, output_vae)
class StringSelector:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"strings": ("STRING", {"multiline": True}),
"multiline": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}),
"select": ("INT", {"min": 0, "max": sys.maxsize, "step": 1, "default": 0}),
}}
RETURN_TYPES = ("STRING",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, strings, multiline, select):
lines = strings.split('\n')
if multiline:
result = []
current_string = ""
for line in lines:
if line.startswith("#"):
if current_string:
result.append(current_string.strip())
current_string = ""
current_string += line + "\n"
if current_string:
result.append(current_string.strip())
if len(result) == 0:
selected = strings
else:
selected = result[select % len(result)]
if selected.startswith('#'):
selected = selected[1:]
else:
if len(lines) == 0:
selected = strings
else:
selected = lines[select % len(lines)]
return (selected, )
@@ -1,625 +0,0 @@
import torch
import torchvision
import cv2
import numpy as np
import folder_paths
import nodes
from . import config
from PIL import Image, ImageFilter
from scipy.ndimage import zoom
import comfy
class TensorBatchBuilder:
def __init__(self):
self.tensor = None
def concat(self, new_tensor):
if self.tensor is None:
self.tensor = new_tensor
else:
self.tensor = torch.concat((self.tensor, new_tensor), dim=0)
def tensor_convert_rgba(image, prefer_copy=True):
"""Assumes NHWC format tensor with 1, 3 or 4 channels."""
_tensor_check_image(image)
n_channel = image.shape[-1]
if n_channel == 4:
return image
if n_channel == 3:
alpha = torch.ones((*image.shape[:-1], 1))
return torch.cat((image, alpha), axis=-1)
if n_channel == 1:
if prefer_copy:
image = image.repeat(1, -1, -1, 4)
else:
image = image.expand(1, -1, -1, 3)
return image
# NOTE: Similar error message as in PIL, for easier googling :P
raise ValueError(f"illegal conversion (channels: {n_channel} -> 4)")
def tensor_convert_rgb(image, prefer_copy=True):
"""Assumes NHWC format tensor with 1, 3 or 4 channels."""
_tensor_check_image(image)
n_channel = image.shape[-1]
if n_channel == 3:
return image
if n_channel == 4:
image = image[..., :3]
if prefer_copy:
image = image.copy()
return image
if n_channel == 1:
if prefer_copy:
image = image.repeat(1, -1, -1, 4)
else:
image = image.expand(1, -1, -1, 3)
return image
# NOTE: Same error message as in PIL, for easier googling :P
raise ValueError(f"illegal conversion (channels: {n_channel} -> 3)")
def general_tensor_resize(image, w: int, h: int):
_tensor_check_image(image)
image = image.permute(0, 3, 1, 2)
image = torch.nn.functional.interpolate(image, size=(h, w), mode="bilinear")
image = image.permute(0, 2, 3, 1)
return image
# TODO: Sadly, we need LANCZOS
LANCZOS = (Image.Resampling.LANCZOS if hasattr(Image, 'Resampling') else Image.LANCZOS)
def tensor_resize(image, w: int, h: int):
_tensor_check_image(image)
if image.shape[3] >= 3:
scaled_images = TensorBatchBuilder()
for single_image in image:
single_image = single_image.unsqueeze(0)
single_pil = tensor2pil(single_image)
scaled_pil = single_pil.resize((w, h), resample=LANCZOS)
single_image = pil2tensor(scaled_pil)
scaled_images.concat(single_image)
return scaled_images.tensor
else:
return general_tensor_resize(image, w, h)
def tensor_get_size(image):
"""Mimicking `PIL.Image.size`"""
_tensor_check_image(image)
_, h, w, _ = image.shape
return (w, h)
def tensor2pil(image):
_tensor_check_image(image)
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(0), 0, 255).astype(np.uint8))
def pil2tensor(image):
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)
def numpy2pil(image):
return Image.fromarray(np.clip(255. * image.squeeze(0), 0, 255).astype(np.uint8))
def to_pil(image):
if isinstance(image, Image.Image):
return image
if isinstance(image, torch.Tensor):
return tensor2pil(image)
if isinstance(image, np.ndarray):
return numpy2pil(image)
raise ValueError(f"Cannot convert {type(image)} to PIL.Image")
def to_tensor(image):
if isinstance(image, Image.Image):
return torch.from_numpy(np.array(image))
if isinstance(image, torch.Tensor):
return image
if isinstance(image, np.ndarray):
return torch.from_numpy(image)
raise ValueError(f"Cannot convert {type(image)} to torch.Tensor")
def to_numpy(image):
if isinstance(image, Image.Image):
return np.array(image)
if isinstance(image, torch.Tensor):
return image.numpy()
if isinstance(image, np.ndarray):
return image
raise ValueError(f"Cannot convert {type(image)} to numpy.ndarray")
def tensor_putalpha(image, mask):
_tensor_check_image(image)
_tensor_check_mask(mask)
image[..., -1] = mask[..., 0]
def _tensor_check_image(image):
if image.ndim != 4:
raise ValueError(f"Expected NHWC tensor, but found {image.ndim} dimensions")
if image.shape[-1] not in (1, 3, 4):
raise ValueError(f"Expected 1, 3 or 4 channels for image, but found {image.shape[-1]} channels")
return
def _tensor_check_mask(mask):
if mask.ndim != 4:
raise ValueError(f"Expected NHWC tensor, but found {mask.ndim} dimensions")
if mask.shape[-1] != 1:
raise ValueError(f"Expected 1 channel for mask, but found {mask.shape[-1]} channels")
return
def tensor_crop(image, crop_region):
_tensor_check_image(image)
return crop_ndarray4(image, crop_region)
def tensor2numpy(image):
_tensor_check_image(image)
return image.numpy()
def tensor_paste(image1, image2, left_top, mask):
"""Mask and image2 has to be the same size"""
_tensor_check_image(image1)
_tensor_check_image(image2)
_tensor_check_mask(mask)
if image2.shape[1:3] != mask.shape[1:3]:
raise ValueError(f"Inconsistent size: Image ({image2.shape[1:3]}) != Mask ({mask.shape[1:3]})")
x, y = left_top
_, h1, w1, _ = image1.shape
_, h2, w2, _ = image2.shape
# calculate image patch size
w = min(w1, x + w2) - x
h = min(h1, y + h2) - y
# If the patch is out of bound, nothing to do!
if w <= 0 or h <= 0:
return
mask = mask[:, :h, :w, :]
image1[:, y:y+h, x:x+w, :] = (
(1 - mask) * image1[:, y:y+h, x:x+w, :] +
mask * image2[:, :h, :w, :]
)
return
def center_of_bbox(bbox):
w, h = bbox[2] - bbox[0], bbox[3] - bbox[1]
return bbox[0] + w/2, bbox[1] + h/2
def combine_masks(masks):
if len(masks) == 0:
return None
else:
initial_cv2_mask = np.array(masks[0][1])
combined_cv2_mask = initial_cv2_mask
for i in range(1, len(masks)):
cv2_mask = np.array(masks[i][1])
if combined_cv2_mask.shape == cv2_mask.shape:
combined_cv2_mask = cv2.bitwise_or(combined_cv2_mask, cv2_mask)
else:
# do nothing - incompatible mask
pass
mask = torch.from_numpy(combined_cv2_mask)
return mask
def combine_masks2(masks):
if len(masks) == 0:
return None
else:
initial_cv2_mask = np.array(masks[0]).astype(np.uint8)
combined_cv2_mask = initial_cv2_mask
for i in range(1, len(masks)):
cv2_mask = np.array(masks[i]).astype(np.uint8)
if combined_cv2_mask.shape == cv2_mask.shape:
combined_cv2_mask = cv2.bitwise_or(combined_cv2_mask, cv2_mask)
else:
# do nothing - incompatible mask
pass
mask = torch.from_numpy(combined_cv2_mask)
return mask
def bitwise_and_masks(mask1, mask2):
mask1 = mask1.cpu()
mask2 = mask2.cpu()
cv2_mask1 = np.array(mask1)
cv2_mask2 = np.array(mask2)
if cv2_mask1.shape == cv2_mask2.shape:
cv2_mask = cv2.bitwise_and(cv2_mask1, cv2_mask2)
return torch.from_numpy(cv2_mask)
else:
# do nothing - incompatible mask shape: mostly empty mask
return mask1
def to_binary_mask(mask, threshold=0):
mask = make_3d_mask(mask)
mask = mask.clone().cpu()
mask[mask > threshold] = 1.
mask[mask <= threshold] = 0.
return mask
def use_gpu_opencv():
return not config.get_config()['disable_gpu_opencv']
def dilate_mask(mask, dilation_factor, iter=1):
if dilation_factor == 0:
return make_2d_mask(mask)
mask = make_2d_mask(mask)
kernel = np.ones((abs(dilation_factor), abs(dilation_factor)), np.uint8)
if use_gpu_opencv():
mask = cv2.UMat(mask)
kernel = cv2.UMat(kernel)
if dilation_factor > 0:
result = cv2.dilate(mask, kernel, iter)
else:
result = cv2.erode(mask, kernel, iter)
if use_gpu_opencv():
return result.get()
else:
return result
def dilate_masks(segmasks, dilation_factor, iter=1):
if dilation_factor == 0:
return segmasks
dilated_masks = []
kernel = np.ones((abs(dilation_factor), abs(dilation_factor)), np.uint8)
if use_gpu_opencv():
kernel = cv2.UMat(kernel)
for i in range(len(segmasks)):
cv2_mask = segmasks[i][1]
if use_gpu_opencv():
cv2_mask = cv2.UMat(cv2_mask)
if dilation_factor > 0:
dilated_mask = cv2.dilate(cv2_mask, kernel, iter)
else:
dilated_mask = cv2.erode(cv2_mask, kernel, iter)
if use_gpu_opencv():
dilated_mask = dilated_mask.get()
item = (segmasks[i][0], dilated_mask, segmasks[i][2])
dilated_masks.append(item)
return dilated_masks
import torch.nn.functional as F
def feather_mask(mask, thickness):
mask = mask.permute(0, 3, 1, 2)
# Gaussian kernel for blurring
kernel_size = 2 * int(thickness) + 1
sigma = thickness / 3 # Adjust the sigma value as needed
blur_kernel = _gaussian_kernel(kernel_size, sigma).to(mask.device, mask.dtype)
# Apply blur to the mask
blurred_mask = F.conv2d(mask, blur_kernel.unsqueeze(0).unsqueeze(0), padding=thickness)
blurred_mask = blurred_mask.permute(0, 2, 3, 1)
return blurred_mask
def _gaussian_kernel(kernel_size, sigma):
# Generate a 1D Gaussian kernel
kernel = torch.exp(-(torch.arange(kernel_size) - kernel_size // 2)**2 / (2 * sigma**2))
return kernel / kernel.sum()
def tensor_gaussian_blur_mask(mask, kernel_size, sigma=10.0):
"""Return NHWC torch.Tenser from ndim == 2 or 4 `np.ndarray` or `torch.Tensor`"""
if isinstance(mask, np.ndarray):
mask = torch.from_numpy(mask)
if mask.ndim == 2:
mask = mask[None, ..., None]
elif mask.ndim == 3:
mask = mask[..., None]
_tensor_check_mask(mask)
if kernel_size <= 0:
return mask
kernel_size = kernel_size*2+1
shortest = min(mask.shape[1], mask.shape[2])
if shortest <= kernel_size:
kernel_size = int(shortest/2)
if kernel_size % 2 == 0:
kernel_size += 1
if kernel_size < 3:
return mask # skip feathering
prev_device = mask.device
device = comfy.model_management.get_torch_device()
mask.to(device)
# apply gaussian blur
mask = mask[:, None, ..., 0]
blurred_mask = torchvision.transforms.GaussianBlur(kernel_size=kernel_size, sigma=sigma)(mask)
blurred_mask = blurred_mask[:, 0, ..., None]
blurred_mask.to(prev_device)
return blurred_mask
def subtract_masks(mask1, mask2):
mask1 = mask1.cpu()
mask2 = mask2.cpu()
cv2_mask1 = np.array(mask1) * 255
cv2_mask2 = np.array(mask2) * 255
if cv2_mask1.shape == cv2_mask2.shape:
cv2_mask = cv2.subtract(cv2_mask1, cv2_mask2)
return torch.clamp(torch.from_numpy(cv2_mask) / 255.0, min=0, max=1)
else:
# do nothing - incompatible mask shape: mostly empty mask
return mask1
def add_masks(mask1, mask2):
mask1 = mask1.cpu()
mask2 = mask2.cpu()
cv2_mask1 = np.array(mask1) * 255
cv2_mask2 = np.array(mask2) * 255
if cv2_mask1.shape == cv2_mask2.shape:
cv2_mask = cv2.add(cv2_mask1, cv2_mask2)
return torch.clamp(torch.from_numpy(cv2_mask) / 255.0, min=0, max=1)
else:
# do nothing - incompatible mask shape: mostly empty mask
return mask1
def normalize_region(limit, startp, size):
if startp < 0:
new_endp = min(limit, size)
new_startp = 0
elif startp + size > limit:
new_startp = max(0, limit - size)
new_endp = limit
else:
new_startp = startp
new_endp = min(limit, startp+size)
return int(new_startp), int(new_endp)
def make_crop_region(w, h, bbox, crop_factor, crop_min_size=None):
x1 = bbox[0]
y1 = bbox[1]
x2 = bbox[2]
y2 = bbox[3]
bbox_w = x2 - x1
bbox_h = y2 - y1
crop_w = bbox_w * crop_factor
crop_h = bbox_h * crop_factor
if crop_min_size is not None:
crop_w = max(crop_min_size, crop_w)
crop_h = max(crop_min_size, crop_h)
kernel_x = x1 + bbox_w / 2
kernel_y = y1 + bbox_h / 2
new_x1 = int(kernel_x - crop_w / 2)
new_y1 = int(kernel_y - crop_h / 2)
# make sure position in (w,h)
new_x1, new_x2 = normalize_region(w, new_x1, crop_w)
new_y1, new_y2 = normalize_region(h, new_y1, crop_h)
return [new_x1, new_y1, new_x2, new_y2]
def crop_ndarray4(npimg, crop_region):
x1 = crop_region[0]
y1 = crop_region[1]
x2 = crop_region[2]
y2 = crop_region[3]
cropped = npimg[:, y1:y2, x1:x2, :]
return cropped
crop_tensor4 = crop_ndarray4
def crop_ndarray2(npimg, crop_region):
x1 = crop_region[0]
y1 = crop_region[1]
x2 = crop_region[2]
y2 = crop_region[3]
cropped = npimg[y1:y2, x1:x2]
return cropped
def crop_image(image, crop_region):
return crop_tensor4(image, crop_region)
def to_latent_image(pixels, vae):
x = pixels.shape[1]
y = pixels.shape[2]
if pixels.shape[1] != x or pixels.shape[2] != y:
pixels = pixels[:, :x, :y, :]
vae_encode = nodes.VAEEncode()
if hasattr(nodes.VAEEncode, "vae_encode_crop_pixels"):
# backward compatibility
print(f"[Impact Pack] ComfyUI is outdated.")
pixels = nodes.VAEEncode.vae_encode_crop_pixels(pixels)
t = vae.encode(pixels[:, :, :, :3])
return {"samples": t}
return vae_encode.encode(vae, pixels)[0]
def empty_pil_tensor(w=64, h=64):
return torch.zeros((1, h, w, 3), dtype=torch.float32)
def make_2d_mask(mask):
if len(mask.shape) == 4:
return mask.squeeze(0).squeeze(0)
elif len(mask.shape) == 3:
return mask.squeeze(0)
return mask
def make_3d_mask(mask):
if len(mask.shape) == 4:
return mask.squeeze(0)
elif len(mask.shape) == 2:
return mask.unsqueeze(0)
return mask
def is_same_device(a, b):
a_device = torch.device(a) if isinstance(a, str) else a
b_device = torch.device(b) if isinstance(b, str) else b
return a_device.type == b_device.type and a_device.index == b_device.index
def collect_non_reroute_nodes(node_map, links, res, node_id):
if node_map[node_id]['type'] != 'Reroute' and node_map[node_id]['type'] != 'Reroute (rgthree)':
res.append(node_id)
else:
for link in node_map[node_id]['outputs'][0]['links']:
next_node_id = str(links[link][2])
collect_non_reroute_nodes(node_map, links, res, next_node_id)
from torchvision.transforms.functional import to_pil_image
def resize_mask(mask, size):
resized_mask = torch.nn.functional.interpolate(mask.unsqueeze(0), size=size, mode='bilinear', align_corners=False)
return resized_mask.squeeze(0)
def apply_mask_alpha_to_pil(decoded_pil, mask):
decoded_rgba = decoded_pil.convert('RGBA')
mask_pil = to_pil_image(mask)
decoded_rgba.putalpha(mask_pil)
return decoded_rgba
def try_install_custom_node(custom_node_url, msg):
try:
import cm_global
cm_global.try_call(api='cm.try-install-custom-node',
sender="Impact Pack", custom_node_url=custom_node_url, msg=msg)
except Exception:
print(msg)
print(f"[Impact Pack] ComfyUI-Manager is outdated. The custom node installation feature is not available.")
# author: Trung0246 --->
class TautologyStr(str):
def __ne__(self, other):
return False
class ByPassTypeTuple(tuple):
def __getitem__(self, index):
if index > 0:
index = 0
item = super().__getitem__(index)
if isinstance(item, str):
return TautologyStr(item)
return item
class NonListIterable:
def __init__(self, data):
self.data = data
def __getitem__(self, index):
return self.data[index]
def add_folder_path_and_extensions(folder_name, full_folder_paths, extensions):
# Iterate over the list of full folder paths
for full_folder_path in full_folder_paths:
# Use the provided function to add each model folder path
folder_paths.add_model_folder_path(folder_name, full_folder_path)
# Now handle the extensions. If the folder name already exists, update the extensions
if folder_name in folder_paths.folder_names_and_paths:
# Unpack the current paths and extensions
current_paths, current_extensions = folder_paths.folder_names_and_paths[folder_name]
# Update the extensions set with the new extensions
updated_extensions = current_extensions | extensions
# Reassign the updated tuple back to the dictionary
folder_paths.folder_names_and_paths[folder_name] = (current_paths, updated_extensions)
else:
# If the folder name was not present, add_model_folder_path would have added it with the last path
# Now we just need to update the set of extensions as it would be an empty set
# Also ensure that all paths are included (since add_model_folder_path adds only one path at a time)
folder_paths.folder_names_and_paths[folder_name] = (full_folder_paths, extensions)
# <---
# wildcard trick is taken from pythongossss's
class AnyType(str):
def __ne__(self, __value: object) -> bool:
return False
any_typ = AnyType("*")
@@ -1,452 +0,0 @@
import re
import random
import os
import nodes
import folder_paths
import yaml
import numpy as np
import threading
from impact import utils
wildcard_lock = threading.Lock()
wildcard_dict = {}
def get_wildcard_list():
with wildcard_lock:
return [f"__{x}__" for x in wildcard_dict.keys()]
def get_wildcard_dict():
global wildcard_dict
with wildcard_lock:
return wildcard_dict
def wildcard_normalize(x):
return x.replace("\\", "/").lower()
def read_wildcard(k, v):
if isinstance(v, list):
k = wildcard_normalize(k)
wildcard_dict[k] = v
elif isinstance(v, dict):
for k2, v2 in v.items():
new_key = f"{k}/{k2}"
new_key = wildcard_normalize(new_key)
read_wildcard(new_key, v2)
def read_wildcard_dict(wildcard_path):
global wildcard_dict
for root, directories, files in os.walk(wildcard_path, followlinks=True):
for file in files:
if file.endswith('.txt'):
file_path = os.path.join(root, file)
rel_path = os.path.relpath(file_path, wildcard_path)
key = os.path.splitext(rel_path)[0].replace('\\', '/').lower()
try:
with open(file_path, 'r', encoding="ISO-8859-1") as f:
lines = f.read().splitlines()
wildcard_dict[key] = lines
except UnicodeDecodeError:
with open(file_path, 'r', encoding="UTF-8", errors="ignore") as f:
lines = f.read().splitlines()
wildcard_dict[key] = lines
elif file.endswith('.yaml'):
file_path = os.path.join(root, file)
with open(file_path, 'r') as f:
yaml_data = yaml.load(f, Loader=yaml.FullLoader)
for k, v in yaml_data.items():
read_wildcard(k, v)
return wildcard_dict
def process(text, seed=None):
if seed is not None:
random.seed(seed)
random_gen = np.random.default_rng(seed)
def replace_options(string):
replacements_found = False
def replace_option(match):
nonlocal replacements_found
options = match.group(1).split('|')
multi_select_pattern = options[0].split('$$')
select_range = None
select_sep = ' '
range_pattern = r'(\d+)(-(\d+))?'
range_pattern2 = r'-(\d+)'
if len(multi_select_pattern) > 1:
r = re.match(range_pattern, options[0])
if r is None:
r = re.match(range_pattern2, options[0])
a = '1'
b = r.group(1).strip()
else:
a = r.group(1).strip()
b = r.group(3)
if b is not None:
b = b.strip()
if r is not None:
if b is not None and is_numeric_string(a) and is_numeric_string(b):
# PATTERN: num1-num2
select_range = int(a), int(b)
elif is_numeric_string(a):
# PATTERN: num
x = int(a)
select_range = (x, x)
if select_range is not None and len(multi_select_pattern) == 2:
# PATTERN: count$$
options[0] = multi_select_pattern[1]
elif select_range is not None and len(multi_select_pattern) == 3:
# PATTERN: count$$ sep $$
select_sep = multi_select_pattern[1]
options[0] = multi_select_pattern[2]
adjusted_probabilities = []
total_prob = 0
for option in options:
parts = option.split('::', 1)
if len(parts) == 2 and is_numeric_string(parts[0].strip()):
config_value = float(parts[0].strip())
else:
config_value = 1 # Default value if no configuration is provided
adjusted_probabilities.append(config_value)
total_prob += config_value
normalized_probabilities = [prob / total_prob for prob in adjusted_probabilities]
if select_range is None:
select_count = 1
else:
select_count = random_gen.integers(low=select_range[0], high=select_range[1]+1, size=1)
if select_count > len(options):
random_gen.shuffle(options)
selected_items = options
else:
selected_items = random_gen.choice(options, p=normalized_probabilities, size=select_count, replace=False)
selected_items2 = [re.sub(r'^\s*[0-9.]+::', '', x, 1) for x in selected_items]
replacement = select_sep.join(selected_items2)
if '::' in replacement:
pass
replacements_found = True
return replacement
pattern = r'{([^{}]*?)}'
replaced_string = re.sub(pattern, replace_option, string)
return replaced_string, replacements_found
def replace_wildcard(string):
local_wildcard_dict = get_wildcard_dict()
pattern = r"__([\w.\-+/*\\]+)__"
matches = re.findall(pattern, string)
replacements_found = False
for match in matches:
keyword = match.lower()
keyword = wildcard_normalize(keyword)
if keyword in local_wildcard_dict:
replacement = random_gen.choice(local_wildcard_dict[keyword])
replacements_found = True
string = string.replace(f"__{match}__", replacement, 1)
elif '*' in keyword:
subpattern = keyword.replace('*', '.*').replace('+','\+')
total_patterns = []
found = False
for k, v in local_wildcard_dict.items():
if re.match(subpattern, k) is not None:
total_patterns += v
found = True
if found:
replacement = random_gen.choice(total_patterns)
replacements_found = True
string = string.replace(f"__{match}__", replacement, 1)
elif '/' not in keyword:
string_fallback = string.replace(f"__{match}__", f"__*/{match}__", 1)
string, replacements_found = replace_wildcard(string_fallback)
return string, replacements_found
replace_depth = 100
stop_unwrap = False
while not stop_unwrap and replace_depth > 1:
replace_depth -= 1 # prevent infinite loop
# pass1: replace options
pass1, is_replaced1 = replace_options(text)
while is_replaced1:
pass1, is_replaced1 = replace_options(pass1)
# pass2: replace wildcards
text, is_replaced2 = replace_wildcard(pass1)
stop_unwrap = not is_replaced1 and not is_replaced2
return text
def is_numeric_string(input_str):
return re.match(r'^-?\d+(\.\d+)?$', input_str) is not None
def safe_float(x):
if is_numeric_string(x):
return float(x)
else:
return 1.0
def extract_lora_values(string):
pattern = r'<lora:([^>]+)>'
matches = re.findall(pattern, string)
def touch_lbw(text):
return re.sub(r'LBW=[A-Za-z][A-Za-z0-9_-]*:', r'LBW=', text)
items = [touch_lbw(match.strip(':')) for match in matches]
added = set()
result = []
for item in items:
item = item.split(':')
lora = None
a = None
b = None
lbw = None
lbw_a = None
lbw_b = None
if len(item) > 0:
lora = item[0]
for sub_item in item[1:]:
if is_numeric_string(sub_item):
if a is None:
a = float(sub_item)
elif b is None:
b = float(sub_item)
elif sub_item.startswith("LBW="):
for lbw_item in sub_item[4:].split(';'):
if lbw_item.startswith("A="):
lbw_a = safe_float(lbw_item[2:].strip())
elif lbw_item.startswith("B="):
lbw_b = safe_float(lbw_item[2:].strip())
elif lbw_item.strip() != '':
lbw = lbw_item
if a is None:
a = 1.0
if b is None:
b = a
if lora is not None and lora not in added:
result.append((lora, a, b, lbw, lbw_a, lbw_b))
added.add(lora)
return result
def remove_lora_tags(string):
pattern = r'<lora:[^>]+>'
result = re.sub(pattern, '', string)
return result
def resolve_lora_name(lora_name_cache, name):
if os.path.exists(name):
return name
else:
if len(lora_name_cache) == 0:
lora_name_cache.extend(folder_paths.get_filename_list("loras"))
for x in lora_name_cache:
if x.endswith(name):
return x
def process_with_loras(wildcard_opt, model, clip, clip_encoder=None):
lora_name_cache = []
pass1 = process(wildcard_opt)
loras = extract_lora_values(pass1)
pass2 = remove_lora_tags(pass1)
for lora_name, model_weight, clip_weight, lbw, lbw_a, lbw_b in loras:
lora_name_ext = lora_name.split('.')
if ('.'+lora_name_ext[-1]) not in folder_paths.supported_pt_extensions:
lora_name = lora_name+".safetensors"
orig_lora_name = lora_name
lora_name = resolve_lora_name(lora_name_cache, lora_name)
if lora_name is not None:
path = folder_paths.get_full_path("loras", lora_name)
else:
path = None
if path is not None:
print(f"LOAD LORA: {lora_name}: {model_weight}, {clip_weight}, LBW={lbw}, A={lbw_a}, B={lbw_b}")
def default_lora():
return nodes.LoraLoader().load_lora(model, clip, lora_name, model_weight, clip_weight)
if lbw is not None:
if 'LoraLoaderBlockWeight //Inspire' not in nodes.NODE_CLASS_MAPPINGS:
utils.try_install_custom_node(
'https://github.com/ltdrdata/ComfyUI-Inspire-Pack',
"To use 'LBW=' syntax in wildcards, 'Inspire Pack' extension is required.")
print(f"'LBW(Lora Block Weight)' is given, but the 'Inspire Pack' is not installed. The LBW= attribute is being ignored.")
model, clip = default_lora()
else:
cls = nodes.NODE_CLASS_MAPPINGS['LoraLoaderBlockWeight //Inspire']
model, clip, _ = cls().doit(model, clip, lora_name, model_weight, clip_weight, False, 0, lbw_a, lbw_b, "", lbw)
else:
model, clip = default_lora()
else:
print(f"LORA NOT FOUND: {orig_lora_name}")
pass3 = [x.strip() for x in pass2.split("BREAK")]
pass3 = [x for x in pass3 if x != '']
if len(pass3) == 0:
pass3 = ['']
pass3_str = [f'[{x}]' for x in pass3]
print(f"CLIP: {str.join(' + ', pass3_str)}")
result = None
for prompt in pass3:
if clip_encoder is None:
cur = nodes.CLIPTextEncode().encode(clip, prompt)[0]
else:
cur = clip_encoder.encode(clip, prompt)[0]
if result is not None:
result = nodes.ConditioningConcat().concat(result, cur)[0]
else:
result = cur
return model, clip, result
def starts_with_regex(pattern, text):
regex = re.compile(pattern)
return bool(regex.match(text))
def split_to_dict(text):
pattern = r'\[([A-Za-z0-9_. ]+)\]([^\[]+)(?=\[|$)'
matches = re.findall(pattern, text)
result_dict = {key: value.strip() for key, value in matches}
return result_dict
class WildcardChooser:
def __init__(self, items, randomize_when_exhaust):
self.i = 0
self.items = items
self.randomize_when_exhaust = randomize_when_exhaust
def get(self, seg):
if self.i >= len(self.items):
self.i = 0
if self.randomize_when_exhaust:
random.shuffle(self.items)
item = self.items[self.i]
self.i += 1
return item
class WildcardChooserDict:
def __init__(self, items):
self.items = items
def get(self, seg):
text = ""
if 'ALL' in self.items:
text = self.items['ALL']
if seg.label in self.items:
text += self.items[seg.label]
return text
def split_string_with_sep(input_string):
sep_pattern = r'\[SEP(?:\:\w+)?\]'
substrings = re.split(sep_pattern, input_string)
result_list = [None]
matches = re.findall(sep_pattern, input_string)
for i, substring in enumerate(substrings):
result_list.append(substring)
if i < len(matches):
if matches[i] == '[SEP]':
result_list.append(None)
elif matches[i] == '[SEP:R]':
result_list.append(random.randint(0, 1125899906842624))
else:
try:
seed = int(matches[i][5:-1])
except:
seed = None
result_list.append(seed)
iterable = iter(result_list)
return list(zip(iterable, iterable))
def process_wildcard_for_segs(wildcard):
if wildcard.startswith('[LAB]'):
raw_items = split_to_dict(wildcard)
items = {}
for k, v in raw_items.items():
v = v.strip()
if v != '':
items[k] = v
return 'LAB', WildcardChooserDict(items)
elif starts_with_regex(r"\[(ASC|DSC|RND)\]", wildcard):
mode = wildcard[1:4]
items = split_string_with_sep(wildcard[5:])
if mode == 'RND':
random.shuffle(items)
return mode, WildcardChooser(items, True)
else:
return mode, WildcardChooser(items, False)
else:
return None, WildcardChooser([(None, wildcard)], False)
@@ -1,80 +0,0 @@
# Due to the current lack of maintenance for the `ComfyUI_Noise` extension,
# I have copied the code from the applied PR.
# https://github.com/BlenderNeko/ComfyUI_Noise/pull/13/files
import comfy
import torch
class Unsampler:
@classmethod
def INPUT_TYPES(s):
return {"required":
{"model": ("MODEL",),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"end_at_step": ("INT", {"default": 0, "min": 0, "max": 10000}),
"cfg": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
"normalize": (["disable", "enable"],),
"positive": ("CONDITIONING",),
"negative": ("CONDITIONING",),
"latent_image": ("LATENT",),
}}
RETURN_TYPES = ("LATENT",)
FUNCTION = "unsampler"
CATEGORY = "sampling"
def unsampler(self, model, cfg, sampler_name, steps, end_at_step, scheduler, normalize, positive, negative,
latent_image):
normalize = normalize == "enable"
device = comfy.model_management.get_torch_device()
latent = latent_image
latent_image = latent["samples"]
end_at_step = min(end_at_step, steps - 1)
end_at_step = steps - end_at_step
noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
noise_mask = None
if "noise_mask" in latent:
noise_mask = comfy.sample.prepare_mask(latent["noise_mask"], noise.shape, device)
real_model = None
real_model = model.model
noise = noise.to(device)
latent_image = latent_image.to(device)
positive = comfy.sample.convert_cond(positive)
negative = comfy.sample.convert_cond(negative)
models, inference_memory = comfy.sample.get_additional_models(positive, negative, model.model_dtype())
comfy.model_management.load_models_gpu([model] + models, model.memory_required(noise.shape) + inference_memory)
sampler = comfy.samplers.KSampler(real_model, steps=steps, device=device, sampler=sampler_name,
scheduler=scheduler, denoise=1.0, model_options=model.model_options)
sigmas = sigmas = sampler.sigmas.flip(0) + 0.0001
pbar = comfy.utils.ProgressBar(steps)
def callback(step, x0, x, total_steps):
pbar.update_absolute(step + 1, total_steps)
samples = sampler.sample(noise, positive, negative, cfg=cfg, latent_image=latent_image,
force_full_denoise=False, denoise_mask=noise_mask, sigmas=sigmas, start_step=0,
last_step=end_at_step, callback=callback)
if normalize:
# technically doesn't normalize because unsampling is not guaranteed to end at a std given by the schedule
samples -= samples.mean()
samples /= samples.std()
samples = samples.cpu()
comfy.sample.cleanup_additional_models(models)
out = latent.copy()
out["samples"] = samples
return (out,)
@@ -1,4 +0,0 @@
{
"Segs Mask": "This node is renamed to 'ImpactSegsAndMask'",
"Segs Mask ForEach": "This node is renamed to 'ImpactSegsAndMaskForEach'"
}
@@ -1,172 +0,0 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "aaaaaaaaaa"
},
"source": [
"Git clone the repo and install the requirements. (ignore the pip errors about protobuf)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "bbbbbbbbbb"
},
"outputs": [],
"source": [
"#@title Environment Setup\n",
"\n",
"from pathlib import Path\n",
"\n",
"OPTIONS = {}\n",
"\n",
"WORKSPACE = 'ComfyUI'\n",
"USE_GOOGLE_DRIVE = True #@param {type:\"boolean\"}\n",
"UPDATE_COMFY_UI = True #@param {type:\"boolean\"}\n",
"\n",
"OPTIONS['USE_GOOGLE_DRIVE'] = USE_GOOGLE_DRIVE\n",
"OPTIONS['UPDATE_COMFY_UI'] = UPDATE_COMFY_UI\n",
"\n",
"if OPTIONS['USE_GOOGLE_DRIVE']:\n",
" !echo \"Mounting Google Drive...\"\n",
" %cd /\n",
" \n",
" from google.colab import drive\n",
" drive.mount('/content/drive')\n",
"\n",
" WORKSPACE = \"/content/drive/MyDrive/ComfyUI\"\n",
" \n",
" %cd /content/drive/MyDrive\n",
"\n",
"![ ! -d $WORKSPACE ] && echo \"-= Initial setup ComfyUI (Original)=-\" && git clone https://github.com/comfyanonymous/ComfyUI\n",
"%cd $WORKSPACE\n",
"\n",
"if OPTIONS['UPDATE_COMFY_UI']:\n",
" !echo \"-= Updating ComfyUI =-\"\n",
" !git pull\n",
" !rm \"/content/drive/MyDrive/ComfyUI/custom_nodes/comfyui-impact-pack.py\"\n",
"\n",
"%cd custom_nodes\n",
"!git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack\n",
"%cd $WORKSPACE\n",
"\n",
"!echo -= Install dependencies =-\n",
"!pip -q install xformers -r requirements.txt\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "kkkkkkkkkkkkkk"
},
"source": [
"### Run ComfyUI with localtunnel (Recommended Way)\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "jjjjjjjjjjjjj",
"outputId": "83be9411-d939-4813-e6c1-80e75bf8e80d"
},
"outputs": [],
"source": [
"!npm install -g localtunnel\n",
"\n",
"import subprocess\n",
"import threading\n",
"import time\n",
"import socket\n",
"def iframe_thread(port):\n",
" while True:\n",
" time.sleep(0.5)\n",
" sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n",
" result = sock.connect_ex(('127.0.0.1', port))\n",
" if result == 0:\n",
" break\n",
" sock.close()\n",
" print(\"\\nComfyUI finished loading, trying to launch localtunnel (if it gets stuck here localtunnel is having issues)\")\n",
" p = subprocess.Popen([\"lt\", \"--port\", \"{}\".format(port)], stdout=subprocess.PIPE)\n",
" for line in p.stdout:\n",
" print(line.decode(), end='')\n",
"\n",
"\n",
"threading.Thread(target=iframe_thread, daemon=True, args=(8188,)).start()\n",
"\n",
"!python main.py --dont-print-server"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "gggggggggg"
},
"source": [
"### Run ComfyUI with colab iframe (use only in case the previous way with localtunnel doesn't work)\n",
"\n",
"You should see the ui appear in an iframe. If you get a 403 error, it's your firefox settings or an extension that's messing things up.\n",
"\n",
"If you want to open it in another window use the link.\n",
"\n",
"Note that some UI features like live image previews won't work because the colab iframe blocks websockets."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "hhhhhhhhhh"
},
"outputs": [],
"source": [
"import threading\n",
"import time\n",
"import socket\n",
"def iframe_thread(port):\n",
" while True:\n",
" time.sleep(0.5)\n",
" sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n",
" result = sock.connect_ex(('127.0.0.1', port))\n",
" if result == 0:\n",
" break\n",
" sock.close()\n",
" from google.colab import output\n",
" output.serve_kernel_port_as_iframe(port, height=1024)\n",
" print(\"to open it in a window you can open this link here:\")\n",
" output.serve_kernel_port_as_window(port)\n",
"\n",
"threading.Thread(target=iframe_thread, daemon=True, args=(8188,)).start()\n",
"\n",
"!python main.py --dont-print-server"
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"provenance": []
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@@ -1,6 +0,0 @@
segment-anything
scikit-image
piexif
transformers
opencv-python-headless
GitPython
@@ -1,976 +0,0 @@
{
"last_node_id": 27,
"last_link_id": 46,
"nodes": [
{
"id": 11,
"type": "EditBasicPipe",
"pos": [
1260,
590
],
"size": {
"0": 267,
"1": 126
},
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "basic_pipe",
"type": "BASIC_PIPE",
"link": 15
},
{
"name": "model",
"type": "MODEL",
"link": null
},
{
"name": "clip",
"type": "CLIP",
"link": null
},
{
"name": "vae",
"type": "VAE",
"link": null
},
{
"name": "positive",
"type": "CONDITIONING",
"link": 17
},
{
"name": "negative",
"type": "CONDITIONING",
"link": null
}
],
"outputs": [
{
"name": "basic_pipe",
"type": "BASIC_PIPE",
"links": [
20
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "EditBasicPipe"
}
},
{
"id": 12,
"type": "CLIPTextEncode",
"pos": [
420,
670
],
"size": {
"0": 422.84503173828125,
"1": 164.31304931640625
},
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 16
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"links": [
17
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
"photorealistic:1.4, best quality:1.4, masterpiece, 1girl is sitting in the cafe terrace, (colorful hair:1.1)"
]
},
{
"id": 6,
"type": "CLIPTextEncode",
"pos": [
415,
186
],
"size": {
"0": 422.84503173828125,
"1": 164.31304931640625
},
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 3
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"links": [
13
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
"photorealistic:1.4, best quality:1.4, masterpiece, 1girl is sitting in the cafe terrace"
]
},
{
"id": 7,
"type": "CLIPTextEncode",
"pos": [
413,
389
],
"size": {
"0": 425.27801513671875,
"1": 180.6060791015625
},
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 5
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"links": [
14
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
"text, watermark, low quality:1.4, worst quality:1.4"
]
},
{
"id": 10,
"type": "ToBasicPipe",
"pos": [
952,
189
],
"size": {
"0": 241.79998779296875,
"1": 106
},
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "model",
"type": "MODEL",
"link": 10
},
{
"name": "clip",
"type": "CLIP",
"link": 11
},
{
"name": "vae",
"type": "VAE",
"link": 12
},
{
"name": "positive",
"type": "CONDITIONING",
"link": 13
},
{
"name": "negative",
"type": "CONDITIONING",
"link": 14
}
],
"outputs": [
{
"name": "basic_pipe",
"type": "BASIC_PIPE",
"links": [
15,
19,
33
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "ToBasicPipe"
}
},
{
"id": 22,
"type": "FromBasicPipe",
"pos": [
880,
1040
],
"size": {
"0": 241.79998779296875,
"1": 106
},
"flags": {},
"order": 8,
"mode": 0,
"inputs": [
{
"name": "basic_pipe",
"type": "BASIC_PIPE",
"link": 33
}
],
"outputs": [
{
"name": "model",
"type": "MODEL",
"links": [
34
],
"shape": 3,
"slot_index": 0
},
{
"name": "clip",
"type": "CLIP",
"links": null,
"shape": 3
},
{
"name": "vae",
"type": "VAE",
"links": [
40
],
"shape": 3,
"slot_index": 2
},
{
"name": "positive",
"type": "CONDITIONING",
"links": [
35
],
"shape": 3,
"slot_index": 3
},
{
"name": "negative",
"type": "CONDITIONING",
"links": [
36
],
"shape": 3,
"slot_index": 4
}
],
"properties": {
"Node name for S&R": "FromBasicPipe"
}
},
{
"id": 24,
"type": "VAEDecode",
"pos": [
1938,
935
],
"size": {
"0": 210,
"1": 46
},
"flags": {},
"order": 14,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": 46
},
{
"name": "vae",
"type": "VAE",
"link": 40
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
41
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "VAEDecode"
}
},
{
"id": 4,
"type": "CheckpointLoaderSimple",
"pos": [
-5,
212
],
"size": {
"0": 315,
"1": 98
},
"flags": {},
"order": 0,
"mode": 0,
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"links": [
10
],
"slot_index": 0
},
{
"name": "CLIP",
"type": "CLIP",
"links": [
3,
5,
11,
16
],
"slot_index": 1
},
{
"name": "VAE",
"type": "VAE",
"links": [
12,
31
],
"slot_index": 2
}
],
"properties": {
"Node name for S&R": "CheckpointLoaderSimple"
},
"widgets_values": [
"V07_v07.safetensors"
]
},
{
"id": 25,
"type": "PreviewImage",
"pos": [
2175,
1079
],
"size": {
"0": 516,
"1": 424
},
"flags": {},
"order": 15,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 41
}
],
"properties": {
"Node name for S&R": "PreviewImage"
}
},
{
"id": 13,
"type": "KSamplerAdvancedProvider",
"pos": [
1727,
192
],
"size": {
"0": 355.20001220703125,
"1": 154
},
"flags": {},
"order": 7,
"mode": 0,
"inputs": [
{
"name": "basic_pipe",
"type": "BASIC_PIPE",
"link": 19
}
],
"outputs": [
{
"name": "KSAMPLER_ADVANCED",
"type": "KSAMPLER_ADVANCED",
"links": [
42
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "KSamplerAdvancedProvider"
},
"widgets_values": [
8,
"fixed",
"normal"
]
},
{
"id": 16,
"type": "EmptyLatentImage",
"pos": [
532,
1143
],
"size": {
"0": 315,
"1": 106
},
"flags": {},
"order": 1,
"mode": 0,
"outputs": [
{
"name": "LATENT",
"type": "LATENT",
"links": [
28,
45
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "EmptyLatentImage"
},
"widgets_values": [
792,
512,
1
]
},
{
"id": 19,
"type": "KSampler",
"pos": [
1194.657802060547,
1075.971700888672
],
"size": [
315,
473.9999771118164
],
"flags": {},
"order": 10,
"mode": 0,
"inputs": [
{
"name": "model",
"type": "MODEL",
"link": 34
},
{
"name": "positive",
"type": "CONDITIONING",
"link": 35
},
{
"name": "negative",
"type": "CONDITIONING",
"link": 36
},
{
"name": "latent_image",
"type": "LATENT",
"link": 28
}
],
"outputs": [
{
"name": "LATENT",
"type": "LATENT",
"links": [
30
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "KSampler"
},
"widgets_values": [
1107040072933062,
"fixed",
20,
8,
"euler",
"normal",
1
]
},
{
"id": 27,
"type": "TwoAdvancedSamplersForMask",
"pos": [
2187,
266
],
"size": [
315,
426.00000762939453
],
"flags": {},
"order": 13,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": 45
},
{
"name": "base_sampler",
"type": "KSAMPLER_ADVANCED",
"link": 42
},
{
"name": "mask_sampler",
"type": "KSAMPLER_ADVANCED",
"link": 43
},
{
"name": "mask",
"type": "MASK",
"link": 44
}
],
"outputs": [
{
"name": "LATENT",
"type": "LATENT",
"links": [
46
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "TwoAdvancedSamplersForMask"
},
"widgets_values": [
1107040072933062,
"fixed",
20,
1,
10
]
},
{
"id": 23,
"type": "PreviewBridge",
"pos": [
1778,
1098
],
"size": {
"0": 315,
"1": 290
},
"flags": {},
"order": 12,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 37
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": null,
"shape": 3
},
{
"name": "MASK",
"type": "MASK",
"links": [
44
],
"shape": 3,
"slot_index": 1
}
],
"properties": {
"Node name for S&R": "PreviewBridge"
},
"widgets_values": [
{
"filename": "clipspace-mask-348148.69999999925.png",
"subfolder": "clipspace",
"type": "input",
"image_hash": 492469318636598500,
"forward_filename": "ComfyUI_00001_.png",
"forward_subfolder": "",
"forward_type": "temp"
}
]
},
{
"id": 15,
"type": "KSamplerAdvancedProvider",
"pos": [
1719,
592
],
"size": {
"0": 355.20001220703125,
"1": 154
},
"flags": {},
"order": 9,
"mode": 0,
"inputs": [
{
"name": "basic_pipe",
"type": "BASIC_PIPE",
"link": 20
}
],
"outputs": [
{
"name": "KSAMPLER_ADVANCED",
"type": "KSAMPLER_ADVANCED",
"links": [
43
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "KSamplerAdvancedProvider"
},
"widgets_values": [
8,
"fixed",
"normal"
]
},
{
"id": 20,
"type": "VAEDecode",
"pos": [
1546,
972
],
"size": {
"0": 210,
"1": 46
},
"flags": {},
"order": 11,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": 30
},
{
"name": "vae",
"type": "VAE",
"link": 31
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
37
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "VAEDecode"
}
}
],
"links": [
[
3,
4,
1,
6,
0,
"CLIP"
],
[
5,
4,
1,
7,
0,
"CLIP"
],
[
10,
4,
0,
10,
0,
"MODEL"
],
[
11,
4,
1,
10,
1,
"CLIP"
],
[
12,
4,
2,
10,
2,
"VAE"
],
[
13,
6,
0,
10,
3,
"CONDITIONING"
],
[
14,
7,
0,
10,
4,
"CONDITIONING"
],
[
15,
10,
0,
11,
0,
"BASIC_PIPE"
],
[
16,
4,
1,
12,
0,
"CLIP"
],
[
17,
12,
0,
11,
4,
"CONDITIONING"
],
[
19,
10,
0,
13,
0,
"BASIC_PIPE"
],
[
20,
11,
0,
15,
0,
"BASIC_PIPE"
],
[
28,
16,
0,
19,
3,
"LATENT"
],
[
30,
19,
0,
20,
0,
"LATENT"
],
[
31,
4,
2,
20,
1,
"VAE"
],
[
33,
10,
0,
22,
0,
"BASIC_PIPE"
],
[
34,
22,
0,
19,
0,
"MODEL"
],
[
35,
22,
3,
19,
1,
"CONDITIONING"
],
[
36,
22,
4,
19,
2,
"CONDITIONING"
],
[
37,
20,
0,
23,
0,
"IMAGE"
],
[
40,
22,
2,
24,
1,
"VAE"
],
[
41,
24,
0,
25,
0,
"IMAGE"
],
[
42,
13,
0,
27,
1,
"KSAMPLER_ADVANCED"
],
[
43,
15,
0,
27,
2,
"KSAMPLER_ADVANCED"
],
[
44,
23,
1,
27,
3,
"MASK"
],
[
45,
16,
0,
27,
0,
"LATENT"
],
[
46,
27,
0,
24,
0,
"LATENT"
]
],
"groups": [],
"config": {},
"extra": {},
"version": 0.4
}
File diff suppressed because it is too large Load Diff
@@ -1,622 +0,0 @@
{
"last_node_id": 38,
"last_link_id": 52,
"nodes": [
{
"id": 21,
"type": "SEGSToImageList",
"pos": [
2160,
970
],
"size": {
"0": 304.79998779296875,
"1": 46
},
"flags": {},
"order": 10,
"mode": 0,
"inputs": [
{
"name": "segs",
"type": "SEGS",
"link": 41
},
{
"name": "fallback_image_opt",
"type": "IMAGE",
"link": 26,
"slot_index": 1
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
27
],
"shape": 6,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "SEGSToImageList"
}
},
{
"id": 5,
"type": "MaskToSEGS",
"pos": [
1520,
980
],
"size": {
"0": 210,
"1": 130
},
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "mask",
"type": "MASK",
"link": 5
}
],
"outputs": [
{
"name": "SEGS",
"type": "SEGS",
"links": [
35,
46
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "MaskToSEGS"
},
"widgets_values": [
"False",
3,
"disabled",
10
]
},
{
"id": 36,
"type": "MasksToMaskList",
"pos": [
2270,
680
],
"size": {
"0": 158.000244140625,
"1": 26
},
"flags": {},
"order": 8,
"mode": 0,
"inputs": [
{
"name": "masks",
"type": "MASKS",
"link": 51
}
],
"outputs": [
{
"name": "MASK",
"type": "MASK",
"links": [
52
],
"shape": 6,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "MasksToMaskList"
},
"color": "#223",
"bgcolor": "#335"
},
{
"id": 35,
"type": "MaskToImage",
"pos": [
2480,
680
],
"size": {
"0": 176.39999389648438,
"1": 38.59991455078125
},
"flags": {},
"order": 11,
"mode": 0,
"inputs": [
{
"name": "mask",
"type": "MASK",
"link": 52
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
50
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "MaskToImage"
}
},
{
"id": 28,
"type": "Segs & Mask ForEach",
"pos": [
1800,
980
],
"size": {
"0": 243.60000610351562,
"1": 46
},
"flags": {},
"order": 7,
"mode": 0,
"inputs": [
{
"name": "segs",
"type": "SEGS",
"link": 35,
"slot_index": 0
},
{
"name": "masks",
"type": "MASKS",
"link": 43
}
],
"outputs": [
{
"name": "SEGS",
"type": "SEGS",
"links": [
41
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "Segs & Mask ForEach"
}
},
{
"id": 22,
"type": "PreviewImage",
"pos": [
2510,
970
],
"size": {
"0": 210,
"1": 246
},
"flags": {},
"order": 12,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 27
}
],
"properties": {
"Node name for S&R": "PreviewImage"
}
},
{
"id": 4,
"type": "LoadImage",
"pos": [
1150,
460
],
"size": {
"0": 315,
"1": 314
},
"flags": {},
"order": 0,
"mode": 0,
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
26,
47
],
"shape": 3,
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": [
5
],
"shape": 3,
"slot_index": 1
}
],
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"clipspace/clipspace-mask-416378.30000000075.png [input]",
"image"
]
},
{
"id": 33,
"type": "SAMDetectorSegmented",
"pos": [
1740,
310
],
"size": {
"0": 315,
"1": 218
},
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "sam_model",
"type": "SAM_MODEL",
"link": 45
},
{
"name": "segs",
"type": "SEGS",
"link": 46
},
{
"name": "image",
"type": "IMAGE",
"link": 47
}
],
"outputs": [
{
"name": "combined_mask",
"type": "MASK",
"links": [
44
],
"shape": 3,
"slot_index": 0
},
{
"name": "batch_masks",
"type": "MASKS",
"links": [
43,
51
],
"shape": 3,
"slot_index": 1
}
],
"properties": {
"Node name for S&R": "SAMDetectorSegmented"
},
"widgets_values": [
"center-1",
0,
0.7,
0,
0.7,
"False"
]
},
{
"id": 2,
"type": "SAMLoader",
"pos": [
1160,
310
],
"size": {
"0": 315,
"1": 82
},
"flags": {},
"order": 1,
"mode": 0,
"outputs": [
{
"name": "SAM_MODEL",
"type": "SAM_MODEL",
"links": [
45
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "SAMLoader"
},
"widgets_values": [
"sam_vit_b_01ec64.pth",
"AUTO"
]
},
{
"id": 6,
"type": "MaskToImage",
"pos": [
2300,
310
],
"size": {
"0": 176.39999389648438,
"1": 26
},
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "mask",
"type": "MASK",
"link": 44
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
8
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "MaskToImage"
}
},
{
"id": 7,
"type": "PreviewImage",
"pos": [
2720,
310
],
"size": {
"0": 210,
"1": 246
},
"flags": {},
"order": 9,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 8
}
],
"properties": {
"Node name for S&R": "PreviewImage"
}
},
{
"id": 9,
"type": "PreviewImage",
"pos": [
2720,
680
],
"size": {
"0": 210,
"1": 246
},
"flags": {},
"order": 13,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 50
}
],
"properties": {
"Node name for S&R": "PreviewImage"
}
},
{
"id": 38,
"type": "Note",
"pos": [
2032,
698
],
"size": [
210,
81.49969482421875
],
"flags": {},
"order": 2,
"mode": 0,
"properties": {
"text": ""
},
"widgets_values": [
"MasksToMaskList node introduced\n"
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 37,
"type": "Note",
"pos": [
2071,
384
],
"size": [
281.500244140625,
65.09967041015625
],
"flags": {},
"order": 3,
"mode": 0,
"properties": {
"text": ""
},
"widgets_values": [
"type of batch_masks => MASKS instead of MASK\n"
],
"color": "#432",
"bgcolor": "#653"
}
],
"links": [
[
5,
4,
1,
5,
0,
"MASK"
],
[
8,
6,
0,
7,
0,
"IMAGE"
],
[
26,
4,
0,
21,
1,
"IMAGE"
],
[
27,
21,
0,
22,
0,
"IMAGE"
],
[
35,
5,
0,
28,
0,
"SEGS"
],
[
41,
28,
0,
21,
0,
"SEGS"
],
[
43,
33,
1,
28,
1,
"MASKS"
],
[
44,
33,
0,
6,
0,
"MASK"
],
[
45,
2,
0,
33,
0,
"SAM_MODEL"
],
[
46,
5,
0,
33,
1,
"SEGS"
],
[
47,
4,
0,
33,
2,
"IMAGE"
],
[
50,
35,
0,
9,
0,
"IMAGE"
],
[
51,
33,
1,
36,
0,
"MASKS"
],
[
52,
36,
0,
35,
0,
"MASK"
]
],
"groups": [],
"config": {},
"extra": {},
"version": 0.4
}
@@ -1,72 +0,0 @@
## When a permission error occurs during the installation process (on Windows)
* There are cases where the package you are trying to install is already being used by another custom node that has been loaded.
* This issue occurs only on Windows.
* Please close ComfyUI and execute install.py directly using Python in the custom_nodes/ComfyUI-Impact-Pack directory.
* In case **portable** version:
1. goto **ComfyUI_windows_portable** directory in **cmd**
2. execute ```.\python_embeded\python -s -m custom_nodes\ComfyUI-Impact-Pack\install.py```
* In case **venv**:
1. activate venv
2. execute ```python -s -m custom_nodes\ComfyUI-Impact-Pack\install.py```
* Others:
1. Please modify the path of 'python' according to your Python environment.
2. execute ```(YOUR PYTHON) -s -m custom_nodes\ComfyUI-Impact-Pack\install.py```
## If the nodes of the Impact Pack hang during execution
* During the execution of processes related to dilation, issues like this may arise depending on the compatibility of the computer environment.
* Please set `disable_gpu_opencv = True` in the `ComfyUI-Impact-Pack/impact-pack.ini` file. Occasionally, issues may arise when the OpenCV GPU mode is activated depending on the environment.
e.g.
```
[default]
dependency_version = 17
mmdet_skip = True
sam_editor_cpu = False
sam_editor_model = sam_vit_b_01ec64.pth
custom_wildcards = /home/me/github/ComfyUI/custom_nodes/ComfyUI-Impact-Pack/custom_wildcards
disable_gpu_opencv = True
```
## An issue has occurred with importing Ultralytics.
```
AttributeError: 'Logger' object has no attribute 'reconfigure'
or
AttributeError: 'Logger' object has no attribute 'encoding'
```
* Update `ComfyUI-Manager` to V1.1.2 or above
## An issue has occurred about 'cv2'
```
AttributeError: module 'cv2' has no attribute 'setNumThreads'
```
* Update 'opencv-python' and 'opencv-python-headless' to latest version
* Once you update to the latest version, you can also downgrade back to 4.6.0.66 if needed.
* For the portable version, navigate to the portable installation directory in the command prompt, and enter the following command:
```
.\python_embeded\python.exe -m pip install -U opencv-python opencv-python-headless
```
* When using the WAS node suite or reactor nodes, using the latest version may not work as expected. You can downgrade using the following command:
```
.\python_embeded\python.exe -m pip install -U opencv-python==4.6.0.66 opencv-python-headless==4.6.0.66
```
## Destortion on Detailer
* Please also note that this issue may be caused by a bug in xformers 0.0.18. If you encounter this problem, please try adjusting the guide_size parameter.
![example](black1.png)
![example](black2.png)
* guide_size changed from 256 -> 192
Binary file not shown.

Before

Width:  |  Height:  |  Size: 735 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 693 KiB

@@ -1,38 +0,0 @@
import os
import sys
import time
import platform
import shutil
import subprocess
comfy_path = '../..'
def rmtree(path):
retry_count = 3
while True:
try:
retry_count -= 1
if platform.system() == "Windows":
subprocess.check_call(['attrib', '-R', path + '\\*', '/S'])
shutil.rmtree(path)
return True
except Exception as ex:
print(f"ex: {ex}")
time.sleep(3)
if retry_count < 0:
raise ex
print(f"Uninstall retry({retry_count})")
js_dest_path = os.path.join(comfy_path, "web", "extensions", "impact-pack")
if os.path.exists(js_dest_path):
rmtree(js_dest_path)
@@ -1,9 +0,0 @@
rose
orchid
iris
carnation
lily
daisy
chrysanthemum
daffodil
dahlia
@@ -1,9 +0,0 @@
diamond
emerald
sapphire
opal
ruby
topaz
pearl
rubyamethyst
aquamarine