{"record":{"id":"d6c047ef785f77ee","repo":"tensorflow/models","slug":"batch-size-has-to-be-an-integer-when-is-static-ist","errorCode":null,"errorMessage":"batch_size has to be an integer when is_static isTrue.","messagePattern":"batch_size has to be an integer when is_static isTrue\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/ops/sampling_ops.py","lineNumber":256,"sourceCode":"\n    Returns:\n      sampled_idx_indicator: boolean tensor of shape [N], True for entries which\n        are sampled. It ensures the length of output of the subsample is always\n        batch_size, even when number of examples set to True in indicator is\n        less than batch_size.\n\n    Raises:\n      ValueError: if labels and indicator are not 1D boolean tensors.\n    \"\"\"\n    # Check if indicator and labels have a static size.\n    if not indicator.shape.is_fully_defined():\n      raise ValueError('indicator must be static in shape when is_static is'\n                       'True')\n    if not labels.shape.is_fully_defined():\n      raise ValueError('labels must be static in shape when is_static is'\n                       'True')\n    if not isinstance(batch_size, int):\n      raise ValueError('batch_size has to be an integer when is_static is'\n                       'True.')\n\n    input_length = tf.shape(input=indicator)[0]\n\n    # Set the number of examples set True in indicator to be at least\n    # batch_size.\n    num_true_sampled = tf.reduce_sum(\n        input_tensor=tf.cast(indicator, tf.float32))\n    additional_false_sample = tf.less_equal(\n        tf.cumsum(tf.cast(tf.logical_not(indicator), tf.float32)),\n        batch_size - num_true_sampled)\n    indicator = tf.logical_or(indicator, additional_false_sample)\n\n    # Shuffle indicator and label. Need to store the permutation to restore the\n    # order post sampling.\n    permutation = tf.random.shuffle(tf.range(input_length))\n    indicator = matmul_gather_on_zeroth_axis(\n        tf.cast(indicator, tf.float32), permutation)","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/ops/sampling_ops.py#L238-L274","documentation":"Error \"batch_size has to be an integer when is_static isTrue.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/ops/sampling_ops.py:256 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass batch_size as a Python integer when is_static=True.","Set is_static=False if batch_size must be a dynamic tensor."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}