Edit TensorFlow model for inference

With IBM Spectrum Conductor Deep Learning Impact you can start a TensorFlow inference job from the cluster management console.

When you start an inference job using IBM Spectrum Conductor Deep Learning Impact, IBM Spectrum Conductor Deep Learning Impact looks for the inference.py file to run the job. e.

IBM Spectrum Conductor Deep Learning Impact passes the following arguments to the script:
  • --input_dir : Directory where to put the predicted images. Files that are submitted to the cluster management console are put in this directory.
    It is recommended to parse the command line arguments with tf.app.flags, for example:
    FLAGS = tf.app.flags.FLAGS
    tf.app.flags.DEFINE_string('input_dir', '',
      """Directory where to put the predicted images.""")
    ...
    imagefiles = glob.iglob(FLAGS.input_dir + '/*.*')
    
  • --output_dir: Directory where to put the inference result.
  • --output_file: File name of the inference result. This must use a JSON format.
    To parse the prediction results and show the results in the cluster management console, IBM Spectrum Conductor Deep Learning Impact requires that the results are saved to a JSON format, for example:
    {
        "type": "classification",
        "result": [
            {
                "prob": 0.616,
                "sampleId": "daisy.jpg",
                "label": "daisy"
            },
            {
                "prob": 0.169,
                "sampleId": "daisy.jpg",
                "label": "dandelion"
            },
    ...
            {
                "prob": 0.162,
                "sampleId": "tulips.jpg",
                "label": "sunflowers"
            }
        ]
    }
    
  • --model: The pre-trained model referring to the checkpoint.
  • --label_file: Labels of the image classes. Class names from class index 0, each name per line.
  • --prob_thresh: The prediction probability threshold to display.
  • --validate: Evaluating this model with validation dataset or not.
IBM Spectrum Conductor Deep Learning Impact includes a Python module to write the inference results to a file. For example:
import inference_helper
inference_helper.writeClassificationResult(result_file,
  imagenames, prediction,
  prob_thresh = FLAGS.prob_thresh,
  label_file = FLAGS.label_file)

Refer to API reference documentation for details and additional examples.