code: def infer(
      use_cuda,
      save_dirname=None,
      model_filename=None,
      params_filename=None,
  ):
      if save_dirname is None:
          return
  
      place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
      exe = fluid.Executor(place)
  
      def load_image(file):
          im = Image.open(file).convert("L")
          im = im.resize((28, 28), Image.ANTIALIAS)
          im = (
              numpy.array(im)
              .reshape(1, 1, 28, 28)
              .astype(numpy.float32)
          )
          im = im / 255.0 * 2.0 - 1.0
          return im
  
      cur_dir = os.path.dirname(os.path.realpath(__file__))
      tensor_img = load_image(cur_dir + "/infer_3.png")
  
      inference_scope = fluid.core.Scope()
      with fluid.scope_guard(inference_scope):
          # Use fluid.io.load_inference_model to obtain the inference program desc,
          # the feed_target_names (the names of variables that will be feeded
          # data using feed operators), and the fetch_targets (variables that
          # we want to obtain data from using fetch operators).
          [
              inference_program,
              feed_target_names,
              fetch_targets,
          ] = fluid.io.load_inference_model(
              save_dirname, exe, model_filename, params_filename
          )
  
          # Construct feed as a dictionary of {feed_target_name: feed_target_data}
          # and results will contain a list of data corresponding to fetch_targets.
          results = exe.run(
              inference_program,
              feed={feed_target_names[0]: tensor_img},
              fetch_list=fetch_targets,
          )
          lab = numpy.argsort(results)
          print(
              "Inference result of image/infer_3.png is: %d"
              % lab[0][0][-1]
          )
  
file_path: AdvBox/DataPoison/mnist_paddle.py
imports: from __future__ import print_function
  from builtins import range
  import os
  import argparse
  from PIL import Image
  import numpy
  import paddle
  import paddle.fluid
label_desc: Use image node_id 7 for calling a global function with example usage: infer(use_cuda, save_dirname, model_filename, params_filename) and returns: im