Skip to content

Commit

Permalink
fix: limit UNet stride to tile size
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed May 4, 2023
1 parent 3b02fc5 commit e68e405
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion api/onnx_web/server/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,18 @@ def pipeline_from_request(
get_config_value("overlap", "max"),
get_config_value("overlap", "min"),
)
stride = get_and_clamp_float(
stride = get_and_clamp_int(
request.args,
"stride",
get_config_value("stride"),
get_config_value("stride", "max"),
get_config_value("stride", "min"),
)

if stride > tiles:
logger.info("limiting stride to tile size, %s > %s", stride, tiles)
stride = tiles

seed = int(request.args.get("seed", -1))
if seed == -1:
# this one can safely use np.random because it produces a single value
Expand Down
5 changes: 4 additions & 1 deletion gui/src/components/control/ImageControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export function ImageControl(props: ImageControlProps) {
staleTime: STALE_TIME,
});

// max stride is the lesser of tile size and server's max stride
const maxStride = Math.max(controlState.tiles, params.stride.max);

return <Stack spacing={2}>
<Stack direction='row' spacing={4}>
<QueryList
Expand Down Expand Up @@ -181,7 +184,7 @@ export function ImageControl(props: ImageControlProps) {
<NumericField
label={t('parameter.stride')}
min={params.stride.min}
max={params.stride.max}
max={maxStride}
step={params.stride.step}
value={controlState.stride}
onChange={(stride) => {
Expand Down
1 change: 1 addition & 0 deletions gui/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export function baseParamsFromServer(defaults: ServerParams): Required<BaseImgPa
tiledVAE: defaults.tiledVAE.default,
tiles: defaults.tiles.default,
overlap: defaults.overlap.default,
stride: defaults.stride.default,
};
}

Expand Down

0 comments on commit e68e405

Please sign in to comment.