def create_model()

in 07_training/serverlessml/flowers/classifier/model.py [0:0]


def create_model(opts, IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS):
    regularizer = tf.keras.regularizers.l1_l2(opts['l1'] or 0, opts['l2'] or 0)
    
    layers = [
      tf.keras.layers.experimental.preprocessing.RandomCrop(
          height=MODEL_IMG_SIZE, width=MODEL_IMG_SIZE,
          input_shape=(IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS),
          name='random/center_crop'
      ),
      tf.keras.layers.experimental.preprocessing.RandomFlip(
          mode='horizontal',
          name='random_lr_flip/none'
      )
    ]
    
    if opts['with_color_distort']:
        layers.append(
            RandomColorDistortion(name='random_contrast_brightness/none')
        )
    
    layers += [
      hub.KerasLayer(
          "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4", 
          trainable=False,
          name='mobilenet_embedding'),
      tf.keras.layers.Dense(opts['num_hidden'] or 16,
                            kernel_regularizer=regularizer, 
                            activation=tf.keras.activations.relu,
                            name='dense_hidden'),
      tf.keras.layers.Dense(len(CLASS_NAMES), 
                            kernel_regularizer=regularizer,
                            activation='softmax',
                            name='flower_prob')
    ]

    # checkpoint and early stopping callbacks
    model_checkpoint_cb = tf.keras.callbacks.ModelCheckpoint(
        filepath='./chkpts',
        monitor='val_accuracy', mode='max',
        save_best_only=True)
    early_stopping_cb = tf.keras.callbacks.EarlyStopping(
        monitor='val_accuracy', mode='max',
        patience=2)
    
    # create model
    return tf.keras.Sequential(layers, name='flower_classification')