{"record":{"id":"4793d23a361bcbe0","repo":"tensorflow/models","slug":"num-classes-should-be-given-when-requesting-one","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/projects/video_ssl/dataloaders/video_ssl_input.py","lineNumber":199,"sourceCode":"    # together in batch dimenstion which will be 2 * batch.\n    image = tf.concat(tf.split(image, num_or_size_splits=2, axis=1), axis=0)\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 dimenstion 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) -> 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 tf.int32.\n  label = tf.cast(label, dtype=tf.int32)\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 Parser(video_input.Parser):","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/video_ssl/dataloaders/video_ssl_input.py#L181-L217","documentation":"Error \"`num_classes` should be given when requesting one hot label.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/video_ssl/dataloaders/video_ssl_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"}