@@ -0,0 +1,2952 @@
+/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.%0A%0ALicensed under the Apache License, Version 2.0 (the %22License%22);%0Ayou may not use this file except in compliance with the License.%0AYou may obtain a copy of the License at%0A%0A    http://www.apache.org/licenses/LICENSE-2.0%0A%0AUnless required by applicable law or agreed to in writing, software%0Adistributed under the License is distributed on an %22AS IS%22 BASIS,%0AWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0ASee the License for the specific language governing permissions and%0Alimitations under the License.%0A==============================================================================*/%0A%0Apackage org.tensorflow.lite.support.label;%0A%0Aimport android.util.Log;%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport org.checkerframework.checker.nullness.qual.NonNull;%0Aimport org.tensorflow.lite.support.common.SupportPreconditions;%0Aimport org.tensorflow.lite.support.tensorbuffer.TensorBuffer;%0A%0A/** Label operation utils. */%0Apublic class LabelUtil %7B%0A  /**%0A   * Maps an int value tensor to a list of string labels. It takes an array of strings as the%0A   * dictionary. Example: if the given tensor is %5B3, 1, 0%5D, and given labels is %5B%22background%22,%0A   * %22apple%22, %22banana%22, %22cherry%22, %22date%22%5D, the result will be %5B%22date%22, %22banana%22, %22apple%22%5D.%0A   *%0A   * @param tensorBuffer: A tensor with index values. The values should be non-negative integers,%0A   *     and each value %7B@code x%7D will be converted to %7B@code labels%5Bx + offset%5D%7D. If the tensor is%0A   *     given as a float %7B@link TensorBuffer%7D, values will be cast to integers. All values that are%0A   *     out of bound will map to empty string.%0A   * @param labels: A list of strings, used as a dictionary to look up. The index of the array%0A   *     element will be used as the key. To get better performance, use an object that implements%0A   *     RandomAccess, such as %7B@link ArrayList%7D.%0A   * @param offset: The offset value when look up int values in the %7B@code labels%7D.%0A   * @return the mapped strings. The length of the list is %7B@link TensorBuffer#getFlatSize%7D.%0A   * @throws IllegalArgumentException if %7B@code tensorBuffer%7D or %7B@code labels%7D is null.%0A   */%0A  public static List%3CString%3E mapValueToLabels(%0A      @NonNull TensorBuffer tensorBuffer, @NonNull List%3CString%3E labels, int offset) %7B%0A    SupportPreconditions.checkNotNull(tensorBuffer, %22Given tensor should not be null%22);%0A    SupportPreconditions.checkNotNull(labels, %22Given labels should not be null%22);%0A    int%5B%5D values = tensorBuffer.getIntArray();%0A    Log.d(%22values%22, Arrays.toString(values));%0A    List%3CString%3E result = new ArrayList%3C%3E();%0A    for (int v : values) %7B%0A      int index = v + offset;%0A      if (index %3C 0 %7C%7C index %3E= labels.size()) %7B%0A        result.add(%22%22);%0A      %7D else %7B%0A        result.add(labels.get(index));%0A      %7D%0A    %7D%0A    return result;%0A  %7D%0A%0A  // Private constructor to prevent initialization.%0A  private LabelUtil() %7B%7D%0A%7D%0A

Add LabelUtils for Object Detection task.