'Function called by TF to save the prediction periodically.'

def write_disk_grid(self, global_step, log_dir, input_images, gt_projs, pred_projs, input_voxels=None, output_voxels=None):

    summary_freq = self._params.save_every
    def write_grid(input_images, gt_projs, pred_projs, global_step, input_voxels, output_voxels):
        'Native    python    function    to    call    for    writing    images    to    files.'
        grid = _build_image_grid(input_images, gt_projs, pred_projs, input_voxels=input_voxels, output_voxels=output_voxels)
        if ((global_step % summary_freq) == 0):
            img_path = os.path.join(log_dir, ('%s.jpg' % str(global_step)))
            utils.save_image(grid, img_path)
        return grid
    save_op = tf.py_func(write_grid, [input_images, gt_projs, pred_projs, global_step, input_voxels, output_voxels], [tf.uint8], 'write_grid')[0]
    slim.summaries.add_image_summary(tf.expand_dims(save_op, axis=0), name='grid_vis')
    return save_op
