Skip to content

Commit ad24c20

Browse files
dunkeronihipsterusername
authored andcommitted
preserve SDXL training values for bounding box
1 parent 3fd28ce commit ad24c20

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

invokeai/frontend/web/src/features/controlLayers/util/getScaledBoundingBoxDimensions.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { roundToMultiple } from 'common/util/roundDownToMultiple';
22
import type { Dimensions } from 'features/controlLayers/store/types';
33
import type { MainModelBase } from 'features/nodes/types/common';
4-
import { getGridSize, getOptimalDimension } from 'features/parameters/util/optimalDimension';
4+
import {
5+
getGridSize,
6+
getOptimalDimension,
7+
isInSDXLTrainingDimensions,
8+
} from 'features/parameters/util/optimalDimension';
59

610
/**
711
* 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
1014
* @param modelBase The base model
1115
*/
1216
export const getScaledBoundingBoxDimensions = (dimensions: Dimensions, modelBase: MainModelBase): Dimensions => {
17+
// Special cases: Return original if SDXL and in training dimensions
18+
if (modelBase === 'sdxl' && isInSDXLTrainingDimensions(dimensions.width, dimensions.height)) {
19+
return { ...dimensions };
20+
}
21+
1322
const optimalDimension = getOptimalDimension(modelBase);
1423
const gridSize = getGridSize(modelBase);
1524
const width = roundToMultiple(dimensions.width, gridSize);

invokeai/frontend/web/src/features/parameters/util/optimalDimension.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,40 @@ export const getOptimalDimension = (base?: BaseModelType | null): number => {
2626
}
2727
};
2828

29+
const SDXL_TRAINING_DIMENSIONS: [number, number][] = [
30+
[512, 2048],
31+
[512, 1984],
32+
[512, 1920],
33+
[512, 1856],
34+
[576, 1792],
35+
[576, 1728],
36+
[576, 1664],
37+
[640, 1600],
38+
[640, 1536],
39+
[704, 1472],
40+
[704, 1408],
41+
[704, 1344],
42+
[768, 1344],
43+
[768, 1280],
44+
[832, 1216],
45+
[832, 1152],
46+
[896, 1152],
47+
[896, 1088],
48+
[960, 1088],
49+
[960, 1024],
50+
[1024, 1024],
51+
];
52+
53+
/**
54+
* Checks if the given width and height are in the SDXL training dimensions.
55+
* @param width The width to check
56+
* @param height The height to check
57+
* @returns Whether the width and height are in the SDXL training dimensions (order agnostic)
58+
*/
59+
export const isInSDXLTrainingDimensions = (width: number, height: number): boolean => {
60+
return SDXL_TRAINING_DIMENSIONS.some(([w, h]) => (w === width && h === height) || (w === height && h === width));
61+
};
62+
2963
/**
3064
* Gets the grid size for a given base model. For Flux, the grid size is 16, otherwise it is 8.
3165
* - sd-1, sd-2, sdxl: 8

0 commit comments

Comments
 (0)