mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-01 03:01:13 -04:00
preserve SDXL training values for bounding box
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import { roundToMultiple } from 'common/util/roundDownToMultiple';
|
||||
import type { Dimensions } from 'features/controlLayers/store/types';
|
||||
import type { MainModelBase } from 'features/nodes/types/common';
|
||||
import { getGridSize, getOptimalDimension } from 'features/parameters/util/optimalDimension';
|
||||
import {
|
||||
getGridSize,
|
||||
getOptimalDimension,
|
||||
isInSDXLTrainingDimensions,
|
||||
} from 'features/parameters/util/optimalDimension';
|
||||
|
||||
/**
|
||||
* Scales the bounding box dimensions to the optimal dimension. The optimal dimensions should be the trained dimension
|
||||
@@ -10,6 +14,11 @@ import { getGridSize, getOptimalDimension } from 'features/parameters/util/optim
|
||||
* @param modelBase The base model
|
||||
*/
|
||||
export const getScaledBoundingBoxDimensions = (dimensions: Dimensions, modelBase: MainModelBase): Dimensions => {
|
||||
// Special cases: Return original if SDXL and in training dimensions
|
||||
if (modelBase === 'sdxl' && isInSDXLTrainingDimensions(dimensions.width, dimensions.height)) {
|
||||
return { ...dimensions };
|
||||
}
|
||||
|
||||
const optimalDimension = getOptimalDimension(modelBase);
|
||||
const gridSize = getGridSize(modelBase);
|
||||
const width = roundToMultiple(dimensions.width, gridSize);
|
||||
|
||||
@@ -26,6 +26,40 @@ export const getOptimalDimension = (base?: BaseModelType | null): number => {
|
||||
}
|
||||
};
|
||||
|
||||
const SDXL_TRAINING_DIMENSIONS: [number, number][] = [
|
||||
[512, 2048],
|
||||
[512, 1984],
|
||||
[512, 1920],
|
||||
[512, 1856],
|
||||
[576, 1792],
|
||||
[576, 1728],
|
||||
[576, 1664],
|
||||
[640, 1600],
|
||||
[640, 1536],
|
||||
[704, 1472],
|
||||
[704, 1408],
|
||||
[704, 1344],
|
||||
[768, 1344],
|
||||
[768, 1280],
|
||||
[832, 1216],
|
||||
[832, 1152],
|
||||
[896, 1152],
|
||||
[896, 1088],
|
||||
[960, 1088],
|
||||
[960, 1024],
|
||||
[1024, 1024],
|
||||
];
|
||||
|
||||
/**
|
||||
* Checks if the given width and height are in the SDXL training dimensions.
|
||||
* @param width The width to check
|
||||
* @param height The height to check
|
||||
* @returns Whether the width and height are in the SDXL training dimensions (order agnostic)
|
||||
*/
|
||||
export const isInSDXLTrainingDimensions = (width: number, height: number): boolean => {
|
||||
return SDXL_TRAINING_DIMENSIONS.some(([w, h]) => (w === width && h === height) || (w === height && h === width));
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the grid size for a given base model. For Flux, the grid size is 16, otherwise it is 8.
|
||||
* - sd-1, sd-2, sdxl: 8
|
||||
|
||||
Reference in New Issue
Block a user