code: def to_categorical(y, nb_classes=None):
      """to_categorical.
  
      Convert class vector (integers from 0 to nb_classes)
      to binary class matrix, for use with categorical_crossentropy.
  
      Arguments:
          y: `array`. Class vector to convert.
          nb_classes: `int`. The total number of classes.
      """
      if nb_classes:
          y = np.asarray(y, dtype="int32")
          if len(y.shape) > 2:
              print("Warning: data array ndim > 2")
          if len(y.shape) > 1:
              y = y.reshape(-1)
          Y = np.zeros((len(y), nb_classes))
          Y[np.arange(len(y)), y] = 1.0
          return Y
      else:
          y = np.array(y)
          return (y[:, None] == np.unique(y)).astype(np.float32)
  
imports: from __future__ import division, print_function, absolute_import
  import os
  import random
  import numpy
  from PIL import Image
  import pickle
  import csv
  import warnings
  import tensorflow.compat.v1
  from io import BytesIO
label_desc: Use image node_id 1 for calling a global function with example usage: to_categorical(y, nb_classes) and returns: Y, unknown