{"record":{"id":"51e93cbf710d2eeb","repo":"tensorflow/models","slug":"only-all-or-backbone-can-be-used-to-initialize-51e93c","errorCode":null,"errorMessage":"Only 'all' or 'backbone' can be used to initialize the model.","messagePattern":"Only 'all' or 'backbone' can be used to initialize the model\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/tasks/image_classification.py","lineNumber":85,"sourceCode":"    \"\"\"Loads pretrained checkpoint.\"\"\"\n    if not self.task_config.init_checkpoint:\n      return\n\n    ckpt_dir_or_file = self.task_config.init_checkpoint\n    if tf.io.gfile.isdir(ckpt_dir_or_file):\n      ckpt_dir_or_file = tf.train.latest_checkpoint(ckpt_dir_or_file)\n\n    # Restoring checkpoint.\n    if self.task_config.init_checkpoint_modules == 'all':\n      ckpt = tf.train.Checkpoint(model=model)\n      status = ckpt.read(ckpt_dir_or_file)\n      status.expect_partial().assert_existing_objects_matched()\n    elif self.task_config.init_checkpoint_modules == 'backbone':\n      ckpt = tf.train.Checkpoint(backbone=model.backbone)\n      status = ckpt.read(ckpt_dir_or_file)\n      status.expect_partial().assert_existing_objects_matched()\n    else:\n      raise ValueError(\n          \"Only 'all' or 'backbone' can be used to initialize the model.\")\n\n    logging.info('Finished loading pretrained checkpoint from %s',\n                 ckpt_dir_or_file)\n\n  def build_inputs(\n      self,\n      params: exp_cfg.DataConfig,\n      input_context: Optional[tf.distribute.InputContext] = None\n  ) -> tf.data.Dataset:\n    \"\"\"Builds classification input.\"\"\"\n\n    num_classes = self.task_config.model.num_classes\n    input_size = self.task_config.model.input_size\n    image_field_key = self.task_config.train_data.image_field_key\n    label_field_key = self.task_config.train_data.label_field_key\n    is_multilabel = self.task_config.train_data.is_multilabel\n","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/tasks/image_classification.py#L67-L103","documentation":"Error \"Only 'all' or 'backbone' can be used to initialize the model.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/tasks/image_classification.py:85 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set the initialization mode to 'all' or 'backbone' when loading classification weights.","Check the init_checkpoint_modules config value."],"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"}