{"record":{"id":"5f2711af91f4cab7","repo":"roboflow/supervision","slug":"could-not-place-len-images-cv2-in-grid-with-siz","errorCode":null,"errorMessage":"Could not place {len(images_cv2)} in grid with size: {grid_size}.","messagePattern":"Could not place (.+?) in grid with size: (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/utils/image.py","lineNumber":856,"sourceCode":"    \"\"\"\n    if len(images) == 0:\n        raise ValueError(\"Could not create image tiles from empty list of images.\")\n    if return_type == \"auto\":\n        return_type = _negotiate_tiles_format(images=images)\n    tile_padding_color = unify_to_bgr(color=tile_padding_color)\n    tile_margin_color = unify_to_bgr(color=tile_margin_color)\n    images_cv2 = images_to_cv2(images=images)\n    if single_tile_size is None:\n        single_tile_size = _aggregate_images_shape(images=images_cv2, mode=tile_scaling)\n    resized_images = [\n        letterbox_image(\n            image=i, resolution_wh=single_tile_size, color=tile_padding_color\n        )\n        for i in images_cv2\n    ]\n    grid_size = _establish_grid_size(images=images_cv2, grid_size=grid_size)\n    if len(images_cv2) > grid_size[0] * grid_size[1]:\n        raise ValueError(\n            f\"Could not place {len(images_cv2)} in grid with size: {grid_size}.\"\n        )\n    if titles is not None:\n        titles = fill(sequence=titles, desired_size=len(images_cv2), content=None)\n    if isinstance(titles_anchors, list):\n        titles_anchors_sequence = titles_anchors\n    else:\n        titles_anchors_sequence = [titles_anchors]\n    titles_anchors = fill(\n        sequence=titles_anchors_sequence, desired_size=len(images_cv2), content=None\n    )\n    titles_color = unify_to_bgr(color=titles_color)\n    titles_background_color = unify_to_bgr(color=titles_background_color)\n    tiles_image = _generate_tiles(\n        images=resized_images,\n        grid_size=grid_size,\n        single_tile_size=single_tile_size,\n        tile_padding_color=tile_padding_color,","sourceCodeStart":838,"sourceCodeEnd":874,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/utils/image.py#L838-L874","documentation":"Raised by `sv.create_tiles` when the resolved `grid_size` (rows x cols) cannot hold all images — i.e. `len(images) > rows * cols`. This only happens when you pass an explicit `grid_size` that is too small; with `grid_size=None` the function auto-negotiates a size that fits.","triggerScenarios":"`sv.create_tiles(images=[im]*10, grid_size=(2, 2))` — 10 images into a 2x2 grid; passing a fixed grid tuned for an earlier, smaller batch; passing columns only (e.g. `(2, None)`) where the computed rows are insufficient.","commonSituations":"Hard-coding grid dimensions for a fixed number of camera feeds, then adding a feed; visualizing a variable number of crops with a constant grid; confusing (rows, cols) order so the product looks larger than it is.","solutions":["Pass `grid_size=None` and let supervision compute a fitting grid.","Or compute it: `cols = math.ceil(math.sqrt(len(images))); grid_size=(math.ceil(len(images)/cols), cols)`.","Double the intended order — verify whether your tuple is (rows, cols) as expected."],"exampleFix":"# before\nmontage = sv.create_tiles(images=images_10, grid_size=(2, 2))\n# after\nmontage = sv.create_tiles(images=images_10, grid_size=None)  # auto-fit","handlingStrategy":"validation","validationCode":"if grid_size is not None:\n    rows, cols = grid_size\n    assert rows * cols >= len(images), f'grid {grid_size} too small for {len(images)} images'","typeGuard":"def grid_fits(grid_size: tuple[int, int], n: int) -> bool:\n    rows, cols = grid_size\n    return rows * cols >= n","tryCatchPattern":null,"preventionTips":["Prefer grid_size=None and let supervision negotiate.","Compute grid from count when you must fix it.","Update hard-coded grids whenever the batch size changes."],"tags":["image","tiles","grid","capacity"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}