def decode_predictions(preds, classes, top): if not classes: print("Warning! you didn't pass your own set of classes for the model therefore imagenet classes are used") return decode_imagenet_predictions(preds, top) if len(preds.shape) != 2 or preds.shape[1] != len(classes): raise ValueError('you need to provide same number of classes as model prediction output ' + \ 'model returns %s predictions, while there are %s classes' % ( preds.shape[1], len(classes))) results = [] for pred in preds: top_indices = pred.argsort()[-top:][::-1] result = [("", classes[i], pred[i]) for i in top_indices] results.append(result) return results