|
18 | 18 | package org.tensorflow.op;
|
19 | 19 |
|
20 | 20 | import java.util.List;
|
| 21 | +import org.tensorflow.ConcreteFunction; |
21 | 22 | import org.tensorflow.Operand;
|
22 | 23 | import org.tensorflow.ndarray.Shape;
|
23 | 24 | import org.tensorflow.op.data.AnonymousIterator;
|
24 | 25 | import org.tensorflow.op.data.BatchDataset;
|
25 | 26 | import org.tensorflow.op.data.ConcatenateDataset;
|
26 | 27 | import org.tensorflow.op.data.DeleteIterator;
|
27 | 28 | import org.tensorflow.op.data.DeserializeIterator;
|
| 29 | +import org.tensorflow.op.data.FilterDataset; |
| 30 | +import org.tensorflow.op.data.FlatMapDataset; |
| 31 | +import org.tensorflow.op.data.InterleaveDataset; |
28 | 32 | import org.tensorflow.op.data.Iterator;
|
29 | 33 | import org.tensorflow.op.data.IteratorGetNext;
|
30 | 34 | import org.tensorflow.op.data.IteratorGetNextAsOptional;
|
31 | 35 | import org.tensorflow.op.data.IteratorGetNextSync;
|
32 | 36 | import org.tensorflow.op.data.IteratorToStringHandle;
|
33 | 37 | import org.tensorflow.op.data.MakeIterator;
|
| 38 | +import org.tensorflow.op.data.MapDataset; |
| 39 | +import org.tensorflow.op.data.OneShotIterator; |
34 | 40 | import org.tensorflow.op.data.OptionalFromValue;
|
35 | 41 | import org.tensorflow.op.data.OptionalGetValue;
|
36 | 42 | import org.tensorflow.op.data.OptionalHasValue;
|
@@ -134,6 +140,75 @@ public DeserializeIterator deserializeIterator(Operand<? extends TType> resource
|
134 | 140 | return DeserializeIterator.create(scope, resourceHandle, serialized);
|
135 | 141 | }
|
136 | 142 |
|
| 143 | + /** |
| 144 | + * Creates a dataset containing elements of {@code input_dataset} matching {@code predicate}. |
| 145 | + * The {@code predicate} function must return a scalar boolean and accept the |
| 146 | + * following arguments: |
| 147 | + * <ul> |
| 148 | + * <li>One tensor for each component of an element of {@code input_dataset}.</li> |
| 149 | + * <li>One tensor for each value in {@code other_arguments}.</li> |
| 150 | + * </ul> |
| 151 | + * |
| 152 | + * @param inputDataset the inputDataset value |
| 153 | + * @param otherArguments A list of tensors, typically values that were captured when |
| 154 | + * building a closure for {@code predicate}. |
| 155 | + * @param predicate A function returning a scalar boolean. |
| 156 | + * @param outputTypes the value of the outputTypes property |
| 157 | + * @param outputShapes the value of the outputShapes property |
| 158 | + * @return a new instance of FilterDataset |
| 159 | + */ |
| 160 | + public FilterDataset filterDataset(Operand<? extends TType> inputDataset, |
| 161 | + Iterable<Operand<?>> otherArguments, ConcreteFunction predicate, |
| 162 | + List<Class<? extends TType>> outputTypes, List<Shape> outputShapes) { |
| 163 | + return FilterDataset.create(scope, inputDataset, otherArguments, predicate, outputTypes, outputShapes); |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * Creates a dataset that applies {@code f} to the outputs of {@code input_dataset}. |
| 168 | + * Unlike MapDataset, the {@code f} in FlatMapDataset is expected to return a |
| 169 | + * Dataset variant, and FlatMapDataset will flatten successive results |
| 170 | + * into a single Dataset. |
| 171 | + * |
| 172 | + * @param inputDataset the inputDataset value |
| 173 | + * @param otherArguments the otherArguments value |
| 174 | + * @param f A function mapping elements of {@code input_dataset}, concatenated with |
| 175 | + * {@code other_arguments}, to a Dataset variant that contains elements matching |
| 176 | + * {@code output_types} and {@code output_shapes}. |
| 177 | + * @param outputTypes the value of the outputTypes property |
| 178 | + * @param outputShapes the value of the outputShapes property |
| 179 | + * @return a new instance of FlatMapDataset |
| 180 | + */ |
| 181 | + public FlatMapDataset flatMapDataset(Operand<? extends TType> inputDataset, |
| 182 | + Iterable<Operand<?>> otherArguments, ConcreteFunction f, |
| 183 | + List<Class<? extends TType>> outputTypes, List<Shape> outputShapes) { |
| 184 | + return FlatMapDataset.create(scope, inputDataset, otherArguments, f, outputTypes, outputShapes); |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * Creates a dataset that applies {@code f} to the outputs of {@code input_dataset}. |
| 189 | + * Unlike MapDataset, the {@code f} in InterleaveDataset is expected to return |
| 190 | + * a Dataset variant, and InterleaveDataset will flatten successive |
| 191 | + * results into a single Dataset. Unlike FlatMapDataset, |
| 192 | + * InterleaveDataset will interleave sequences of up to {@code block_length} |
| 193 | + * consecutive elements from {@code cycle_length} input elements. |
| 194 | + * |
| 195 | + * @param inputDataset the inputDataset value |
| 196 | + * @param otherArguments the otherArguments value |
| 197 | + * @param cycleLength the cycleLength value |
| 198 | + * @param blockLength the blockLength value |
| 199 | + * @param f A function mapping elements of {@code input_dataset}, concatenated with |
| 200 | + * {@code other_arguments}, to a Dataset variant that contains elements matching |
| 201 | + * {@code output_types} and {@code output_shapes}. |
| 202 | + * @param outputTypes the value of the outputTypes property |
| 203 | + * @param outputShapes the value of the outputShapes property |
| 204 | + * @return a new instance of InterleaveDataset |
| 205 | + */ |
| 206 | + public InterleaveDataset interleaveDataset(Operand<? extends TType> inputDataset, |
| 207 | + Iterable<Operand<?>> otherArguments, Operand<TInt64> cycleLength, Operand<TInt64> blockLength, |
| 208 | + ConcreteFunction f, List<Class<? extends TType>> outputTypes, List<Shape> outputShapes) { |
| 209 | + return InterleaveDataset.create(scope, inputDataset, otherArguments, cycleLength, blockLength, f, outputTypes, outputShapes); |
| 210 | + } |
| 211 | + |
137 | 212 | /**
|
138 | 213 | * The IteratorV2 operation
|
139 | 214 | *
|
@@ -215,6 +290,56 @@ public MakeIterator makeIterator(Operand<? extends TType> dataset,
|
215 | 290 | return MakeIterator.create(scope, dataset, iterator);
|
216 | 291 | }
|
217 | 292 |
|
| 293 | + /** |
| 294 | + * Creates a dataset that applies {@code f} to the outputs of {@code input_dataset}. |
| 295 | + * |
| 296 | + * @param inputDataset the inputDataset value |
| 297 | + * @param otherArguments the otherArguments value |
| 298 | + * @param f the value of the f property |
| 299 | + * @param outputTypes the value of the outputTypes property |
| 300 | + * @param outputShapes the value of the outputShapes property |
| 301 | + * @param options carries optional attribute values |
| 302 | + * @return a new instance of MapDataset |
| 303 | + */ |
| 304 | + public MapDataset mapDataset(Operand<? extends TType> inputDataset, |
| 305 | + Iterable<Operand<?>> otherArguments, ConcreteFunction f, |
| 306 | + List<Class<? extends TType>> outputTypes, List<Shape> outputShapes, |
| 307 | + MapDataset.Options... options) { |
| 308 | + return MapDataset.create(scope, inputDataset, otherArguments, f, outputTypes, outputShapes, options); |
| 309 | + } |
| 310 | + |
| 311 | + /** |
| 312 | + * Makes a "one-shot" iterator that can be iterated only once. |
| 313 | + * A one-shot iterator bundles the logic for defining the dataset and |
| 314 | + * the state of the iterator in a single op, which allows simple input |
| 315 | + * pipelines to be defined without an additional initialization |
| 316 | + * ("MakeIterator") step. |
| 317 | + * <p>One-shot iterators have the following limitations: |
| 318 | + * <ul> |
| 319 | + * <li>They do not support parameterization: all logic for creating the underlying |
| 320 | + * dataset must be bundled in the {@code dataset_factory} function.</li> |
| 321 | + * <li>They are not resettable. Once a one-shot iterator reaches the end of its |
| 322 | + * underlying dataset, subsequent "IteratorGetNext" operations on that |
| 323 | + * iterator will always produce an {@code OutOfRange} error.</li> |
| 324 | + * </ul> |
| 325 | + * <p>For greater flexibility, use "Iterator" and "MakeIterator" to define |
| 326 | + * an iterator using an arbitrary subgraph, which may capture tensors |
| 327 | + * (including fed values) as parameters, and which may be reset multiple |
| 328 | + * times by rerunning "MakeIterator". |
| 329 | + * |
| 330 | + * @param datasetFactory A function of type {@code () -> DT_VARIANT}, where the returned |
| 331 | + * DT_VARIANT is a dataset. |
| 332 | + * @param outputTypes the value of the outputTypes property |
| 333 | + * @param outputShapes the value of the outputShapes property |
| 334 | + * @param options carries optional attribute values |
| 335 | + * @return a new instance of OneShotIterator |
| 336 | + */ |
| 337 | + public OneShotIterator oneShotIterator(ConcreteFunction datasetFactory, |
| 338 | + List<Class<? extends TType>> outputTypes, List<Shape> outputShapes, |
| 339 | + OneShotIterator.Options... options) { |
| 340 | + return OneShotIterator.create(scope, datasetFactory, outputTypes, outputShapes, options); |
| 341 | + } |
| 342 | + |
218 | 343 | /**
|
219 | 344 | * Constructs an Optional variant from a tuple of tensors.
|
220 | 345 | *
|
|
0 commit comments