code: def f1_score_with_invalid(
      target: np.ndarray, prediction: np.ndarray
  ) -> Dict[str, float]:
      """Compute F1 score, but any prediction != 0 or 1 is counted as incorrect.
  
      Args:
        target: Numpy array of targets, either 0 or 1 (binary label space).
        prediction: Numpy array of model predictions, any integer value.
  
      Returns:
        F1 score, where any prediction != 0 or 1 is counted as wrong.
      """
      # Get indices of invalid predictions:
      invalid_idx_mask = np.logical_and(
          prediction != 0, prediction != 1
      )
      # For any prediction != 0 or 1, set it to the opposite of what the target is:
      prediction[invalid_idx_mask] = 1 - target[invalid_idx_mask]
      return {"f1": sklearn.metrics.f1_score(target, prediction)}
  
imports: import functools
  from typing import Any, Dict, List, Mapping, Optional, Tuple, Union
  from absl import logging
  from clu import metric_writers
  import flax
  from flax import jax_utils
  import flax.linen
  import jax
  import jax.numpy
  import jax.profiler
  import ml_collections
  import numpy
  from scenic.common_lib import debug_utils
  from scenic.train_lib import optimizers
  from scenic.train_lib import train_utils
  import scipy
  import sklearn.metrics
label_desc: Use image node_id 1 for calling a global function with example usage: f1_score_with_invalid(target, prediction) and returns: dict