paddle导出推理模型只生成(inference.json、inference.yaml、inference.pdiparams),简单解决办法
·
只需要在导出模型命令中添加 Global.export_with_pir=null ,即可
python tools/export_model.py -c configs/rec/PP-OCRv4/en_PP-OCRv4_mobile_rec.yml -o Global.export_with_pir=null Global.checkpoints="output/rec_ppocr_v4/best" Global.save_inference_dir="./output"
在export_model.py源码export_single_model函数中有一个判断,如果全局配置不存在export_with_pir,就不会导出inference.pdmodel、inference.pdiparams.info,所以设置全局export_with_pir 设为null,就会走另外一个分支
def export_single_model(
model,
arch_config,
save_path,
logger,
yaml_path,
config,
input_shape=None,
quanter=None,
):
model = dynamic_to_static(model, arch_config, logger, input_shape)
if quanter is None:
try:
import encryption # Attempt to import the encryption module for AIStudio's encryption model
except (
ModuleNotFoundError
): # Encryption is not needed if the module cannot be imported
print("Skipping import of the encryption module")
paddle_version = version.parse(paddle.__version__)
if config["Global"].get("export_with_pir", True):
assert (
paddle_version >= version.parse("3.0.0b2")
or paddle_version == version.parse("0.0.0")
) and os.environ.get("FLAGS_enable_pir_api", None) not in ["0", "False"]
paddle.jit.save(model, save_path)
else:
if paddle_version >= version.parse(
"3.0.0b2"
) or paddle_version == version.parse("0.0.0"):
model.forward.rollback()
with paddle.pir_utils.OldIrGuard():
model = dynamic_to_static(model, arch_config, logger, input_shape)
paddle.jit.save(model, save_path)
else:
paddle.jit.save(model, save_path)
else:
quanter.save_quantized_model(model, save_path)
logger.info("inference model is saved to {}".format(save_path))
return
更多推荐


所有评论(0)