overridefunanalyze(imageProxy: ImageProxy){...// TODO 2: Convert Image to Bitmap then to TensorImageval tfImage = TensorImage.fromBitmap(toBitmap(imageProxy))...}
对图像进行处理并生成结果,主要包含下述操作:
按照属性score对识别结果按照概率从高到低排序
列出最高k种可能的结果,k的结果由常量MAX_RESULT_DISPLAY定义
overridefunanalyze(imageProxy: ImageProxy){...// TODO 3: Process the image using the trained model, sort and pick out the top resultsval outputs = flowerModel.process(tfImage).probabilityAsCategoryList.apply{
sortByDescending { it.score }// Sort with highest confidence first}.take(MAX_RESULT_DISPLAY)// take the top results...}
overridefunanalyze(imageProxy: ImageProxy){...// TODO 4: Converting the top probability items into a list of recognitionsfor(output in outputs){
items.add(Recognition(output.label, output.score))}...}
将原先用于虚拟显示识别结果的代码注释掉或者删除
// START - Placeholder code at the start of the codelab. Comment this block of code out.for(i in0..MAX_RESULT_DISPLAY-1){
items.add(Recognition("Fake label $i", Random.nextFloat()))}// END - Placeholder code at the start of the codelab. Comment this block of code out.