Open fightingshao opened 3 weeks ago
paddlex/temp/中的内容会在程序退出时自动释放,是在程序退出后没有释放吗?系统环境是什么呢?
是CentOS Linux release 7.6.1810(Core)
请问可以取消图片保存吗?我这是服务,所以需要一直后台启动。。。
您好,PaddleX在识别时,当图片传入的时ndarray会默认创建临时目录保存图片,可以通过修改 https://github.com/PaddlePaddle/PaddleX/blob/22e7501aea85166cc973a193cdbe7f0a4e809459/paddlex/inference/components/transforms/image/common.py 中的 ReadImage 来取消掉创建临时目录,具体修改如下: `class ReadImage(_BaseRead): INPUT_KEYS = ["img"] OUTPUT_KEYS = ["img", "img_size", "ori_img", "ori_img_size"] DEAULT_INPUTS = {"img": "img"} DEAULT_OUTPUTS = { "img": "img", "input_path": "input_path", "img_size": "img_size", "ori_img": "ori_img", "ori_img_size": "ori_img_size", }
_FLAGS_DICT = {
"BGR": cv2.IMREAD_COLOR,
"RGB": cv2.IMREAD_COLOR,
"GRAY": cv2.IMREAD_GRAYSCALE,
}
SUFFIX = ["jpg", "png", "jpeg", "JPEG", "JPG", "bmp", "PDF", "pdf"]
def __init__(self, batch_size=1, format="BGR"):
"""
Initialize the instance.
Args:
format (str, optional): Target color format to convert the image to.
Choices are 'BGR', 'RGB', and 'GRAY'. Default: 'BGR'.
"""
super().__init__(batch_size)
self.format = format
flags = self._FLAGS_DICT[self.format]
self._img_reader = ImageReader(backend="opencv", flags=flags)
self._pdf_reader = PDFReader()
self._writer = ImageWriter(backend="opencv")
def apply(self, img):
"""apply"""
def process_ndarray(img):
# with temp_file_manager.temp_file_context(suffix=".png") as temp_file:
# img_path = Path(temp_file.name)
# self._writer.write(img_path, img)
# print("="*100)
# print("img_path", img_path)
# if self.format == "RGB":
# img = img[:, :, ::-1]
img_path = ""
return {
"input_path": img_path,
"img": img,
"img_size": [img.shape[1], img.shape[0]],
"ori_img": deepcopy(img),
"ori_img_size": deepcopy([img.shape[1], img.shape[0]]),
}`
需要注意的是,这种改法目前只在OCR测试有效,并且可能导致其他产线运行失败,后续我们会考虑支持该功能。
使用create_pipeline中ocr识别,其中使用模型PP-OCRv4_mobile_rec、PP-OCRv4_mobile_det,在paddlex/temp/下面生成大量的文本分割图片,请问如何设置取消图片保存