Skip to content

Conversation

@lstein
Copy link
Collaborator

@lstein lstein commented Jul 23, 2023

What type of PR is this? (check all applicable)

  • Refactor
  • [ X] Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Community Node Submission

Have you discussed this change with the InvokeAI team?

  • [ X] Yes
  • No, because:

Have you updated all relevant documentation?

  • [X ] Yes
  • [] No

Description

This PR adds NSFW checker and invisible watermark fields. The NSFW checker takes an image input and produces an image output. If NSFW content is detected, the output image will be blurred and a "caution" icon pasted into its upper left corner. A boolean active field controls whether the checker is active. If turned off it simply returns a copy of the image.

The invisible watermark node adds an invisible text to the image, defaulting to "InvokeAI". To decode the watermark use the invisible-watermark command, which is part of the invisible-watermark library:

$ invisible-watermark -v -a decode -t bytes -m dwtDct -l 64 ./bluebird-watermark.png 
decode time ms: 14.129877090454102
InvokeAI

Note that the -l (length) argument is mandatory. It is set to 64 here because the watermark InvokeAI is 8 bytes/64 bits long. The length must match in order for the watermark to be decoded correctly.

Both nodes are now incorporated into the linear Text2Image and Image2Image UIs, including the canvas. They are not implemented for inpaint currently.

The nodes can be disabled with configuration options:

invisible_watermark: false
nsfw_checker: false

or at launch time with --no-invisible_watermark and --no-nsfw_checker.

@lstein lstein requested a review from hipsterusername as a code owner July 24, 2023 03:41
Copy link
Contributor

@psychedelicious psychedelicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this all makes sense and implements the NSFW checks and watermark in a very nodely way. Requesting a number of small changes, and one larger design change.

@lstein lstein requested a review from ebr as a code owner July 24, 2023 13:24
@lstein lstein requested a review from psychedelicious July 25, 2023 20:15
@lstein lstein mentioned this pull request Jul 26, 2023
7 tasks
Lincoln Stein and others added 8 commits July 26, 2023 15:26
- add `addNSFWCheckerToGraph` and `addWatermarkerToGraph` functions
- use them in all linear graph creation
- add state & toggles to settings modal to enable these
- trigger queries for app config on socket connect
- disable the nsfw/watermark booleans if we get the app config and they are not available
@psychedelicious psychedelicious force-pushed the feat/safety-checker-node branch from 91e903c to db48f32 Compare July 26, 2023 08:20
@psychedelicious
Copy link
Contributor

feat(ui): add nsfw & watermark to linear ui

  • add addNSFWCheckerToGraph and addWatermarkerToGraph functions
  • use them in all linear graph creation
  • add state & toggles to settings modal to enable these
  • trigger queries for app config on socket connect
  • disable the nsfw/watermark booleans if we get the app config and they are not available

@psychedelicious
Copy link
Contributor

psychedelicious commented Jul 26, 2023

This is ready for review.

NSFW & Watermarking functionality

In Settings, there are toggles for NSFW checker and watermarker. There are 4 possible combinations of these two toggles:

  • NSFW off, watermark off
  • NSFW off, watermark on
  • NSFW on, watermark off
  • NSFW on, watermark on (default)

Test the following with every combination AND for both NSFW and non-NSFW outputs:

  • txt2img tab
  • txt2img tab with SDXL
  • txt2img tab with SDXL & Refiner
  • img2img tab
  • img2img tab with SDXL
  • img2img tab with SDXL & Refiner
  • canvas tab (txt2img generation)
  • canvas tab (img2img generation)
  • canvas tab (inpaint generation)

Expected results:

  • NSFW images are always blurred when NSFW checker is on
  • If the watermarker is enabled, there should be a barely-visible watermark, typically visible as a grid of yellow dots
  • You only ever get a single image in gallery
  • You get metadata for every generation (note that NSFW & watermark status are not reported in metadata)

NSFW & Watermarking installation/availability

  1. Have them both installed (watermark is a python package so you should have it already if you've pip installed, but NSFW checker is an optional model, run configure script to install)
  2. Enable both settings
  3. "Disable" both features by commenting out where they are appended to arrays, around L70 in invokeai/app/api/routers/app_info.py
  4. Restart the backend
  5. When it comes back up and the UI reconnects, the setting should disable themselves and you should be prevented from turning them back on

@lstein
Copy link
Collaborator Author

lstein commented Jul 26, 2023

Both nsfw and watermark options have been removed from invokeai.yaml. Internally they remain deprecated config options that always return True. This is to avoid pydantic croaking when it reads a legacy config file that has the nsfw_checker option in it. However, these options will not be written out to new files.

@lstein lstein merged commit f060e32 into main Jul 26, 2023
@lstein lstein deleted the feat/safety-checker-node branch July 26, 2023 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants