{"record":{"id":"c71aa6b40883b8d7","repo":"deepfakes/faceswap","slug":"the-output-size-of-the-selected-model-is-too-small","errorCode":null,"errorMessage":"The output size of the selected model is too small for MS-SSIM. Use SSIM instead.","messagePattern":"The output size of the selected model is too small for MS-SSIM\\. Use SSIM instead\\.","errorType":"validation","errorClass":"FaceswapError","httpStatus":null,"severity":"error","filePath":"lib/model/losses/perceptual_loss.py","lineNumber":455,"sourceCode":"        if self._validated:\n            return\n        im_size = image.shape[2]\n        smallest_scale = self._get_smallest_size(im_size, len(self._power_factors) - 1)\n        kernel_size = self._kernel.shape[-1]\n\n        if smallest_scale >= kernel_size:\n            logger.info(\"[MSSIM] Inbound images are valid. smallest_scale: %s, kernel_size: %s\",\n                        smallest_scale, kernel_size)\n            self._validated = True\n            return\n\n        logger.warning(\"[MSSIM] Output size %spx is below 176px. The MS-SSIM kernel must be \"\n                       \"adjusted to accommodate. You will likely get better results using SSIM.\",\n                       im_size)\n        del self._kernel\n        flt = smallest_scale - 1 if smallest_scale % 2 == 0 else smallest_scale\n        if flt < 3:\n            raise FaceswapError(\"The output size of the selected model is too small for MS-SSIM. \"\n                                \"Use SSIM instead.\")\n        logger.debug(\"[MSSIM] Adjusting filter kernel to %s from %s for smallest scale %s.\",\n                     flt, kernel_size, smallest_scale)\n        self._kernel = self._fspecial_gauss(flt, self._filter_sigma).to(image.device)\n        self._validated = True\n\n    @classmethod\n    def _do_pad(cls, images: list[torch.Tensor], remainder: torch.Tensor) -> list[torch.Tensor]:\n        \"\"\"Pad images\n\n        Parameters\n        ----------\n        images\n            Images to pad (N,C,H,W)\n        remainder\n            Remaining images to pad (C,H,W)\n\n        Returns","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/lib/model/losses/perceptual_loss.py#L437-L473","documentation":"MSSIMLoss validates at first forward pass that the smallest down-scaled image is at least the Gaussian kernel size; for tiny model outputs it shrinks the kernel, but if the adjusted filter size would drop below 3px the loss cannot be computed and a FaceswapError advises switching to SSIM. The validation triggers on output images below roughly 176px and fails hard only for very small outputs.","triggerScenarios":"Training a model whose output size is very small (far below 176px) with loss_function=ms_ssim; custom models with tiny output dimensions hitting MSSIM's first batch validation.","commonSituations":"Low-resolution experimental model configurations; users preferring MS-SSIM accuracy on small-output architectures where it is mathematically unsupported.","solutions":["Switch the loss to 'ssim' as the message advises.","Or increase the model's output size above the MS-SSIM threshold (>=176px comfortably).","If a custom small model is required, use a different loss (mae/mse/lpips)."],"exampleFix":"# train config\n# before\nloss_function = ms_ssim  # output size 64px -> FaceswapError\n# after\nloss_function = ssim","handlingStrategy":"validation","validationCode":"MIN_OUTPUT_PX = 176\nassert model_output_size >= MIN_OUTPUT_PX or config.loss_function != 'ms_ssim', \\\n    'ms_ssim requires output >= 176px; use ssim'","typeGuard":null,"tryCatchPattern":"try:\n    loss = MSSIMLoss(...)\n    loss(sample_batch)  # trigger validation at setup, not mid-epoch\nexcept FaceswapError as err:\n    if 'MS-SSIM' in str(err):\n        loss = SSIMLoss(...)\n    else:\n        raise","preventionTips":["Pair ms_ssim only with models outputting >=176px.","Warm up the loss with a dummy batch during model build to fail fast.","Heed the 176px warning log — it precedes the hard failure."],"tags":["training","loss-function","image-size","config"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}