code: def _freeze_model_by_percentage(
      model: tf.keras.Model, percentage: float
  ):
      """Freeze part of the model based on specified percentage.
  
      Args:
        model: The keras model need to be partially frozen
        percentage: the percentage of layers to freeze
  
      Raises:
        ValueError: Invalid values.
      """
      if percentage < 0 or percentage > 1:
          raise ValueError(
              "Freeze percentage should between 0.0 and 1.0"
          )
  
      if not model.trainable:
          raise ValueError(
              "The model is not trainable, please set model.trainable to True"
          )
  
      num_layers = len(model.layers)
      num_layers_to_freeze = int(num_layers * percentage)
      for idx, layer in enumerate(model.layers):
          if idx < num_layers_to_freeze:
              layer.trainable = False
          else:
              layer.trainable = True
  
imports: import os
  from typing import List
  import absl
  import flatbuffers
  import tensorflow
  import tensorflow_transform
  from tfx.components.trainer.fn_args_utils import DataAccessor
  from tfx.components.trainer.fn_args_utils import FnArgs
  from tfx.components.trainer.rewriting import converters
  from tfx.components.trainer.rewriting import rewriter
  from tfx.components.trainer.rewriting import rewriter_factory
  from tfx.dsl.io import fileio
  from tfx_bsl.tfxio import dataset_options
  from tflite_support import metadata_schema_py_generated
  from tflite_support import metadata
label_desc: Use image node_id 6 for calling a global function with example usage: _freeze_model_by_percentage(model, percentage) without return types