• Create a Dataset that produces each element from provided JavaScript generator, which is a function* (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Generator_functions), or a function that returns an iterator (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Generator_functions).

    The returned iterator should have .next() function that returns element in format of {value: TensorContainer, done:boolean}.

    Example of creating a dataset from an iterator factory:

    function makeIterator() {
    const numElements = 10;
    let index = 0;

    const iterator = {
    next: () => {
    let result;
    if (index < numElements) {
    result = {value: index, done: false};
    index++;
    return result;
    }
    return {value: index, done: true};
    }
    };
    return iterator;
    }
    const ds = tf.data.generator(makeIterator);
    await ds.forEachAsync(e => console.log(e));

    Example of creating a dataset from a generator:

    function* dataGenerator() {
    const numElements = 10;
    let index = 0;
    while (index < numElements) {
    const x = index;
    index++;
    yield x;
    }
    }

    const ds = tf.data.generator(dataGenerator);
    await ds.forEachAsync(e => console.log(e));

    Type Parameters

    Parameters

    • generator: (() => Iterator<T, any, undefined> | Promise<Iterator<T, any, undefined>>)

      A JavaScript generator function that returns a JavaScript iterator.

        • (): Iterator<T, any, undefined> | Promise<Iterator<T, any, undefined>>
        • Returns Iterator<T, any, undefined> | Promise<Iterator<T, any, undefined>>

    Returns Dataset<T>

    Doc

Generated using TypeDoc