{"record":{"id":"2c3a44f6a8d03ee0","repo":"keras-team/keras","slug":"input-shapes-x1-shape-and-x2-shape-must-match-2c3a44","errorCode":null,"errorMessage":"Input shapes {x1.shape} and {x2.shape} must match for PSNR calculation. ","messagePattern":"Input shapes (.+?) and (.+?) must match for PSNR calculation\\. ","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/numpy/nn.py","lineNumber":1346,"sourceCode":"        )\n    elif strategy == \"beam_search\":\n        return _ctc_beam_search_decode(\n            inputs,\n            sequence_lengths,\n            beam_width=beam_width,\n            top_paths=top_paths,\n            mask_index=mask_index,\n        )\n    else:\n        raise ValueError(\n            f\"Invalid strategy {strategy}. Supported values are \"\n            \"'greedy' and 'beam_search'.\"\n        )\n\n\ndef psnr(x1, x2, max_val):\n    if x1.shape != x2.shape:\n        raise ValueError(\n            f\"Input shapes {x1.shape} and {x2.shape} must \"\n            \"match for PSNR calculation. \"\n        )\n\n    max_val = convert_to_tensor(max_val, dtype=x2.dtype)\n    mse = np.mean(np.square(x1 - x2))\n    psnr = 20 * np.log10(max_val) - 10 * np.log10(mse)\n    return psnr\n\n\ndef _get_large_negative(dtype):\n    dtype = backend.standardize_dtype(dtype)\n    val = 65500.0 if dtype == \"float16\" else 3.38953e38\n    return np.asarray(val * -0.7, dtype=dtype)\n\n\ndef _apply_masks(logits, mask, is_causal):\n    if mask is None and not is_causal:","sourceCodeStart":1328,"sourceCodeEnd":1364,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/numpy/nn.py#L1328-L1364","documentation":"The NumPy `psnr` (peak signal-to-noise ratio) implementation requires the two images to have identical shapes because it compares them element-wise before computing the MSE log-ratio. This guard fires when `x1.shape != x2.shape`, i.e. the predicted and reference tensors do not cover the same pixel grid (different resolutions, channel counts, or batch sizes).","triggerScenarios":"Thrown at keras/src/backend/numpy/nn.py:1346 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Resize one image to match the other (e.g. keras.ops.image.resize) before computing PSNR","Fix a preprocessing or generation step that produced predictions at a different resolution or channel count than the ground truth","Crop or pad the images to a common shape if resizing would distort content"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}