mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat: Add SDXL Negative Aesthetic Score
This commit is contained in:
parent
90fa3eebb3
commit
499e89d6f6
@ -67,7 +67,10 @@ class CoreMetadata(BaseModelExcludeNull):
|
||||
)
|
||||
refiner_steps: Union[int, None] = Field(default=None, description="The number of steps used for the refiner")
|
||||
refiner_scheduler: Union[str, None] = Field(default=None, description="The scheduler used for the refiner")
|
||||
refiner_aesthetic_store: Union[float, None] = Field(
|
||||
refiner_positive_aesthetic_store: Union[float, None] = Field(
|
||||
default=None, description="The aesthetic score used for the refiner"
|
||||
)
|
||||
refiner_negative_aesthetic_store: Union[float, None] = Field(
|
||||
default=None, description="The aesthetic score used for the refiner"
|
||||
)
|
||||
refiner_start: Union[float, None] = Field(default=None, description="The start value used for refiner denoising")
|
||||
@ -136,7 +139,10 @@ class MetadataAccumulatorInvocation(BaseInvocation):
|
||||
)
|
||||
refiner_steps: Union[int, None] = Field(default=None, description="The number of steps used for the refiner")
|
||||
refiner_scheduler: Union[str, None] = Field(default=None, description="The scheduler used for the refiner")
|
||||
refiner_aesthetic_store: Union[float, None] = Field(
|
||||
refiner_positive_aesthetic_score: Union[float, None] = Field(
|
||||
default=None, description="The aesthetic score used for the refiner"
|
||||
)
|
||||
refiner_negative_aesthetic_score: Union[float, None] = Field(
|
||||
default=None, description="The aesthetic score used for the refiner"
|
||||
)
|
||||
refiner_start: Union[float, None] = Field(default=None, description="The start value used for refiner denoising")
|
||||
|
@ -25,7 +25,8 @@ export const addSDXLRefinerToGraph = (
|
||||
): void => {
|
||||
const {
|
||||
refinerModel,
|
||||
refinerAestheticScore,
|
||||
refinerPositiveAestheticScore,
|
||||
refinerNegativeAestheticScore,
|
||||
refinerSteps,
|
||||
refinerScheduler,
|
||||
refinerCFGScale,
|
||||
@ -40,7 +41,10 @@ export const addSDXLRefinerToGraph = (
|
||||
|
||||
if (metadataAccumulator) {
|
||||
metadataAccumulator.refiner_model = refinerModel;
|
||||
metadataAccumulator.refiner_aesthetic_store = refinerAestheticScore;
|
||||
metadataAccumulator.refiner_positive_aesthetic_score =
|
||||
refinerPositiveAestheticScore;
|
||||
metadataAccumulator.refiner_negative_aesthetic_score =
|
||||
refinerNegativeAestheticScore;
|
||||
metadataAccumulator.refiner_cfg_scale = refinerCFGScale;
|
||||
metadataAccumulator.refiner_scheduler = refinerScheduler;
|
||||
metadataAccumulator.refiner_start = refinerStart;
|
||||
@ -74,13 +78,13 @@ export const addSDXLRefinerToGraph = (
|
||||
type: 'sdxl_refiner_compel_prompt',
|
||||
id: SDXL_REFINER_POSITIVE_CONDITIONING,
|
||||
style: craftedPositiveStylePrompt,
|
||||
aesthetic_score: refinerAestheticScore,
|
||||
aesthetic_score: refinerPositiveAestheticScore,
|
||||
};
|
||||
graph.nodes[SDXL_REFINER_NEGATIVE_CONDITIONING] = {
|
||||
type: 'sdxl_refiner_compel_prompt',
|
||||
id: SDXL_REFINER_NEGATIVE_CONDITIONING,
|
||||
style: craftedNegativeStylePrompt,
|
||||
aesthetic_score: refinerAestheticScore,
|
||||
aesthetic_score: refinerNegativeAestheticScore,
|
||||
};
|
||||
graph.nodes[SDXL_REFINER_DENOISE_LATENTS] = {
|
||||
type: 'denoise_latents',
|
||||
|
@ -4,16 +4,16 @@ import {
|
||||
refinerModelChanged,
|
||||
setNegativeStylePromptSDXL,
|
||||
setPositiveStylePromptSDXL,
|
||||
setRefinerAestheticScore,
|
||||
setRefinerCFGScale,
|
||||
setRefinerNegativeAestheticScore,
|
||||
setRefinerPositiveAestheticScore,
|
||||
setRefinerScheduler,
|
||||
setRefinerStart,
|
||||
setRefinerSteps,
|
||||
} from 'features/sdxl/store/sdxlSlice';
|
||||
import { useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { UnsafeImageMetadata } from 'services/api/types';
|
||||
import { ImageDTO } from 'services/api/types';
|
||||
import { ImageDTO, UnsafeImageMetadata } from 'services/api/types';
|
||||
import { initialImageSelected, modelSelected } from '../store/actions';
|
||||
import {
|
||||
setCfgScale,
|
||||
@ -34,8 +34,9 @@ import {
|
||||
isValidPositivePrompt,
|
||||
isValidSDXLNegativeStylePrompt,
|
||||
isValidSDXLPositiveStylePrompt,
|
||||
isValidSDXLRefinerAestheticScore,
|
||||
isValidSDXLRefinerModel,
|
||||
isValidSDXLRefinerNegativeAestheticScore,
|
||||
isValidSDXLRefinerPositiveAestheticScore,
|
||||
isValidSDXLRefinerStart,
|
||||
isValidScheduler,
|
||||
isValidSeed,
|
||||
@ -339,7 +340,8 @@ export const useRecallParameters = () => {
|
||||
refiner_cfg_scale,
|
||||
refiner_steps,
|
||||
refiner_scheduler,
|
||||
refiner_aesthetic_store,
|
||||
refiner_positive_aesthetic_store,
|
||||
refiner_negative_aesthetic_store,
|
||||
refiner_start,
|
||||
} = metadata;
|
||||
|
||||
@ -398,8 +400,24 @@ export const useRecallParameters = () => {
|
||||
dispatch(setRefinerScheduler(refiner_scheduler));
|
||||
}
|
||||
|
||||
if (isValidSDXLRefinerAestheticScore(refiner_aesthetic_store)) {
|
||||
dispatch(setRefinerAestheticScore(refiner_aesthetic_store));
|
||||
if (
|
||||
isValidSDXLRefinerPositiveAestheticScore(
|
||||
refiner_positive_aesthetic_store
|
||||
)
|
||||
) {
|
||||
dispatch(
|
||||
setRefinerPositiveAestheticScore(refiner_positive_aesthetic_store)
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
isValidSDXLRefinerNegativeAestheticScore(
|
||||
refiner_negative_aesthetic_store
|
||||
)
|
||||
) {
|
||||
dispatch(
|
||||
setRefinerNegativeAestheticScore(refiner_negative_aesthetic_store)
|
||||
);
|
||||
}
|
||||
|
||||
if (isValidSDXLRefinerStart(refiner_start)) {
|
||||
|
@ -353,22 +353,40 @@ export const isValidPrecision = (val: unknown): val is PrecisionParam =>
|
||||
zPrecision.safeParse(val).success;
|
||||
|
||||
/**
|
||||
* Zod schema for SDXL refiner aesthetic score parameter
|
||||
* Zod schema for SDXL refiner positive aesthetic score parameter
|
||||
*/
|
||||
export const zSDXLRefinerAestheticScore = z.number().min(1).max(10);
|
||||
export const zSDXLRefinerPositiveAestheticScore = z.number().min(1).max(10);
|
||||
/**
|
||||
* Type alias for SDXL refiner aesthetic score parameter, inferred from its zod schema
|
||||
* Type alias for SDXL refiner aesthetic positive score parameter, inferred from its zod schema
|
||||
*/
|
||||
export type SDXLRefinerAestheticScoreParam = z.infer<
|
||||
typeof zSDXLRefinerAestheticScore
|
||||
export type SDXLRefinerPositiveAestheticScoreParam = z.infer<
|
||||
typeof zSDXLRefinerPositiveAestheticScore
|
||||
>;
|
||||
/**
|
||||
* Validates/type-guards a value as a SDXL refiner aesthetic score parameter
|
||||
* Validates/type-guards a value as a SDXL refiner positive aesthetic score parameter
|
||||
*/
|
||||
export const isValidSDXLRefinerAestheticScore = (
|
||||
export const isValidSDXLRefinerPositiveAestheticScore = (
|
||||
val: unknown
|
||||
): val is SDXLRefinerAestheticScoreParam =>
|
||||
zSDXLRefinerAestheticScore.safeParse(val).success;
|
||||
): val is SDXLRefinerPositiveAestheticScoreParam =>
|
||||
zSDXLRefinerPositiveAestheticScore.safeParse(val).success;
|
||||
|
||||
/**
|
||||
* Zod schema for SDXL refiner negative aesthetic score parameter
|
||||
*/
|
||||
export const zSDXLRefinerNegativeAestheticScore = z.number().min(1).max(10);
|
||||
/**
|
||||
* Type alias for SDXL refiner aesthetic negative score parameter, inferred from its zod schema
|
||||
*/
|
||||
export type SDXLRefinerNegativeAestheticScoreParam = z.infer<
|
||||
typeof zSDXLRefinerNegativeAestheticScore
|
||||
>;
|
||||
/**
|
||||
* Validates/type-guards a value as a SDXL refiner negative aesthetic score parameter
|
||||
*/
|
||||
export const isValidSDXLRefinerNegativeAestheticScore = (
|
||||
val: unknown
|
||||
): val is SDXLRefinerNegativeAestheticScoreParam =>
|
||||
zSDXLRefinerNegativeAestheticScore.safeParse(val).success;
|
||||
|
||||
/**
|
||||
* Zod schema for SDXL start parameter
|
||||
|
@ -4,9 +4,10 @@ import { stateSelector } from 'app/store/store';
|
||||
import { useAppSelector } from 'app/store/storeHooks';
|
||||
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
|
||||
import IAICollapse from 'common/components/IAICollapse';
|
||||
import ParamSDXLRefinerAestheticScore from './SDXLRefiner/ParamSDXLRefinerAestheticScore';
|
||||
import ParamSDXLRefinerCFGScale from './SDXLRefiner/ParamSDXLRefinerCFGScale';
|
||||
import ParamSDXLRefinerModelSelect from './SDXLRefiner/ParamSDXLRefinerModelSelect';
|
||||
import ParamSDXLRefinerNegativeAestheticScore from './SDXLRefiner/ParamSDXLRefinerNegativeAestheticScore';
|
||||
import ParamSDXLRefinerPositiveAestheticScore from './SDXLRefiner/ParamSDXLRefinerPositiveAestheticScore';
|
||||
import ParamSDXLRefinerScheduler from './SDXLRefiner/ParamSDXLRefinerScheduler';
|
||||
import ParamSDXLRefinerStart from './SDXLRefiner/ParamSDXLRefinerStart';
|
||||
import ParamSDXLRefinerSteps from './SDXLRefiner/ParamSDXLRefinerSteps';
|
||||
@ -38,7 +39,8 @@ const ParamSDXLRefinerCollapse = () => {
|
||||
<ParamSDXLRefinerCFGScale />
|
||||
</Flex>
|
||||
<ParamSDXLRefinerScheduler />
|
||||
<ParamSDXLRefinerAestheticScore />
|
||||
<ParamSDXLRefinerPositiveAestheticScore />
|
||||
<ParamSDXLRefinerNegativeAestheticScore />
|
||||
<ParamSDXLRefinerStart />
|
||||
</Flex>
|
||||
</IAICollapse>
|
||||
|
@ -0,0 +1,60 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import { stateSelector } from 'app/store/store';
|
||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
|
||||
import IAISlider from 'common/components/IAISlider';
|
||||
import { setRefinerNegativeAestheticScore } from 'features/sdxl/store/sdxlSlice';
|
||||
import { memo, useCallback } from 'react';
|
||||
import { useIsRefinerAvailable } from 'services/api/hooks/useIsRefinerAvailable';
|
||||
|
||||
const selector = createSelector(
|
||||
[stateSelector],
|
||||
({ sdxl, hotkeys }) => {
|
||||
const { refinerNegativeAestheticScore } = sdxl;
|
||||
const { shift } = hotkeys;
|
||||
|
||||
return {
|
||||
refinerNegativeAestheticScore,
|
||||
shift,
|
||||
};
|
||||
},
|
||||
defaultSelectorOptions
|
||||
);
|
||||
|
||||
const ParamSDXLRefinerNegativeAestheticScore = () => {
|
||||
const { refinerNegativeAestheticScore, shift } = useAppSelector(selector);
|
||||
|
||||
const isRefinerAvailable = useIsRefinerAvailable();
|
||||
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const handleChange = useCallback(
|
||||
(v: number) => dispatch(setRefinerNegativeAestheticScore(v)),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
const handleReset = useCallback(
|
||||
() => dispatch(setRefinerNegativeAestheticScore(2.5)),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
return (
|
||||
<IAISlider
|
||||
label="Negative Aesthetic Score"
|
||||
step={shift ? 0.1 : 0.5}
|
||||
min={1}
|
||||
max={10}
|
||||
onChange={handleChange}
|
||||
handleReset={handleReset}
|
||||
value={refinerNegativeAestheticScore}
|
||||
sliderNumberInputProps={{ max: 10 }}
|
||||
withInput
|
||||
withReset
|
||||
withSliderMarks
|
||||
isInteger={false}
|
||||
isDisabled={!isRefinerAvailable}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default memo(ParamSDXLRefinerNegativeAestheticScore);
|
@ -3,50 +3,50 @@ import { stateSelector } from 'app/store/store';
|
||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
|
||||
import IAISlider from 'common/components/IAISlider';
|
||||
import { setRefinerAestheticScore } from 'features/sdxl/store/sdxlSlice';
|
||||
import { setRefinerPositiveAestheticScore } from 'features/sdxl/store/sdxlSlice';
|
||||
import { memo, useCallback } from 'react';
|
||||
import { useIsRefinerAvailable } from 'services/api/hooks/useIsRefinerAvailable';
|
||||
|
||||
const selector = createSelector(
|
||||
[stateSelector],
|
||||
({ sdxl, hotkeys }) => {
|
||||
const { refinerAestheticScore } = sdxl;
|
||||
const { refinerPositiveAestheticScore } = sdxl;
|
||||
const { shift } = hotkeys;
|
||||
|
||||
return {
|
||||
refinerAestheticScore,
|
||||
refinerPositiveAestheticScore,
|
||||
shift,
|
||||
};
|
||||
},
|
||||
defaultSelectorOptions
|
||||
);
|
||||
|
||||
const ParamSDXLRefinerAestheticScore = () => {
|
||||
const { refinerAestheticScore, shift } = useAppSelector(selector);
|
||||
const ParamSDXLRefinerPositiveAestheticScore = () => {
|
||||
const { refinerPositiveAestheticScore, shift } = useAppSelector(selector);
|
||||
|
||||
const isRefinerAvailable = useIsRefinerAvailable();
|
||||
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const handleChange = useCallback(
|
||||
(v: number) => dispatch(setRefinerAestheticScore(v)),
|
||||
(v: number) => dispatch(setRefinerPositiveAestheticScore(v)),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
const handleReset = useCallback(
|
||||
() => dispatch(setRefinerAestheticScore(6)),
|
||||
() => dispatch(setRefinerPositiveAestheticScore(6)),
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
return (
|
||||
<IAISlider
|
||||
label="Aesthetic Score"
|
||||
label="Positive Aesthetic Score"
|
||||
step={shift ? 0.1 : 0.5}
|
||||
min={1}
|
||||
max={10}
|
||||
onChange={handleChange}
|
||||
handleReset={handleReset}
|
||||
value={refinerAestheticScore}
|
||||
value={refinerPositiveAestheticScore}
|
||||
sliderNumberInputProps={{ max: 10 }}
|
||||
withInput
|
||||
withReset
|
||||
@ -57,4 +57,4 @@ const ParamSDXLRefinerAestheticScore = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default memo(ParamSDXLRefinerAestheticScore);
|
||||
export default memo(ParamSDXLRefinerPositiveAestheticScore);
|
@ -16,7 +16,8 @@ type SDXLInitialState = {
|
||||
refinerSteps: number;
|
||||
refinerCFGScale: number;
|
||||
refinerScheduler: SchedulerParam;
|
||||
refinerAestheticScore: number;
|
||||
refinerPositiveAestheticScore: number;
|
||||
refinerNegativeAestheticScore: number;
|
||||
refinerStart: number;
|
||||
};
|
||||
|
||||
@ -30,7 +31,8 @@ const sdxlInitialState: SDXLInitialState = {
|
||||
refinerSteps: 20,
|
||||
refinerCFGScale: 7.5,
|
||||
refinerScheduler: 'euler',
|
||||
refinerAestheticScore: 6,
|
||||
refinerPositiveAestheticScore: 6,
|
||||
refinerNegativeAestheticScore: 2.5,
|
||||
refinerStart: 0.7,
|
||||
};
|
||||
|
||||
@ -68,8 +70,17 @@ const sdxlSlice = createSlice({
|
||||
setRefinerScheduler: (state, action: PayloadAction<SchedulerParam>) => {
|
||||
state.refinerScheduler = action.payload;
|
||||
},
|
||||
setRefinerAestheticScore: (state, action: PayloadAction<number>) => {
|
||||
state.refinerAestheticScore = action.payload;
|
||||
setRefinerPositiveAestheticScore: (
|
||||
state,
|
||||
action: PayloadAction<number>
|
||||
) => {
|
||||
state.refinerPositiveAestheticScore = action.payload;
|
||||
},
|
||||
setRefinerNegativeAestheticScore: (
|
||||
state,
|
||||
action: PayloadAction<number>
|
||||
) => {
|
||||
state.refinerNegativeAestheticScore = action.payload;
|
||||
},
|
||||
setRefinerStart: (state, action: PayloadAction<number>) => {
|
||||
state.refinerStart = action.payload;
|
||||
@ -87,7 +98,8 @@ export const {
|
||||
setRefinerSteps,
|
||||
setRefinerCFGScale,
|
||||
setRefinerScheduler,
|
||||
setRefinerAestheticScore,
|
||||
setRefinerPositiveAestheticScore,
|
||||
setRefinerNegativeAestheticScore,
|
||||
setRefinerStart,
|
||||
} = sdxlSlice.actions;
|
||||
|
||||
|
@ -1209,10 +1209,15 @@ export type components = {
|
||||
*/
|
||||
refiner_scheduler?: string;
|
||||
/**
|
||||
* Refiner Aesthetic Store
|
||||
* Refiner Positive Aesthetic Store
|
||||
* @description The aesthetic score used for the refiner
|
||||
*/
|
||||
refiner_aesthetic_store?: number;
|
||||
refiner_positive_aesthetic_store?: number;
|
||||
/**
|
||||
* Refiner Negative Aesthetic Store
|
||||
* @description The aesthetic score used for the refiner
|
||||
*/
|
||||
refiner_negative_aesthetic_store?: number;
|
||||
/**
|
||||
* Refiner Start
|
||||
* @description The start value used for refiner denoising
|
||||
@ -3599,10 +3604,15 @@ export type components = {
|
||||
*/
|
||||
refiner_scheduler?: string;
|
||||
/**
|
||||
* Refiner Aesthetic Store
|
||||
* Refiner Positive Aesthetic Score
|
||||
* @description The aesthetic score used for the refiner
|
||||
*/
|
||||
refiner_aesthetic_store?: number;
|
||||
refiner_positive_aesthetic_score?: number;
|
||||
/**
|
||||
* Refiner Negative Aesthetic Score
|
||||
* @description The aesthetic score used for the refiner
|
||||
*/
|
||||
refiner_negative_aesthetic_score?: number;
|
||||
/**
|
||||
* Refiner Start
|
||||
* @description The start value used for refiner denoising
|
||||
@ -5781,11 +5791,11 @@ export type components = {
|
||||
image?: components["schemas"]["ImageField"];
|
||||
};
|
||||
/**
|
||||
* StableDiffusionOnnxModelFormat
|
||||
* ControlNetModelFormat
|
||||
* @description An enumeration.
|
||||
* @enum {string}
|
||||
*/
|
||||
StableDiffusionOnnxModelFormat: "olive" | "onnx";
|
||||
ControlNetModelFormat: "checkpoint" | "diffusers";
|
||||
/**
|
||||
* StableDiffusion2ModelFormat
|
||||
* @description An enumeration.
|
||||
@ -5793,23 +5803,23 @@ export type components = {
|
||||
*/
|
||||
StableDiffusion2ModelFormat: "checkpoint" | "diffusers";
|
||||
/**
|
||||
* ControlNetModelFormat
|
||||
* StableDiffusionXLModelFormat
|
||||
* @description An enumeration.
|
||||
* @enum {string}
|
||||
*/
|
||||
ControlNetModelFormat: "checkpoint" | "diffusers";
|
||||
StableDiffusionXLModelFormat: "checkpoint" | "diffusers";
|
||||
/**
|
||||
* StableDiffusionOnnxModelFormat
|
||||
* @description An enumeration.
|
||||
* @enum {string}
|
||||
*/
|
||||
StableDiffusionOnnxModelFormat: "olive" | "onnx";
|
||||
/**
|
||||
* StableDiffusion1ModelFormat
|
||||
* @description An enumeration.
|
||||
* @enum {string}
|
||||
*/
|
||||
StableDiffusion1ModelFormat: "checkpoint" | "diffusers";
|
||||
/**
|
||||
* StableDiffusionXLModelFormat
|
||||
* @description An enumeration.
|
||||
* @enum {string}
|
||||
*/
|
||||
StableDiffusionXLModelFormat: "checkpoint" | "diffusers";
|
||||
};
|
||||
responses: never;
|
||||
parameters: never;
|
||||
|
Loading…
Reference in New Issue
Block a user