mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): convert t2i to cnet and vice-versa when model changes
This commit is contained in:
parent
54acd3f2b1
commit
6f572e1cce
@ -12,7 +12,12 @@ import type {
|
|||||||
ProcessorConfig,
|
ProcessorConfig,
|
||||||
T2IAdapterConfig,
|
T2IAdapterConfig,
|
||||||
} from 'features/controlLayers/util/controlAdapters';
|
} from 'features/controlLayers/util/controlAdapters';
|
||||||
import { buildControlAdapterProcessor, imageDTOToImageWithDims } from 'features/controlLayers/util/controlAdapters';
|
import {
|
||||||
|
buildControlAdapterProcessor,
|
||||||
|
controlNetToT2IAdapter,
|
||||||
|
imageDTOToImageWithDims,
|
||||||
|
t2iAdapterToControlNet,
|
||||||
|
} from 'features/controlLayers/util/controlAdapters';
|
||||||
import { zModelIdentifierField } from 'features/nodes/types/common';
|
import { zModelIdentifierField } from 'features/nodes/types/common';
|
||||||
import { calculateNewSize } from 'features/parameters/components/ImageSize/calculateNewSize';
|
import { calculateNewSize } from 'features/parameters/components/ImageSize/calculateNewSize';
|
||||||
import { initialAspectRatioState } from 'features/parameters/components/ImageSize/constants';
|
import { initialAspectRatioState } from 'features/parameters/components/ImageSize/constants';
|
||||||
@ -284,6 +289,14 @@ export const controlLayersSlice = createSlice({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
layer.controlAdapter.model = zModelIdentifierField.parse(modelConfig);
|
layer.controlAdapter.model = zModelIdentifierField.parse(modelConfig);
|
||||||
|
|
||||||
|
// We may need to convert the CA to match the model
|
||||||
|
if (layer.controlAdapter.type === 't2i_adapter' && layer.controlAdapter.model.type === 'controlnet') {
|
||||||
|
layer.controlAdapter = t2iAdapterToControlNet(layer.controlAdapter);
|
||||||
|
} else if (layer.controlAdapter.type === 'controlnet' && layer.controlAdapter.model.type === 't2i_adapter') {
|
||||||
|
layer.controlAdapter = controlNetToT2IAdapter(layer.controlAdapter);
|
||||||
|
}
|
||||||
|
|
||||||
const candidateProcessorConfig = buildControlAdapterProcessor(modelConfig);
|
const candidateProcessorConfig = buildControlAdapterProcessor(modelConfig);
|
||||||
if (candidateProcessorConfig?.type !== layer.controlAdapter.processorConfig?.type) {
|
if (candidateProcessorConfig?.type !== layer.controlAdapter.processorConfig?.type) {
|
||||||
// The processor has changed. For example, the previous model was a Canny model and the new model is a Depth
|
// The processor has changed. For example, the previous model was a Canny model and the new model is a Depth
|
||||||
|
@ -4,7 +4,7 @@ import type {
|
|||||||
ParameterIPAdapterModel,
|
ParameterIPAdapterModel,
|
||||||
ParameterT2IAdapterModel,
|
ParameterT2IAdapterModel,
|
||||||
} from 'features/parameters/types/parameterSchemas';
|
} from 'features/parameters/types/parameterSchemas';
|
||||||
import { merge } from 'lodash-es';
|
import { merge, omit } from 'lodash-es';
|
||||||
import type {
|
import type {
|
||||||
BaseModelType,
|
BaseModelType,
|
||||||
CannyImageProcessorInvocation,
|
CannyImageProcessorInvocation,
|
||||||
@ -466,3 +466,18 @@ export const imageDTOToImageWithDims = ({ image_name, width, height }: ImageDTO)
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const t2iAdapterToControlNet = (t2iAdapter: T2IAdapterConfig): ControlNetConfig => {
|
||||||
|
return {
|
||||||
|
...deepClone(t2iAdapter),
|
||||||
|
type: 'controlnet',
|
||||||
|
controlMode: initialControlNet.controlMode,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const controlNetToT2IAdapter = (controlNet: ControlNetConfig): T2IAdapterConfig => {
|
||||||
|
return {
|
||||||
|
...omit(deepClone(controlNet), 'controlMode'),
|
||||||
|
type: 't2i_adapter',
|
||||||
|
};
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user