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

PLT update, add Ocr model case #2937

Merged
merged 77 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
a3fe935
add plt export, test=model
Zeref996 Jul 11, 2024
54168e3
add plt export, test=model
Zeref996 Jul 11, 2024
b5c1730
add plt export, test=model
Zeref996 Jul 11, 2024
cdbe8e0
add plt export, test=model
Zeref996 Jul 11, 2024
d7c8369
add plt export, test=model
Zeref996 Jul 12, 2024
b57f7f4
add plt export, test=model
Zeref996 Jul 12, 2024
b3c1017
add plt export, test=model
Zeref996 Jul 15, 2024
4224630
add plt export, test=model
Zeref996 Jul 15, 2024
afc64f6
add plt export, test=model
Zeref996 Jul 15, 2024
dcb84ee
add plt export, test=model
Zeref996 Jul 15, 2024
8b393e5
add plt export, test=model
Zeref996 Jul 15, 2024
68ad191
add plt export, test=model
Zeref996 Jul 15, 2024
a363f8a
add plt export, test=model
Zeref996 Jul 15, 2024
835a6a1
add plt export, test=model
Zeref996 Jul 15, 2024
45d510e
add plt export, test=model
Zeref996 Jul 16, 2024
7013b7e
Merge remote-tracking branch 'upstream/develop' into plt-update-002
Zeref996 Jul 23, 2024
044c301
fix plt start, test=model
Zeref996 Jul 23, 2024
139a490
Merge remote-tracking branch 'upstream/develop' into plt-update-003
Zeref996 Jul 23, 2024
f52dc56
fix plt start, test=model
Zeref996 Jul 23, 2024
12b7ed6
fix plt start, test=model
Zeref996 Jul 23, 2024
513937f
fix plt start, test=model
Zeref996 Jul 23, 2024
8c4cf28
Merge remote-tracking branch 'upstream/develop' into plt-update-004
Zeref996 Aug 1, 2024
40a4a99
fix plt perf, test=model
Zeref996 Aug 1, 2024
3cdd124
Merge remote-tracking branch 'upstream/develop' into plt-update-004
Zeref996 Aug 5, 2024
7ce511d
add plt bm ignore, test=model
Zeref996 Aug 5, 2024
6c092a4
Merge remote-tracking branch 'upstream/develop' into plt-update-006
Zeref996 Aug 5, 2024
ea94ce8
update plt start.sh, test=model
Zeref996 Aug 5, 2024
c6ef08c
Merge remote-tracking branch 'upstream/develop' into plt-update-007
Zeref996 Aug 5, 2024
59430eb
update plt start.sh, test=model
Zeref996 Aug 5, 2024
eb8557c
Merge remote-tracking branch 'upstream/develop' into plt-update-008
Zeref996 Aug 8, 2024
d04932d
Merge remote-tracking branch 'upstream/develop' into plt-update-009
Zeref996 Aug 15, 2024
1ee0c40
add inputspec plt ci, test=model
Zeref996 Aug 15, 2024
9e90a82
add inputspec plt ci, test=model
Zeref996 Aug 15, 2024
7c537d8
Merge remote-tracking branch 'upstream/develop' into plt-update-009
Zeref996 Aug 19, 2024
b802922
update plt ci, test=model
Zeref996 Aug 19, 2024
55fc399
update plt ci, test=model
Zeref996 Aug 19, 2024
b9a0a8a
update plt ci, test=model
Zeref996 Aug 19, 2024
9ddd06c
update plt ci, test=model
Zeref996 Aug 20, 2024
3df68a8
update plt ci, test=model
Zeref996 Aug 20, 2024
8e8a5df
Merge remote-tracking branch 'upstream/develop' into plt-update-011
Zeref996 Aug 23, 2024
e06a669
update plt gsb, test=model
Zeref996 Aug 23, 2024
9c0d389
Merge remote-tracking branch 'upstream/develop' into plt-update-012
Zeref996 Aug 23, 2024
4ebc12f
fix plt statistic, test=model
Zeref996 Aug 23, 2024
7ca3088
Merge remote-tracking branch 'upstream/develop' into plt-update-013
Zeref996 Aug 28, 2024
aad05cd
plt update net instance, test=model
Zeref996 Aug 28, 2024
83accc5
plt update net instance, test=model
Zeref996 Aug 29, 2024
0bc98a2
plt update net instance, test=model
Zeref996 Aug 29, 2024
b4e3891
plt update net instance, test=model
Zeref996 Aug 29, 2024
57b98ad
plt update net instance, test=model
Zeref996 Aug 29, 2024
a501315
plt update net instance, test=model
Zeref996 Aug 29, 2024
f1922fa
plt update net instance, test=model
Zeref996 Aug 29, 2024
fd6284c
plt update net instance, test=model
Zeref996 Aug 30, 2024
3dddc7f
plt update net instance, test=model
Zeref996 Aug 30, 2024
849b2a8
plt update net instance, test=model
Zeref996 Aug 30, 2024
0c598c7
plt update net instance, test=model
Zeref996 Aug 30, 2024
5c017f9
plt update net instance, test=model
Zeref996 Aug 30, 2024
eed8461
plt update net instance, test=model
Zeref996 Aug 30, 2024
b59f018
plt update net instance, test=model
Zeref996 Aug 30, 2024
430e1ea
plt update net instance, test=model
Zeref996 Aug 30, 2024
b3efb14
plt update net instance, test=model
Zeref996 Aug 30, 2024
fb02edd
plt update net instance, test=model
Zeref996 Sep 2, 2024
8941680
plt update net instance, test=model
Zeref996 Sep 2, 2024
ce0c1e7
plt update net instance, test=model
Zeref996 Sep 2, 2024
e71139f
plt update net instance, test=model
Zeref996 Sep 3, 2024
ef875df
plt update net instance, test=model
Zeref996 Sep 3, 2024
ee1559c
plt update net instance, test=model
Zeref996 Sep 3, 2024
b154952
plt update net instance, test=model
Zeref996 Sep 3, 2024
25aaae1
plt update net instance, test=model
Zeref996 Sep 4, 2024
4a85e2d
plt update net instance, test=model
Zeref996 Sep 4, 2024
9755ebc
plt update net instance, test=model
Zeref996 Sep 4, 2024
d087c91
Merge remote-tracking branch 'upstream/develop' into plt-update-013
Zeref996 Sep 5, 2024
3cbc3a8
Merge remote-tracking branch 'upstream/develop' into develop
Zeref996 Sep 5, 2024
4472abd
fix plt tools, test=model
Zeref996 Sep 6, 2024
6e8dfc1
Merge branch 'pr_2936' into model-module-00
Zeref996 Sep 6, 2024
adf3a58
update ply add model case, test=model
Zeref996 Sep 6, 2024
1643378
update ply add model case, test=model
Zeref996 Sep 6, 2024
9cf3f9e
update ply add model case, test=model
Zeref996 Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions framework/e2e/PaddleLT_new/binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import numpy as np
from layertest import LayerTest
from strategy.compare import perf_compare
from tools.logger import Logger
from tools.res_save import save_pickle
from pltools.logger import Logger
from pltools.res_save import save_pickle


def get_commits(start, end):
Expand Down
4 changes: 2 additions & 2 deletions framework/e2e/PaddleLT_new/db/layer_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from db.snapshot import Snapshot

# from strategy.compare import perf_compare
from tools.logger import Logger
from tools.res_save import xlsx_save
from pltools.logger import Logger
from pltools.res_save import xlsx_save


class LayerBenchmarkDB(object):
Expand Down
145 changes: 145 additions & 0 deletions framework/e2e/PaddleLT_new/debug/infer_debug_dropout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import os
import numpy as np
import paddle
import paddle.inference as paddle_infer


class LayerCase(paddle.nn.Layer):
def __init__(self):
super().__init__()
self.parameter_0 = self.create_parameter(
shape=[2048],
dtype=paddle.float32,
)
self.parameter_1 = self.create_parameter(
shape=[1024],
dtype=paddle.float32,
)
self.parameter_2 = self.create_parameter(
shape=[1024],
dtype=paddle.float32,
)
self.parameter_3 = self.create_parameter(
shape=[1024],
dtype=paddle.float32,
)
self.parameter_4 = self.create_parameter(
shape=[1024],
dtype=paddle.float32,
)
self.parameter_5 = self.create_parameter(
shape=[1024],
dtype=paddle.float32,
)
self.parameter_6 = self.create_parameter(
shape=[2048, 1024],
dtype=paddle.float32,
)
self.parameter_7 = self.create_parameter(
shape=[1024, 2048],
dtype=paddle.float32,
)

def forward(
self,
var_0, # (shape: [1, 169, 1024], dtype: paddle.float32, stop_gradient: False)
var_1, # (shape: [1, 169, 1024], dtype: paddle.float32, stop_gradient: False)
):
var_2 = paddle.nn.functional.common.dropout(
var_0, p=0.1, axis=None, training=self.training, mode="upscale_in_train", name=None
)
var_3 = var_1.__add__(var_2)
var_4 = paddle.nn.functional.norm.layer_norm(
var_3, normalized_shape=[1024], weight=self.parameter_5, bias=self.parameter_3, epsilon=1e-05
)
var_5 = paddle.nn.functional.common.linear(x=var_4, weight=self.parameter_7, bias=self.parameter_0, name=None)
var_6 = paddle.nn.functional.activation.gelu(var_5)
var_7 = paddle.nn.functional.common.dropout(
var_6, p=0.1, axis=None, training=self.training, mode="upscale_in_train", name=None
)
var_8 = paddle.nn.functional.common.linear(x=var_7, weight=self.parameter_6, bias=self.parameter_1, name=None)
var_9 = paddle.nn.functional.common.dropout(
var_8, p=0.1, axis=None, training=self.training, mode="upscale_in_train", name=None
)
var_10 = var_4.__add__(var_9)
var_11 = paddle.nn.functional.norm.layer_norm(
var_10, normalized_shape=[1024], weight=self.parameter_2, bias=self.parameter_4, epsilon=1e-05
)
return var_11


seed = 33


def reset(seed):
"""
重置模型图
:param seed: 随机种子
:return:
"""
paddle.enable_static()
paddle.disable_static()
paddle.seed(seed)
np.random.seed(seed)
np.set_printoptions(threshold=5, edgeitems=3)


# def _net_input():
# """get input"""
# reset(seed)
# data = (
# paddle.to_tensor(np.random.random(size=[1, 169, 1024]).astype('float32')),
# paddle.to_tensor(np.random.random(size=[1, 169, 1024]).astype('float32')),
# )
# return data

data = [
np.random.random(size=[1, 169, 1024]).astype("float32"),
np.random.random(size=[1, 169, 1024]).astype("float32"),
]

tensor_data = [paddle.to_tensor(data[0]), paddle.to_tensor(data[1])]


def _net_instant():
"""get net"""
reset(seed)
net = LayerCase()
return net


# 动态图结果
reset(seed)
net = _net_instant()
net.eval()
logit = net(*tensor_data)

# export
reset(seed)
st_net = paddle.jit.to_static(_net_instant())
st_net.eval()
st_net(*tensor_data)
paddle.jit.save(st_net, path=os.path.join("save_path", "jit_save"))

# infer
reset(seed)
config = paddle_infer.Config("save_path/jit_save" + ".pdmodel", "save_path/jit_save" + ".pdiparams")
config.enable_use_gpu(1000, 0)
predictor = paddle_infer.create_predictor(config)
input_names = predictor.get_input_names()
for i, name in enumerate(input_names):
input_handle = predictor.get_input_handle(name)
input_tmp = data[i]
input_handle.copy_from_cpu(input_tmp)
predictor.run()
output_names = predictor.get_output_names()
if len(output_names) > 1:
infer_res = []
for i, name in enumerate(output_names):
output_handle = predictor.get_output_handle(output_names[i])
infer_res.append(output_handle.copy_to_cpu())
else:
output_handle = predictor.get_output_handle(output_names[0])
infer_res = output_handle.copy_to_cpu()

print(logit - infer_res)
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/diy/data/single_img_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import paddle
from paddle.io import Dataset, BatchSampler, DataLoader
import tools.np_tool as tool
import pltools.np_tool as tool


class SingleImageWithoutLabelDataset(Dataset):
Expand Down
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/diy/data/struct_img_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import paddle
from paddle.io import Dataset, BatchSampler, DataLoader
import tools.np_tool as tool
import pltools.np_tool as tool


# class ListImageWithoutLabelDataset(Dataset):
Expand Down
4 changes: 2 additions & 2 deletions framework/e2e/PaddleLT_new/engine/paddle_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from generator.builder_layer import BuildLayer
from generator.builder_data import BuildData

from tools.logger import Logger
from pltools.logger import Logger

from tools.res_save import save_tensor
from pltools.res_save import save_tensor


class LayerEval(object):
Expand Down
6 changes: 3 additions & 3 deletions framework/e2e/PaddleLT_new/engine/paddle_eval_bm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from engine.paddle_xtools import reset
from generator.builder_layer import BuildLayer
from generator.builder_data import BuildData
from tools.res_save import save_pickle
from tools.statistics import trimmean, mean, best, best_top_k, perf_by_step
from tools.logger import Logger
from pltools.res_save import save_pickle
from pltools.statistics import trimmean, mean, best, best_top_k, perf_by_step
from pltools.logger import Logger


class LayerEvalBM(object):
Expand Down
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/engine/paddle_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from generator.builder_layer import BuildLayer
from generator.builder_data import BuildData

from tools.logger import Logger
from pltools.logger import Logger


class LayerExport(object):
Expand Down
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/engine/paddle_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from generator.builder_layer import BuildLayer
from generator.builder_data import BuildData

from tools.logger import Logger
from pltools.logger import Logger


class LayerInfer(object):
Expand Down
2 changes: 1 addition & 1 deletion framework/e2e/PaddleLT_new/engine/paddle_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from generator.builder_optimizer import BuildOptimizer
from generator.builder_loss import BuildLoss

from tools.logger import Logger
from pltools.logger import Logger


class LayerTrain(object):
Expand Down
6 changes: 3 additions & 3 deletions framework/e2e/PaddleLT_new/engine/paddle_train_bm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from generator.builder_data import BuildData
from generator.builder_optimizer import BuildOptimizer
from generator.builder_loss import BuildLoss
from tools.res_save import save_pickle
from tools.statistics import trimmean, mean, best, best_top_k, perf_by_step
from tools.logger import Logger
from pltools.res_save import save_pickle
from pltools.statistics import trimmean, mean, best, best_top_k, perf_by_step
from pltools.logger import Logger


class LayerTrainBM(object):
Expand Down
4 changes: 2 additions & 2 deletions framework/e2e/PaddleLT_new/engine/torch_eval_bm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from engine.torch_xtools import reset
from generator.builder_layer import BuildLayer
from generator.builder_data import BuildData
from tools.res_save import save_pickle
from tools.statistics import trimmean, mean, best, best_top_k, perf_by_step
from pltools.res_save import save_pickle
from pltools.statistics import trimmean, mean, best, best_top_k, perf_by_step


class TorchLayerEvalBM(object):
Expand Down
6 changes: 5 additions & 1 deletion framework/e2e/PaddleLT_new/generator/builder_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
import diy
import layerApicase
import layercase

if os.environ.get("USE_PADDLE_MODEL", "None") == "PaddleOCR":
import layerModelcase
import PaddleOCR
elif os.environ.get("FRAMEWORK") == "torch":
import torch
import layerTorchcase

import tools.np_tool as tool
import pltools.np_tool as tool


class BuildData(object):
Expand Down
4 changes: 4 additions & 0 deletions framework/e2e/PaddleLT_new/generator/builder_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import diy
import layerApicase
import layercase

if os.environ.get("USE_PADDLE_MODEL", "None") == "PaddleOCR":
import layerModelcase
import PaddleOCR
elif os.environ.get("FRAMEWORK") == "torch":
import torch
import layerTorchcase
Expand Down
18 changes: 18 additions & 0 deletions framework/e2e/PaddleLT_new/layerModelcase/Ocr_cases/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
import glob

# 获取当前文件所在目录
current_dir = os.path.dirname(__file__)

# 获取当前目录下所有的文件夹路径(注意:这里不需要尾随的斜杠)
folders = glob.glob(os.path.join(current_dir, '*'))

# 过滤出文件夹(排除文件)
folders = [folder for folder in folders if os.path.isdir(folder) and not os.path.basename(folder) == '__pycache__']

# 动态导入所有 .py 文件
for folder in folders:
# 获取文件名(不含扩展名)
module_name = os.path.basename(folder)
# 导入模块
__import__('layerModelcase.Ocr_cases.' + module_name, globals(), locals(), [])
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import glob

# 获取当前文件所在目录
current_dir = os.path.dirname(__file__)

# 获取当前目录下所有的 .py 文件路径
py_files = glob.glob(os.path.join(current_dir, "*.py"))

# 动态导入所有 .py 文件
for py_file in py_files:
# 获取文件名(不含扩展名)
module_name = os.path.basename(py_file)[:-3]
# 导入模块
__import__('layerModelcase.Ocr_cases.backbones.' + module_name, globals(), locals(), [])
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import paddle
import numpy as np
import PaddleOCR.ppocr.modeling.backbones as backbones


def LayerCase():
"""模型库中间态"""
model = backbones.build_backbone(config={"name": "DenseNet"}, model_type="cls")
return model



def create_inputspec():
inputspec = (
paddle.static.InputSpec(shape=(-1, 3, 224, 224), dtype=paddle.float32, stop_gradient=False),
)
return inputspec

def create_tensor_inputs():
inputs = (
paddle.rand(shape=[1, 3, 224, 224], dtype=paddle.float32),
)
return inputs


def create_numpy_inputs():
inputs = (
np.random.random(size=[1, 3, 224, 224]).astype('float32'),
)
return inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import paddle
import numpy as np
import PaddleOCR.ppocr.modeling.backbones as backbones


def LayerCase():
"""模型库中间态"""
model = backbones.build_backbone(config={"name": "EfficientNetb3_PREN"}, model_type="cls")
return model



def create_inputspec():
inputspec = (
paddle.static.InputSpec(shape=(-1, 3, 224, 224), dtype=paddle.float32, stop_gradient=False),
)
return inputspec

def create_tensor_inputs():
inputs = (
paddle.rand(shape=[1, 3, 224, 224], dtype=paddle.float32),
)
return inputs


def create_numpy_inputs():
inputs = (
np.random.random(size=[1, 3, 224, 224]).astype('float32'),
)
return inputs
Loading