* Produces a short text string summarizing the prediction * Input prediction should be a list of {className: string, prediction: float} * objects. * @param {[{className: string, predictions: number}]} predictions ordered list * of objects, each with a prediction class and score
(predictions)
| 37 | * of objects, each with a prediction class and score |
| 38 | */ |
| 39 | function textContentFromPrediction(predictions) { |
| 40 | if (!predictions || predictions.length < 1) { |
| 41 | return `No prediction 🙁`; |
| 42 | } |
| 43 | // Confident. |
| 44 | if (predictions[0].probability >= HIGH_CONFIDENCE_THRESHOLD) { |
| 45 | return `😄 ${predictions[0].className}!`; |
| 46 | } |
| 47 | // Not Confident. |
| 48 | if (predictions[0].probability >= LOW_CONFIDENCE_THRESHOLD && |
| 49 | predictions[0].probability < HIGH_CONFIDENCE_THRESHOLD) { |
| 50 | return `${predictions[0].className}?...\n Maybe ${ |
| 51 | predictions[1].className}?`; |
| 52 | } |
| 53 | // Very not confident. |
| 54 | if (predictions[0].probability < LOW_CONFIDENCE_THRESHOLD) { |
| 55 | return `😕 ${predictions[0].className}????...\n Maybe ${ |
| 56 | predictions[1].className}????`; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns a list of all DOM image elements pointing to the provided srcUrl. |