text: import os
  import re
  import zipfile
  
  import numpy as np
  import tensorflow as tf
  from tensorflow import keras
  
  import matplotlib.pyplot as plt
  import tensorflow_datasets as tfds
  from utils import *
  from anchorbox import *
  from configs import *
  from backbone import *
  from loss import *
  from preprocess import *
  from callbacks import *
  
  """
  ## Downloading the COCO2017 dataset
  Training on the entire COCO2017 dataset which has around 118k images takes a
  lot of time, hence we will be using a smaller subset of ~500 images for
  training in this example.
  """
  
  url = "https://github.com/srihari-humbarwadi/datasets/releases/download/v0.1.0/data.zip"
  filename = os.path.join(os.getcwd(), "data.zip")
  keras.utils.get_file(filename, url)
  
  
  with zipfile.ZipFile("data.zip", "r") as z_fp:
      z_fp.extractall("./")
  
  
  """
  ## Initializing and compiling model
  """
  
  resnet50_backbone = get_backbone()
  loss_fn = RetinaNetLoss(num_classes)
  model = RetinaNet(num_classes, resnet50_backbone)
  
  optimizer = tf.optimizers.SGD(learning_rate=learning_rate_fn, momentum=0.9)
  model.compile(loss=loss_fn, optimizer=optimizer)
  
  """
  ## Load the COCO2017 dataset using TensorFlow Datasets
  """
  
  #  set `data_dir=None` to load the complete dataset
  
  (train_dataset, val_dataset), dataset_info = tfds.load(
      "coco/2017", split=["train", "validation"], with_info=True, data_dir="data"
  )
  
  """
  ## Setting up a `tf.data` pipeline
  To ensure that the model is fed with data efficiently we will be using
  `tf.data` API to create our input pipeline. The input pipeline
  consists for the following major processing steps:
  - Apply the preprocessing function to the samples
  - Create batches with fixed batch size. Since images in the batch can
  have different dimensions, and can also have different number of
  objects, we use `padded_batch` to the add the necessary padding to create
  rectangular tensors
  - Create targets for each sample in the batch using `LabelEncoder`
  """
  
  autotune = tf.data.AUTOTUNE
  train_dataset = train_dataset.map(preprocess_data, num_parallel_calls=autotune)
  train_dataset = train_dataset.shuffle(8 * batch_size)
  train_dataset = train_dataset.padded_batch(
      batch_size=batch_size, padding_values=(0.0, 1e-8, -1), drop_remainder=True
  )
  train_dataset = train_dataset.map(
      label_encoder.encode_batch, num_parallel_calls=autotune
  )
  train_dataset = train_dataset.apply(tf.data.experimental.ignore_errors())
  train_dataset = train_dataset.prefetch(autotune)
  
  val_dataset = val_dataset.map(preprocess_data, num_parallel_calls=autotune)
  val_dataset = val_dataset.padded_batch(
      batch_size=1, padding_values=(0.0, 1e-8, -1), drop_remainder=True
  )
  val_dataset = val_dataset.map(label_encoder.encode_batch, num_parallel_calls=autotune)
  val_dataset = val_dataset.apply(tf.data.experimental.ignore_errors())
  val_dataset = val_dataset.prefetch(autotune)
  
  """
  ## Training the model
  """
  
  # Uncomment the following lines, when training on full dataset
  # train_steps_per_epoch = dataset_info.splits["train"].num_examples // batch_size
  # val_steps_per_epoch = \
  #     dataset_info.splits["validation"].num_examples // batch_size
  
  # train_steps = 4 * 100000
  # epochs = train_steps // train_steps_per_epoch
  
  epochs = 1
  
  # Running 100 training and 50 validation steps,
  # remove `.take` when training on the full dataset
  
  model.fit(
      train_dataset.take(100),
      validation_data=val_dataset.take(50),
      epochs=epochs,
      callbacks=callbacks_list,
      verbose=1,
  )
  
  