text: #!/usr/bin/python3
  import os
  import time
  import shutil
  import tensorflow as tf
  import tensorflow.neuron as tfn
  import tensorflow.compat.v1.keras as keras
  from tensorflow.keras.applications.resnet50 import ResNet50
  from tensorflow.keras.applications.resnet50 import preprocess_input
  
  # Create a workspace
  WORKSPACE = './ws_resnet50'
  os.makedirs(WORKSPACE, exist_ok=True)
  
  # Prepare export directory (old one removed)
  model_dir = os.path.join(WORKSPACE, 'resnet50')
  compiled_model_dir = os.path.join(WORKSPACE, 'resnet50_neuron')
  shutil.rmtree(model_dir, ignore_errors=True)
  shutil.rmtree(compiled_model_dir, ignore_errors=True)
  
  # Instantiate Keras ResNet50 model
  keras.backend.set_learning_phase(0)
  keras.backend.set_image_data_format('channels_last')
  
  model = ResNet50(weights='imagenet')
  
  # Export SavedModel
  tf.saved_model.simple_save(
      session            = keras.backend.get_session(),
      export_dir         = model_dir,
      inputs             = {'input': model.inputs[0]},
      outputs            = {'output': model.outputs[0]})
  
  # Compile using Neuron
  tfn.saved_model.compile(model_dir, compiled_model_dir)    
  
  # Prepare SavedModel for uploading to Inf1 instance
  shutil.make_archive('./resnet50_neuron', 'zip', WORKSPACE, 'resnet50_neuron')
  