Skip to content

Conversation

@scyyh11
Copy link
Collaborator

@scyyh11 scyyh11 commented Nov 28, 2025

  1. 使用 cv2.imencode 优化图像编码,降低内存占用。
  2. 增加 malloc_trim 强制回收内存碎片。
  3. 增加显式 GC 和对象删除逻辑。

2. 增加 malloc_trim 强制回收内存碎片。
3. 增加显式 GC 和对象删除逻辑。
@paddle-bot
Copy link

paddle-bot bot commented Nov 28, 2025

Thanks for your contribution!

Copy link
Member

@Bobholamovic Bobholamovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢贡献!我留了一些评论,请看看。

elif isinstance(image, np.ndarray):
import cv2

success, buffer = cv2.imencode('.jpg', image, [int(cv2.IMWRITE_JPEG_QUALITY), 95])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此前发现cv2.imencodePIL.Image.save存在区别,这样做似乎会影响精度。可能需要确认一下换用cv2.imencode的必要性。

result = future.result()
results.append(result.choices[0].message.content)

_force_memory_compact()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在每次执行完成后调用gc.collect,是否影响推理速度?

gc.collect()
if platform.system() == "Linux":
try:
libc = ctypes.CDLL("libc.so.6")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里硬编码了库名。是否可以采用更通用的方法(例如ctypes.util.find_library)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants