Skip to content

paddlex.deploy.Predictor multithreading execute unet will cause RuntimeError: could not execute a primitive #34492

@dwSun

Description

@dwSun
import os

import numpy as np
from PIL import Image

from multiprocessing.dummy import Pool as ThreadPool
import paddlex as pdx


model = pdx.deploy.Predictor("path/to/model", use_gpu=False)

def handler(img):
    print("#")
    image = Image.open(img)
    image_data = np.asarray(image)
    # RGB -> BGR
    image_data = image_data[..., ::-1]
    model.predict(img, topk=5)


img_dirs = "/path/to/imgs"
files = []
for r, ds, fs in os.walk(img_dirs):
    for f in fs:
        if f.endswith(".JPG"):
            files.append(os.path.join(r, f))


p = ThreadPool()
p.map(handler, files)
p.close()
p.join()

as above,loading deeplabv3p model does not report error,but loading unet will report error:

  File "test_seg.3.py", line 26, in handler
    model.predict(img, topk=5)
  File "/home/user/miniconda3/envs/tower/lib/python3.8/site-packages/paddlex/deploy.py", line 278, in predict
    model_pred = self.raw_predict(preprocessed_input)
  File "/home/user/miniconda3/envs/tower/lib/python3.8/site-packages/paddlex/deploy.py", line 257, in raw_predict
    self.predictor.zero_copy_run()
RuntimeError: could not execute a primitive

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions