{"record":{"id":"11e41749e33e7325","repo":"keras-team/keras","slug":"factor-argument-must-have-values-larger-than-1","errorCode":null,"errorMessage":"`factor` argument must have values larger than -1. Received: factor={factor}","messagePattern":"`factor` argument must have values larger than -1\\. Received: factor=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/legacy/layers.py","lineNumber":85,"sourceCode":"\n    def __init__(self, factor, interpolation=\"bilinear\", seed=None, **kwargs):\n        super().__init__(**kwargs)\n        self.seed_generator = backend.random.SeedGenerator(seed)\n        self.factor = factor\n        if isinstance(factor, (tuple, list)):\n            self.height_lower = factor[0]\n            self.height_upper = factor[1]\n        else:\n            self.height_lower = -factor\n            self.height_upper = factor\n\n        if self.height_upper < self.height_lower:\n            raise ValueError(\n                \"`factor` argument cannot have an upper bound lesser than the \"\n                f\"lower bound. Received: factor={factor}\"\n            )\n        if self.height_lower < -1.0 or self.height_upper < -1.0:\n            raise ValueError(\n                \"`factor` argument must have values larger than -1. \"\n                f\"Received: factor={factor}\"\n            )\n        self.interpolation = interpolation\n        self.seed = seed\n\n    def call(self, inputs, training=True):\n        inputs = tf.convert_to_tensor(inputs, dtype=self.compute_dtype)\n\n        def random_height_inputs(inputs):\n            \"\"\"Inputs height-adjusted with random ops.\"\"\"\n            inputs_shape = tf.shape(inputs)\n            img_hd = tf.cast(inputs_shape[-3], tf.float32)\n            img_wd = inputs_shape[-2]\n            height_factor = backend.random.uniform(\n                shape=[],\n                minval=(1.0 + self.height_lower),\n                maxval=(1.0 + self.height_upper),","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/legacy/layers.py#L67-L103","documentation":"RandomHeight scales image heights by a factor sampled from [height_lower, height_upper]; both bounds must exceed -1 so sampled factors stay meaningful (a factor of -1 would collapse the height to zero or negative). Passing factor <= -1, or a tuple containing such a value, triggers this ValueError in __init__.","triggerScenarios":"Constructing RandomHeight(factor=-1.0), factor=-1.2, or factor=(-1.5, 0.2); note a single positive n becomes (-n, n), so a lone value below -1 also fails.","commonSituations":"Misreading factor as a percentage and passing -50 for -50%; copy-pasting crop/zoom parameters from other domains into height scaling; symmetric ranges like (-2, 2) that exceed the domain.","solutions":["Keep both bounds strictly greater than -1, e.g. RandomHeight(factor=(-0.2, 0.3))","Express fractions as decimals in (-1, inf), e.g. -0.5 not -50","Validate factor bounds programmatically before constructing the layer"],"exampleFix":"# before\nlayer = RandomHeight(factor=(-1.5, 0.5))\n# after\nlayer = RandomHeight(factor=(-0.5, 0.5))","handlingStrategy":"validation","validationCode":"lo, hi = tuple(factor) if isinstance(factor, (tuple, list)) else (-factor, factor)\nassert lo > -1 and hi > -1, f'factor bounds must be > -1: {factor}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Express augmentation factors as fractions in (-1, inf)","Validate config files at load time before constructing layers"],"tags":["keras","data-augmentation","argument-validation","legacy","random-height"],"backgroundTag":"argument-out-of-range","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}