towhee-io / towhee

Towhee is a framework that is dedicated to making neural data processing pipelines simple and fast.
https://towhee.io
Apache License 2.0
3.16k stars 246 forks source link

[Bug]: Memory leakage during image feature extraction(OOM) #2696

Closed youwenwang2024 closed 2 months ago

youwenwang2024 commented 2 months ago
def pipline(img):
    p_search = (
        pipe.input('img')
        .map('img', 'vec', ops.image_embedding.timm('lambda_resnet50ts'))
        .output('vec')
    )
    res =  pipline(img).get()
    del p_search
    return res

if __name__ =="__main__":
    from glob import glob
    path = 'mypath'
    inputFiles =  glob(path+"/*.*")
    print(len(inputFiles))
    for idx in range(len(inputFiles)):
        input_file_path  = inputFiles[idx]
        pipline(input_file_path)

There are a large number of images in the folder. When calling the feature extraction interface in a loop, the memory gradually increases, ultimately leading to OOM. What is the reason for this

Environment

- Towhee version(1.1.0):
- OS(Ubuntu):
- GPU:4090
junjiejiangjjj commented 2 months ago

Don't create a new pipeline every time, try this:


 p_search = (
        pipe.input('img')
        .map('img', 'vec', ops.image_embedding.timm('lambda_resnet50ts'))
        .output('vec')
    )

def pipline(img):
    res =  p_search(img).get()
    return res
youwenwang2024 commented 2 months ago

According to the method you provided, the problem has been resolved. Thank you