Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

模型转化报错

Open sitongchen opened this issue 7 years ago • 5 comments

在模型文件convert的时候使用inference_scope.find_var(file).get_tensor() 报错 inference_scope.find_var(file)为NoneType

代码如下: import os

import math import paddle import paddle.fluid as fluid import sys import struct import time import numpy as np

from paddle.fluid.metrics import Auc

import argparse

def convert(use_cuda, model_dir, dest_model_dir): place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() exe = fluid.Executor(place) inference_scope = fluid.core.Scope() if 1: fluid_v1={} with open("/home/chensitong03/work/tools/data/fluid_v1") as f: for line in f.readlines(): arrs = line.rstrip().split(" "") fluid_v1[arrs[1]] = arrs[0]

    for file in os.listdir(model_dir):
        if file not in fluid_v1:
            continue
        param = inference_scope.find_var(file).get_tensor()   这里报错,是需要再初始化什么东西么
        dim_arrs = param._get_dims()
        。。。。。。

sitongchen avatar Oct 23 '19 09:10 sitongchen

V1的parameter名称和fluid的parameter名称不完全一样,所以会找不到

wanghaoshuang avatar Oct 23 '19 09:10 wanghaoshuang

相关issue: https://github.com/PaddlePaddle/Paddle/issues/12819#issuecomment-414556154

wanghaoshuang avatar Oct 23 '19 10:10 wanghaoshuang

这里没有v1的parameter呀

sitongchen avatar Oct 23 '19 11:10 sitongchen

@sitongchen 抱歉,你的代码是全部的代码么?

inference_scope = fluid.core.Scope()

这句声明之后,inference_scope是空的,要用类似于以下的方法初始化:

exe = fluid.Executor(place)
exe.run(startup_program, inference_scope)

关于startup_program可以参考:https://www.paddlepaddle.org.cn/documentation/docs/zh/1.5/api_cn/fluid_cn.html#cn-api-fluid-default-startup-program

wanghaoshuang avatar Oct 24 '19 13:10 wanghaoshuang

Since you haven't replied for more than a year, we have closed this issue/pr. If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. 由于您超过一年未回复,我们将关闭这个issue/pr。 若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。

paddle-bot-old avatar Oct 26 '20 09:10 paddle-bot-old