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

Update convertModel.py #521

Open
wants to merge 1 commit into
base: release/v2.2.5
Choose a base branch
from
Open
Changes from all commits
Commits
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
11 changes: 5 additions & 6 deletions packages/paddlejs-converter/convertModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import stat
import traceback
import numpy as np
import paddle.fluid as fluid
import paddle as paddle
import copy
from functools import reduce
Expand Down Expand Up @@ -193,7 +192,7 @@ def organizeModelVariableInfo(result):

# persistable数据存入paramValuesDict,等待排序
if v.persistable:
tensor = np.array(fluid.global_scope().find_var(v.name).get_tensor())
tensor = np.array(paddle.static.global_scope().find_var(v.name).get_tensor())
data = tensor.flatten().tolist()
paramValuesDict[v.name] = data

Expand All @@ -214,7 +213,7 @@ def organizeModelVariableInfo(result):
exe.run(program, feed=feedData, fetch_list=fetch_targets, return_numpy=False)

for varKey in varInfoDict:
var = fluid.global_scope().find_var(varKey)
var = paddle.static.global_scope().find_var(varKey)
varData = np.array(var.get_tensor())
varShape = list(varData.shape)
varInfoDict[varKey]['shape'] = validateShape(varShape, varKey)
Expand Down Expand Up @@ -363,7 +362,7 @@ def appendConnectOp(fetch_targets):
# 从fetch_targets中提取输出算子信息
for target in fetch_targets:
name = target.name
curVar = fluid.global_scope().find_var(name)
curVar = paddle.static.global_scope().find_var(name)
curTensor = np.array(curVar.get_tensor())
shape = list(curTensor.shape)
totalShape += reduce(lambda x, y: x * y, shape)
Expand Down Expand Up @@ -450,8 +449,8 @@ def convertToPaddleJSModel(modelDir, modelName, paramsName, outputDir, useGPUOpt

# 初始化fluid运行环境和配置
global exe
exe = fluid.Executor(fluid.CPUPlace())
result = fluid.io.load_inference_model(dirname=modelDir, executor=exe, model_filename=modelName, params_filename=paramsName)
exe = paddle.static.Executor(paddle.CPUPlace())
result = paddle.static.load_inference_model(path_prefix=modelDir, executor=exe)
global program
program = result[0]
fetch_targets = result[2]
Expand Down