{"record":{"id":"f7758f8c935838bd","repo":"tensorflow/models","slug":"num-classes-should-be-given-when-requesting-one-f7758f","errorCode":null,"errorMessage":"`num_classes` should be given when requesting one hot label.","messagePattern":"`num_classes` should be given when requesting one hot label\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/dataloaders/video_input.py","lineNumber":199,"sourceCode":"      [batch * num_test_clips * num_test_crops, num_frames, height, width, 3].\n  \"\"\"\n  num_views = num_test_clips * num_test_crops\n  if num_views > 1 and not is_training:\n    # In this case, multiple views are merged together in batch dimension which\n    # will be batch * num_views.\n    image = tf.reshape(image, [-1, num_frames] + image.shape[2:].as_list())\n\n  return image\n\n\ndef process_label(label: tf.Tensor,\n                  one_hot_label: bool = True,\n                  num_classes: Optional[int] = None,\n                  label_dtype: tf.DType = tf.int32) -> tf.Tensor:\n  \"\"\"Processes label Tensor.\"\"\"\n  # Validate parameters.\n  if one_hot_label and not num_classes:\n    raise ValueError(\n        '`num_classes` should be given when requesting one hot label.')\n\n  # Cast to label_dtype (default = tf.int32).\n  label = tf.cast(label, dtype=label_dtype)\n\n  if one_hot_label:\n    # Replace label index by one hot representation.\n    label = tf.one_hot(label, num_classes)\n    if len(label.shape.as_list()) > 1:\n      label = tf.reduce_sum(label, axis=0)\n    if num_classes == 1:\n      # The trick for single label.\n      label = 1 - label\n\n  return label\n\n\nclass Decoder(decoder.Decoder):","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/dataloaders/video_input.py#L181-L217","documentation":"Error \"`num_classes` should be given when requesting one hot label.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/dataloaders/video_input.py:199 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"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"}