Skip to content

Commit de407f1

Browse files
lu-wang-gxunkai55
authored andcommitted
Fix Java API doc errors in TFLite Java Library and Support Library
PiperOrigin-RevId: 374126621
1 parent d49682b commit de407f1

File tree

17 files changed

+74
-70
lines changed

17 files changed

+74
-70
lines changed

tensorflow_lite_support/java/src/java/org/tensorflow/lite/support/audio/TensorAudio.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
* aggregated audio samples via `getTensorBuffer` method.
3838
*
3939
* <p>Note that this class can only handle input audio in Float (in {@link
40-
* AudioFormat#ENCODING_PCM_16BIT}) or Short (in {@link AudioFormat#ENCODING_PCM_FLOAT}). Internally
41-
* it converts and stores all the audio samples in PCM Float encoding.
40+
* android.media.AudioFormat#ENCODING_PCM_16BIT}) or Short (in {@link
41+
* android.media.AudioFormat#ENCODING_PCM_FLOAT}). Internally it converts and stores all the audio
42+
* samples in PCM Float encoding.
4243
*
4344
* <p>Typical usage in Kotlin
4445
*
@@ -48,7 +49,7 @@
4849
* interpreter.run(tensor.getTensorBuffer(), outputBuffer);
4950
* </pre>
5051
*
51-
* <p>Another sample usage with {@link AudioRecord}
52+
* <p>Another sample usage with {@link android.media.AudioRecord}
5253
*
5354
* <pre>
5455
* val tensor = TensorAudio.create(format, modelInputLength)
@@ -76,8 +77,8 @@ public static TensorAudio create(TensorAudioFormat format, int sampleCounts) {
7677
}
7778

7879
/**
79-
* Creates a {@link android.media.TensorAudio} instance with a ring buffer whose size is {@code
80-
* sampleCounts} * {@code format.getChannelCount()}.
80+
* Creates a {@link TensorAudio} instance with a ring buffer whose size is {@code sampleCounts} *
81+
* {@code format.getChannelCount()}.
8182
*
8283
* @param format the {@link android.media.AudioFormat} required by the TFLite model. It defines
8384
* the number of channels and sample rate.

tensorflow_lite_support/java/src/java/org/tensorflow/lite/support/common/FileUtil.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ public static List<String> loadSingleColumnTextFile(
130130

131131
/**
132132
* Loads vocabulary from an input stream of an opened vocabulary file (which is a single-column
133-
* text file). See details for vocabulary files in {@link FileUtil#loadVocabularyFile(Context,
134-
* String)}.
133+
* text file).
134+
*
135+
* <p>A vocabulary file is a single-column plain text file whose contents are split into lines,
136+
* and each line is an individual value. The file should be in assets of the context.
135137
*
136138
* @param inputStream the input stream of an opened vocabulary file.
137139
* @return a list of vocabulary words.
@@ -157,7 +159,7 @@ public static MappedByteBuffer loadMappedFile(@NonNull Context context, @NonNull
157159
SupportPreconditions.checkNotNull(context, "Context should not be null.");
158160
SupportPreconditions.checkNotNull(filePath, "File path cannot be null.");
159161
try (AssetFileDescriptor fileDescriptor = context.getAssets().openFd(filePath);
160-
FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor())) {
162+
FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor())) {
161163
FileChannel fileChannel = inputStream.getChannel();
162164
long startOffset = fileDescriptor.getStartOffset();
163165
long declaredLength = fileDescriptor.getDeclaredLength();

tensorflow_lite_support/java/src/java/org/tensorflow/lite/support/common/Processor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
package org.tensorflow.lite.support.common;
1717

18-
/**
19-
* Processes T object with prepared {@link Operator<T>}.
20-
*/
18+
/** Processes T object with prepared {@code Operator<T>}. */
2119
public interface Processor<T> {
2220
T process(T input);
2321
}

tensorflow_lite_support/java/src/java/org/tensorflow/lite/support/common/SequentialProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.checkerframework.checker.nullness.qual.NonNull;
2424

2525
/**
26-
* A processor base class that chains a serial of {@link Operator<T>} and executes them.
26+
* A processor base class that chains a serial of {@code Operator<T>} and executes them.
2727
*
2828
* <p>Typically, users could use its subclasses, e.g. {@link
2929
* org.tensorflow.lite.support.image.ImageProcessor} rather than directly use this one.

tensorflow_lite_support/java/src/java/org/tensorflow/lite/support/common/SupportPreconditions.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ public static int checkElementIndex(int index, int size, @Nullable String desc)
144144
*
145145
* @param expression a boolean expression
146146
* @throws IllegalStateException if {@code expression} is false
147-
* @see Verify#verify Verify.verify()
148147
*/
149148
public static void checkState(boolean expression) {
150149
if (!expression) {
@@ -160,7 +159,6 @@ public static void checkState(boolean expression) {
160159
* @param errorMessage the exception message to use if the check fails; will be converted to a
161160
* string using {@link String#valueOf(Object)}
162161
* @throws IllegalStateException if {@code expression} is false
163-
* @see Verify#verify Verify.verify()
164162
*/
165163
public static void checkState(boolean expression, @Nullable Object errorMessage) {
166164
if (!expression) {

tensorflow_lite_support/java/src/java/org/tensorflow/lite/support/common/TensorProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* </pre>
3030
*
3131
* @see TensorProcessor.Builder to build a {@link TensorProcessor} instance.
32-
* @see TensorProcessor#process(TensorBuffer) to apply the processor on a {@link TensorBuffer}.
32+
* @see TensorProcessor#process to apply the processor on a {@link TensorBuffer}.
3333
*/
3434
public class TensorProcessor extends SequentialProcessor<TensorBuffer> {
3535
private TensorProcessor(Builder builder) {

tensorflow_lite_support/java/src/java/org/tensorflow/lite/support/common/ops/CastOp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public class CastOp implements TensorOperator {
3434
* <p>When this Op is executed, if the original {@link TensorBuffer} is already in {@code
3535
* destinationType}, the original buffer will be directly returned.
3636
*
37-
* @param destinationType: The type of the casted {@link TensorBuffer}.
37+
* @param destinationType The type of the casted {@link TensorBuffer}.
3838
* @throws IllegalArgumentException if {@code destinationType} is neither {@link DataType#UINT8}
39-
* nor {@link DataType#FLOAT32}.
39+
* nor {@link DataType#FLOAT32}.
4040
*/
4141
public CastOp(DataType destinationType) {
4242
SupportPreconditions.checkArgument(

tensorflow_lite_support/java/src/java/org/tensorflow/lite/support/image/BoundingBoxUtil.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
/**
3030
* Helper class for converting values that represents bounding boxes into rectangles.
3131
*
32-
* <p>The class provides a static function to create bounding boxes as {@link RectF} from different
33-
* types of configurations.
32+
* <p>The class provides a static function to create bounding boxes as {@link
33+
* android.graphics.RectF} from different types of configurations.
3434
*
3535
* <p>Generally, a bounding box could be represented by 4 float values, but the values could be
3636
* interpreted in many ways. We now support 3 {@link Type} of configurations, and the order of
@@ -229,8 +229,7 @@ private static RectF getRectF(
229229
int imageWidth,
230230
CoordinateType coordinateType) {
231231
if (coordinateType == CoordinateType.PIXEL) {
232-
return new RectF(
233-
left, top, right, bottom);
232+
return new RectF(left, top, right, bottom);
234233
} else if (coordinateType == CoordinateType.RATIO) {
235234
return new RectF(
236235
left * imageWidth, top * imageHeight, right * imageWidth, bottom * imageHeight);

tensorflow_lite_support/java/src/java/org/tensorflow/lite/support/image/ColorSpaceType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ int getNumElements(int height, int width) {
159159
},
160160

161161
/**
162-
* YUV420 format corresponding to {@link ImageFormat#YUV_420_888}. The actual encoding format
163-
* (i.e. NV12 / Nv21 / YV12 / YV21) depends on the implementation of the image.
162+
* YUV420 format corresponding to {@link android.graphics.ImageFormat#YUV_420_888}. The actual
163+
* encoding format (i.e. NV12 / Nv21 / YV12 / YV21) depends on the implementation of the image.
164164
*
165165
* <p>Use this format only when you load an {@link android.media.Image}.
166166
*/

tensorflow_lite_support/java/src/java/org/tensorflow/lite/support/image/TensorImage.java

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@
3131
* <p>At present, only RGB images are supported, and the A channel is always ignored.
3232
*
3333
* <p>Details of data storage: a {@link TensorImage} object may have 2 potential sources of truth: a
34-
* {@link Bitmap} or a {@link TensorBuffer}. {@link TensorImage} maintains the state and only
35-
* converts one to the other when needed. A typical use case of {@link TensorImage} is to first load
36-
* a {@link Bitmap} image, then process it using {@link ImageProcessor}, and finally get the
37-
* underlying {@link ByteBuffer} of the {@link TensorBuffer} and feed it into the TFLite
38-
* interpreter.
34+
* {@link android.graphics.Bitmap} or a {@link TensorBuffer}. {@link TensorImage} maintains the
35+
* state and only converts one to the other when needed. A typical use case of {@link TensorImage}
36+
* is to first load a {@link android.graphics.Bitmap} image, then process it using {@link
37+
* ImageProcessor}, and finally get the underlying {@link ByteBuffer} of the {@link TensorBuffer}
38+
* and feed it into the TFLite interpreter.
3939
*
4040
* <p>IMPORTANT: to achieve the best performance, {@link TensorImage} avoids copying data whenever
4141
* it's possible. Therefore, it doesn't own its data. Callers should not modify data objects those
42-
* are passed to {@link TensorImage#load(Bitmap)} or {@link TensorImage#load(TensorBuffer)}.
42+
* are passed to {@link TensorImage#load(Bitmap)} or {@link TensorImage#load(TensorBuffer,
43+
* ColorSpaceType)}.
4344
*
4445
* <p>IMPORTANT: all methods are not proved thread-safe.
4546
*
@@ -87,10 +88,11 @@ public TensorImage(DataType dataType) {
8788
}
8889

8990
/**
90-
* Initializes a {@link TensorImage} object of {@link DataType#UINT8} with a {@link Bitmap} .
91+
* Initializes a {@link TensorImage} object of {@link DataType#UINT8} with a {@link
92+
* android.graphics.Bitmap} .
9193
*
92-
* @see TensorImage#load(Bitmap) for reusing the object when it's expensive to create objects
93-
* frequently, because every call of {@code fromBitmap} creates a new {@link TensorImage}.
94+
* @see #load(Bitmap) for reusing the object when it's expensive to create objects frequently,
95+
* because every call of {@code fromBitmap} creates a new {@link TensorImage}.
9496
*/
9597
public static TensorImage fromBitmap(Bitmap bitmap) {
9698
TensorImage image = new TensorImage();
@@ -113,11 +115,12 @@ public static TensorImage createFrom(TensorImage src, DataType dataType) {
113115
}
114116

115117
/**
116-
* Loads a {@link Bitmap} image object into this {@link TensorImage}.
118+
* Loads a {@link android.graphics.Bitmap} image object into this {@link TensorImage}.
117119
*
118120
* <p>Note: if the {@link TensorImage} has data type other than {@link DataType#UINT8}, numeric
119121
* casting and clamping will be applied when calling {@link #getTensorBuffer} and {@link
120-
* #getBuffer}, where the {@link Bitmap} will be converted into a {@link TensorBuffer}.
122+
* #getBuffer}, where the {@link android.graphics.Bitmap} will be converted into a {@link
123+
* TensorBuffer}.
121124
*
122125
* <p>Important: when loading a bitmap, DO NOT MODIFY the bitmap from the caller side anymore. The
123126
* {@link TensorImage} object will rely on the bitmap. It will probably modify the bitmap as well.
@@ -183,9 +186,9 @@ public void load(TensorBuffer buffer) {
183186
}
184187

185188
/**
186-
* Loads a {@link TensorBuffer} containing pixel values with the specific {@link ColorSapceType}.
189+
* Loads a {@link TensorBuffer} containing pixel values with the specific {@link ColorSpaceType}.
187190
*
188-
* <p>Only supports {@link ColorSapceType#RGB} and {@link ColorSpaceType#GRAYSCALE}. Use {@link
191+
* <p>Only supports {@link ColorSpaceType#RGB} and {@link ColorSpaceType#GRAYSCALE}. Use {@link
189192
* #load(TensorBuffer, ImageProperties)} for other color space types.
190193
*
191194
* <p>Note: if the data type of {@code buffer} does not match that of this {@link TensorImage},
@@ -196,7 +199,6 @@ public void load(TensorBuffer buffer) {
196199
* (1, h, w, 3) for RGB images, and either (h, w) or (1, h, w) for GRAYSCALE images
197200
* @throws IllegalArgumentException if the shape of buffer does not match the color space type, or
198201
* if the color space type is not supported
199-
* @see ColorSpaceType#assertShape
200202
*/
201203
public void load(TensorBuffer buffer, ColorSpaceType colorSpaceType) {
202204
checkArgument(
@@ -241,22 +243,23 @@ public void load(ByteBuffer buffer, ImageProperties imageProperties) {
241243
}
242244

243245
/**
244-
* Loads an {@link Image} object into this {@link TensorImage}.
246+
* Loads an {@link android.media.Image} object into this {@link TensorImage}.
245247
*
246-
* <p>The main usage of this method is to load an {@link Image} object as model input to the <a
247-
* href="TFLite Task
248+
* <p>The main usage of this method is to load an {@link android.media.Image} object as model
249+
* input to the <a href="TFLite Task
248250
* Library">https://www.tensorflow.org/lite/inference_with_metadata/task_library/overview</a>.
249-
* {@link TensorImage} backed by {@link Image} is not supported by {#link ImageProcessor}.
251+
* {@link TensorImage} backed by {@link android.media.Image} is not supported by {#link
252+
* ImageProcessor}.
250253
*
251-
* <p>* @throws IllegalArgumentException if the {@link ImageFormat} of {@code image} is not
252-
* YUV_420_888
254+
* <p>* @throws IllegalArgumentException if the {@link android.graphics.ImageFormat} of {@code
255+
* image} is not YUV_420_888
253256
*/
254257
public void load(Image image) {
255258
container = MediaImageContainer.create(image);
256259
}
257260

258261
/**
259-
* Returns a {@link Bitmap} representation of this {@link TensorImage}.
262+
* Returns a {@link android.graphics.Bitmap} representation of this {@link TensorImage}.
260263
*
261264
* <p>Numeric casting and clamping will be applied if the stored data is not uint8.
262265
*
@@ -266,9 +269,9 @@ public void load(Image image) {
266269
* <p>Important: it's only a reference. DO NOT MODIFY. We don't create a copy here for performance
267270
* concern, but if modification is necessary, please make a copy.
268271
*
269-
* @return a reference to a {@link Bitmap} in {@code ARGB_8888} config ("A" channel is always
270-
* opaque) or in {@code ALPHA_8}, depending on the {@link ColorSpaceType} of this {@link
271-
* TensorBuffer}.
272+
* @return a reference to a {@link android.graphics.Bitmap} in {@code ARGB_8888} config ("A"
273+
* channel is always opaque) or in {@code ALPHA_8}, depending on the {@link ColorSpaceType} of
274+
* this {@link TensorBuffer}.
272275
* @throws IllegalStateException if the {@link TensorImage} never loads data
273276
*/
274277
public Bitmap getBitmap() {
@@ -320,17 +323,18 @@ public TensorBuffer getTensorBuffer() {
320323
}
321324

322325
/**
323-
* Returns an {@link Image} representation of this {@link TensorImage}.
326+
* Returns an {@link android.media.Image} representation of this {@link TensorImage}.
324327
*
325-
* <p>This method only works when the {@link TensorImage} is backed by an {@link Image}, meaning
326-
* you need to first load an {@link Image} through {@link TensorImage#load(Image)}.
328+
* <p>This method only works when the {@link TensorImage} is backed by an {@link
329+
* android.media.Image}, meaning you need to first load an {@link android.media.Image} through
330+
* {@link #load(Image)}.
327331
*
328332
* <p>Important: it's only a reference. DO NOT MODIFY. We don't create a copy here for performance
329333
* concern, but if modification is necessary, please make a copy.
330334
*
331-
* @return a reference to a {@link Bitmap} in {@code ARGB_8888} config ("A" channel is always
332-
* opaque) or in {@code ALPHA_8}, depending on the {@link ColorSpaceType} of this {@link
333-
* TensorBuffer}.
335+
* @return a reference to a {@link android.graphics.Bitmap} in {@code ARGB_8888} config ("A"
336+
* channel is always opaque) or in {@code ALPHA_8}, depending on the {@link ColorSpaceType} of
337+
* this {@link TensorBuffer}.
334338
* @throws IllegalStateException if the {@link TensorImage} never loads data
335339
*/
336340
public Image getMediaImage() {

0 commit comments

Comments
 (0)