Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问paddleslim可以对kie推理模型进行裁剪吗? #1804

Open
hzlirz opened this issue Nov 8, 2023 · 1 comment
Open

请问paddleslim可以对kie推理模型进行裁剪吗? #1804

hzlirz opened this issue Nov 8, 2023 · 1 comment
Assignees

Comments

@hzlirz
Copy link

hzlirz commented Nov 8, 2023

kie的两个模型加起来有2G,可以使用paddleslim轻量化吗?如何解决下述报错:

我参考:地址

然后报错:
(paddleocr) root@DESKTOP-VSUROIT:/home/huang/paddle-ocr-gpu# python core_code/paddle_slim_kie.py /root/miniconda3/envs/paddleocr/lib/python3.9/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.") I1108 16:21:45.052196 580245 interpretercore.cc:237] New Executor is Running. W1108 16:21:45.303526 580245 gpu_resources.cc:119] Please NOTE: device: 0, GPU Compute Capability: 7.5, Driver API Version: 12.2, Runtime API Version: 11.8 W1108 16:21:45.304080 580245 gpu_resources.cc:149] device: 0, cuDNN Version: 8.9. 2023-11-08 16:21:51,999-INFO: devices: gpu 2023-11-08 16:21:58,532-INFO: Selected strategies: [] Traceback (most recent call last): File "/home/huang/paddle-ocr-gpu/core_code/paddle_slim_kie.py", line 54, in <module> ac.compress() File "/root/miniconda3/envs/paddleocr/lib/python3.9/site-packages/paddleslim-0.0.0.dev0-py3.9.egg/paddleslim/auto_compression/compressor.py", line 577, in compress AssertionError

我的list如下
image

我的代码如下:
import paddle
from PIL import Image
from paddle.vision.datasets import DatasetFolder
from paddle.vision.transforms import transforms
from paddleslim.auto_compression import AutoCompression

paddle.enable_static()

class ImageNetDataset(DatasetFolder):
def init(self, path, image_size=224):
super().init(path)
normalize = transforms.Normalize(
mean=[123.675, 116.28, 103.53], std=[58.395, 57.120, 57.375])
self.transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(image_size), transforms.Transpose(),
normalize
])

def __getitem__(self, idx):
    img_path, _ = self.samples[idx]
    return self.transform(Image.open(img_path).convert('RGB'))

def __len__(self):
    return len(self.samples)

train_dataset = ImageNetDataset("./train_data/XFUND/zh_train/")
image = paddle.static.data(
name='inputs', shape=[None] + [3, 224, 224], dtype='float32')
train_loader = paddle.io.DataLoader(train_dataset, feed_list=[image], batch_size=32, return_list=False)

ac = AutoCompression(
model_dir="./inference/ser_vi_layoutxlm_xfund_infer",
model_filename="inference.pdmodel",
params_filename="inference.pdiparams",
save_dir="./slim_xfund_infer",
config={'Quantization': {}, "HyperParameterOptimization": {'ptq_algo': ['avg'], 'max_quant_count': 3}},
train_dataloader=train_loader,
eval_dataloader=train_loader)
ac.compress()

@zzjjay
Copy link
Collaborator

zzjjay commented Feb 18, 2024

看起来是ocr模型?
可以参考自动压缩中ocr模型的压缩示例脚步进行尝试;
https://github.com/PaddlePaddle/PaddleSlim/tree/develop/example/auto_compression/ocr

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

No branches or pull requests

2 participants