code: def train(
      image_files,
      labels,
      domain,
      image_width=224,
      image_height=224,
      epochs=1,
      batch_size=16,
      test_ratio=0.2,
      seed=None,
  ):
      """
      Train VGG16 model on provided image files. This will create a new MLflow run and log all
      parameters, metrics and the resulting model with MLflow. The resulting model is an instance
      of KerasImageClassifierPyfunc - a custom python function model that embeds all necessary
      preprocessing together with the VGG16 Keras model. The resulting model can be applied
      directly to image base64 encoded image data.
  
      :param image_height: Height of the input image in pixels.
      :param image_width: Width of the input image in pixels.
      :param image_files: List of image files to be used for training.
      :param labels: List of labels for the image files.
      :param domain: Dictionary representing the domain of the response.
                     Provides mapping label-name -> label-id.
      :param epochs: Number of epochs to train the model for.
      :param batch_size: Batch size used during training.
      :param test_ratio: Fraction of dataset to be used for validation. This data will not be used
                         during training.
      :param seed: Random seed. Used e.g. when splitting the dataset into train / validation.
      """
      assert len(set(labels)) == len(domain)
  
      input_shape = (image_width, image_height, 3)
  
      with mlflow.start_run():
          mlflow.log_param("epochs", str(epochs))
          mlflow.log_param("batch_size", str(batch_size))
          mlflow.log_param("validation_ratio", str(test_ratio))
          if seed:
              mlflow.log_param("seed", str(seed))
  
          def _read_image(filename):
              with open(filename, "rb") as f:
                  return f.read()
  
          with tf.Graph().as_default() as g:
              with tf.compat.v1.Session(graph=g).as_default():
                  dims = input_shape[:2]
                  x = np.array(
                      [
                          decode_and_resize_image(_read_image(x), dims)
                          for x in image_files
                      ]
                  )
                  y = np_utils.to_categorical(
                      np.array(labels), num_classes=len(domain)
                  )
                  train_size = 1 - test_ratio
                  x_train, x_valid, y_train, y_valid = train_test_split(
                      x, y, random_state=seed, train_size=train_size
                  )
                  model = _create_model(
                      input_shape=input_shape, classes=len(domain)
                  )
                  model.compile(
                      optimizer=keras.optimizers.SGD(
                          decay=1e-5, nesterov=True, momentum=0.9
                      ),
                      loss=keras.losses.categorical_crossentropy,
                      metrics=["accuracy"],
                  )
                  sorted_domain = sorted(
                      domain.keys(), key=lambda x: domain[x]
                  )
                  model.fit(
                      x=x_train,
                      y=y_train,
                      validation_data=(x_valid, y_valid),
                      epochs=epochs,
                      batch_size=batch_size,
                      callbacks=[
                          MLflowLogger(
                              model=model,
                              x_train=x_train,
                              y_train=y_train,
                              x_valid=x_valid,
                              y_valid=y_valid,
                              artifact_path="model",
                              domain=sorted_domain,
                              image_dims=input_shape,
                          )
                      ],
                  )
  
imports: import math
  import os
  import tarfile
  import click
  import keras
  import numpy
  import tensorflow
  from image_pyfunc import decode_and_resize_image, log_model
  from keras.applications import vgg16
  from keras.callbacks import Callback
  from keras.layers import Dense, Flatten, Input, Lambda
  from keras.models import Model
  from keras.utils import np_utils
  from sklearn.model_selection import train_test_split
  import mlflow
  from mlflow.models import infer_signature
label_desc: Use image node_id 5 for calling a global function with example usage: train(image_files, labels, domain, image_width, image_height, epochs, batch_size, test_ratio, seed) and returns: f