{"record":{"id":"4d142341126666e9","repo":"keras-team/keras","slug":"weights-path-undefined","errorCode":null,"errorMessage":"weights_path undefined","messagePattern":"weights_path undefined","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/applications/densenet.py","lineNumber":293,"sourceCode":"                    cache_subdir=\"models\",\n                    file_hash=\"9d60b8095a5708f2dcce2bca79d332c7\",\n                )\n            elif blocks == [6, 12, 32, 32]:\n                weights_path = file_utils.get_file(\n                    \"densenet169_weights_tf_dim_ordering_tf_kernels.h5\",\n                    DENSENET169_WEIGHT_PATH,\n                    cache_subdir=\"models\",\n                    file_hash=\"d699b8f76981ab1b30698df4c175e90b\",\n                )\n            elif blocks == [6, 12, 48, 32]:\n                weights_path = file_utils.get_file(\n                    \"densenet201_weights_tf_dim_ordering_tf_kernels.h5\",\n                    DENSENET201_WEIGHT_PATH,\n                    cache_subdir=\"models\",\n                    file_hash=\"1ceb130c1ea1b78c3bf6114dbdfd8807\",\n                )\n            else:\n                raise ValueError(\"weights_path undefined\")\n        else:\n            if blocks == [6, 12, 24, 16]:\n                weights_path = file_utils.get_file(\n                    \"densenet121_weights_tf_dim_ordering_tf_kernels_notop.h5\",\n                    DENSENET121_WEIGHT_PATH_NO_TOP,\n                    cache_subdir=\"models\",\n                    file_hash=\"30ee3e1110167f948a6b9946edeeb738\",\n                )\n            elif blocks == [6, 12, 32, 32]:\n                weights_path = file_utils.get_file(\n                    \"densenet169_weights_tf_dim_ordering_tf_kernels_notop.h5\",\n                    DENSENET169_WEIGHT_PATH_NO_TOP,\n                    cache_subdir=\"models\",\n                    file_hash=\"b8c4d4c20dd625c148057b9ff1c1176b\",\n                )\n            elif blocks == [6, 12, 48, 32]:\n                weights_path = file_utils.get_file(\n                    \"densenet201_weights_tf_dim_ordering_tf_kernels_notop.h5\",","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/applications/densenet.py#L275-L311","documentation":"The cropping operation's compute_output_spec only accepts rank-3 or rank-4 image tensors; any other rank raises this ValueError before cropping math runs.","triggerScenarios":"Calling ops.image.crop_images (or its layer) with rank-2 masks, rank-5 video tensors, or mis-shaped numpy inputs.","commonSituations":"Grayscale (H,W) masks without a channel axis; video batches; feeding flat feature vectors by mistake.","solutions":["Expand dims to (H,W,C) or (N,H,W,C)","For rank-5 data, loop/reshape frames to rank-4","Assert the rank before calling"],"exampleFix":"# before\nout = ops.image.crop_images(mask, ...)  # (H, W)\n# after\nout = ops.image.crop_images(mask[..., None], ...)  # (H, W, 1)","handlingStrategy":"type-guard","validationCode":"shape = ops.shape(images)\nif len(shape) == 2:\n    images = images[..., None]","typeGuard":"def has_image_rank(images) -> bool:\n    return len(images.shape) in (3, 4)","tryCatchPattern":"try:\n    out = ops.image.crop_images(images, ...)\nexcept ValueError as e:\n    if 'Invalid images rank' in str(e):\n        images = images[..., None]\n        out = ops.image.crop_images(images, ...)\n    else:\n        raise","preventionTips":["Always carry a channel axis in image pipelines","Assert rank before crop/pad ops"],"tags":["keras","rank-validation","cropping"],"backgroundTag":"tensor-rank-mismatch","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}