old_contents: import numpy as np
  import json
  
  from ..utils.data_utils import get_file
  from .. import backend as K
  
  CLASS_INDEX = None
  CLASS_INDEX_PATH = 'https://s3.amazonaws.com/deep-learning-models/image-models/imagenet_class_index.json'
  
  
  def preprocess_input(x, dim_ordering='default'):
      if dim_ordering == 'default':
          dim_ordering = K.image_dim_ordering()
      assert dim_ordering in {'tf', 'th'}
  
      if dim_ordering == 'th':
          # 'RGB'->'BGR'
          x = x[:, ::-1, :, :]
          # Zero-center by mean pixel
          x[:, 0, :, :] -= 103.939
          x[:, 1, :, :] -= 116.779
          x[:, 2, :, :] -= 123.68
      else:
          # 'RGB'->'BGR'
          x = x[:, :, :, ::-1]
          # Zero-center by mean pixel
          x[:, :, :, 0] -= 103.939
          x[:, :, :, 1] -= 116.779
          x[:, :, :, 2] -= 123.68
      return x
  
  
  def decode_predictions(preds, top=5):
      global CLASS_INDEX
      if len(preds.shape) != 2 or preds.shape[1] != 1000:
          raise ValueError('`decode_predictions` expects '
                           'a batch of predictions '
                           '(i.e. a 2D array of shape (samples, 1000)). '
                           'Found array with shape: ' + str(preds.shape))
      if CLASS_INDEX is None:
          fpath = get_file('imagenet_class_index.json',
                           CLASS_INDEX_PATH,
                           cache_subdir='models')
          CLASS_INDEX = json.load(open(fpath))
      results = []
      for pred in preds:
          top_indices = pred.argsort()[-top:][::-1]
          result = [tuple(CLASS_INDEX[str(i)]) + (pred[i],) for i in top_indices]
          results.append(result)
      return results
  
new_contents: import numpy as np
  import json
  
  from ..utils.data_utils import get_file
  from .. import backend as K
  
  CLASS_INDEX = None
  CLASS_INDEX_PATH = 'https://s3.amazonaws.com/deep-learning-models/image-models/imagenet_class_index.json'
  
  
  def preprocess_input(x, dim_ordering='default'):
      if dim_ordering == 'default':
          dim_ordering = K.image_dim_ordering()
      assert dim_ordering in {'tf', 'th'}
  
      if dim_ordering == 'th':
          # 'RGB'->'BGR'
          x = x[:, ::-1, :, :]
          # Zero-center by mean pixel
          x[:, 0, :, :] -= 103.939
          x[:, 1, :, :] -= 116.779
          x[:, 2, :, :] -= 123.68
      else:
          # 'RGB'->'BGR'
          x = x[:, :, :, ::-1]
          # Zero-center by mean pixel
          x[:, :, :, 0] -= 103.939
          x[:, :, :, 1] -= 116.779
          x[:, :, :, 2] -= 123.68
      return x
  
  
  def decode_predictions(preds, top=5):
      global CLASS_INDEX
      if len(preds.shape) != 2 or preds.shape[1] != 1000:
          raise ValueError('`decode_predictions` expects '
                           'a batch of predictions '
                           '(i.e. a 2D array of shape (samples, 1000)). '
                           'Found array with shape: ' + str(preds.shape))
      if CLASS_INDEX is None:
          fpath = get_file('imagenet_class_index.json',
                           CLASS_INDEX_PATH,
                           cache_subdir='models')
          CLASS_INDEX = json.load(open(fpath))
      results = []
      for pred in preds:
          top_indices = pred.argsort()[-top:][::-1]
          result = [tuple(CLASS_INDEX[str(i)]) + (pred[i],) for i in top_indices]
          result.sort(key=lambda x: x[2], reverse=True)
          results.append(result)
      return results
  
subject: Make sure ImageNet predictions are sorted