Infer from a pre-defined Dataset. Dataset is defined in paddle.base.dataset. Given a program, either a program or compiled program, infer_from_dataset will consume all data samples in dataset. Input scope can be given by users. By default, scope is global_scope(). Th
(
self,
program: Program | CompiledProgram | None = None,
dataset: DatasetBase | _FleetDatasetBase | None = None,
scope: core._Scope | None = None,
thread: int = 0,
debug: bool = False,
fetch_list: list[Tensor] | None = None,
fetch_info: list[str] | None = None,
print_period: int = 100,
fetch_handler: FetchHandler | None = None,
)
| 2883 | return None |
| 2884 | |
| 2885 | def infer_from_dataset( |
| 2886 | self, |
| 2887 | program: Program | CompiledProgram | None = None, |
| 2888 | dataset: DatasetBase | _FleetDatasetBase | None = None, |
| 2889 | scope: core._Scope | None = None, |
| 2890 | thread: int = 0, |
| 2891 | debug: bool = False, |
| 2892 | fetch_list: list[Tensor] | None = None, |
| 2893 | fetch_info: list[str] | None = None, |
| 2894 | print_period: int = 100, |
| 2895 | fetch_handler: FetchHandler | None = None, |
| 2896 | ) -> None: |
| 2897 | """ |
| 2898 | Infer from a pre-defined Dataset. Dataset is defined in paddle.base.dataset. |
| 2899 | Given a program, either a program or compiled program, infer_from_dataset will |
| 2900 | consume all data samples in dataset. Input scope can be given by users. By default, |
| 2901 | scope is global_scope(). The total number of thread run in training is `thread`. |
| 2902 | Thread number used in training will be minimum value of threadnum in Dataset and |
| 2903 | the value of thread in this interface. Debug can be set so that executor will display |
| 2904 | Run-Time for all operators and the throughputs of current infer task. |
| 2905 | |
| 2906 | The document of infer_from_dataset is almost the same as train_from_dataset, |
| 2907 | except that in distributed training, push gradients will be disabled in infer_from_dataset. |
| 2908 | infer_from_dataset() can be used for evaluation in multi-thread very easily. |
| 2909 | |
| 2910 | Args: |
| 2911 | program(Program|CompiledProgram): the program that needs to be run, |
| 2912 | if not provided, then default_main_program (not compiled) will be used. |
| 2913 | dataset(paddle.base.Dataset): dataset created outside this function, |
| 2914 | a user should provide a well-defined dataset before calling this function. |
| 2915 | Please check the document of Dataset if needed. default is None |
| 2916 | scope(Scope): the scope used to run this program, you can switch it to different scope |
| 2917 | for each run. default is global_scope |
| 2918 | thread(int): number of thread a user wants to run in this function. Default is 0, which |
| 2919 | means using thread num of dataset |
| 2920 | debug(bool): whether a user wants to run infer_from_dataset, default is False |
| 2921 | fetch_list(Tensor List): fetch Tensor list, each Tensor will be printed during |
| 2922 | training, default is None |
| 2923 | fetch_info(String List): print information for each Tensor, default is None |
| 2924 | print_period(int): the number of mini-batches for each print, default is 100 |
| 2925 | fetch_handler(FetchHandler): a user define class for fetch output. |
| 2926 | |
| 2927 | Returns: |
| 2928 | None |
| 2929 | |
| 2930 | Examples: |
| 2931 | |
| 2932 | .. code-block:: pycon |
| 2933 | |
| 2934 | >>> # doctest: +SKIP("This does not supported in PIR mode") |
| 2935 | >>> import paddle |
| 2936 | |
| 2937 | >>> paddle.enable_static() |
| 2938 | >>> place = paddle.CPUPlace() # you can set place = paddle.CUDAPlace(0) to use gpu |
| 2939 | >>> exe = paddle.static.Executor(place) |
| 2940 | >>> x = paddle.static.data(name="x", shape=[None, 10, 10], dtype="int64") |
| 2941 | >>> y = paddle.static.data(name="y", shape=[None, 1], dtype="int64", lod_level=1) |
| 2942 | >>> dataset = paddle.base.DatasetFactory().create_dataset() |
no test coverage detected