Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

本地predict错误

Open sjtuwy opened this issue 9 years ago • 6 comments

错误信息如下:

+ model=./gender_sparse_model/pass-00019
+ config=./trainer_config_gender_sparse.cluster.py
+ predict_data=./gender_sparse_data/20161112
+ python predict.py -n ./trainer_config_gender_sparse.cluster.py -w ./gender_sparse_model/pass-00019 -i ./gender_sparse_data/20161112
I1221 17:59:07.502112 34343 Util.cpp:158] commandline:  --use_gpu=0 
I1221 17:59:07.502246 34343 Util.cpp:132] Calling runInitFunctions
I1221 17:59:07.502578 34343 Util.cpp:146] Call runInitFunctions done.
Traceback (most recent call last):
  File "<string>", line 13, in <module>
NameError: name 'GLOG_logtostderr' is not defined
[INFO 2016-12-21 17:59:07,525 networks.py:1466] The input order is [input_fea]
[INFO 2016-12-21 17:59:07,525 networks.py:1472] The output order is [__fc_layer_6__]
I1221 17:59:12.760416 34343 GradientMachine.cpp:124] Loading parameters from ./gender_sparse_model/pass-00019
Traceback (most recent call last):
  File "predict.py", line 107, in <module>
    main()
  File "predict.py", line 104, in main
    predict.predict_onebyone(data)
  File "predict.py", line 77, in predict_onebyone
    input = self.converter.convert([[fea]])
  File "/home/disk0/it/paddle/paddle_internal_release_tools/idl/paddle/output/python27-gcc482/lib/python2.7/site-packages/py_paddle/dataprovider_converter.py", line 152, in convert
    scanner.finish_scan(argument)
  File "/home/disk0/it/paddle/paddle_internal_release_tools/idl/paddle/output/python27-gcc482/lib/python2.7/site-packages/py_paddle/dataprovider_converter.py", line 78, in finish_scan
    m.sparseCopyFrom(self.__rows__, self.__cols__, self.__value__)
  File "/home/disk0/it/paddle/paddle_internal_release_tools/idl/paddle/output/python27-gcc482/lib/python2.7/site-packages/py_paddle/swig_paddle.py", line 680, in sparseCopyFrom
    return _swig_paddle.Matrix_sparseCopyFrom(self, *args)
NotImplementedError: Wrong number or type of arguments for overloaded function 'Matrix_sparseCopyFrom'.
  Possible C/C++ prototypes are:
    Matrix::sparseCopyFrom(std::vector< int,std::allocator< int > > const &,std::vector< int,std::allocator< int > > const &,std::vector< float,std::allocator< float > > const &)
    Matrix::sparseCopyFrom(std::vector< int,std::allocator< int > > const &,std::vector< int,std::allocator< int > > const &)

麻烦协助排查下原因,谢谢。 附: predict.sh:

model=./gender_sparse_model/pass-00019
config=./trainer_config_gender_sparse.cluster.py
predict_data=./gender_sparse_data/20161112
python predict.py \
     -n $config\
     -w $model \
     -i $predict_data \
     > ./gender_sparse_data/20161112.res

predict.py:

import os
import numpy as np
from optparse import OptionParser
from py_paddle import swig_paddle, DataProviderConverter
from paddle.trainer.config_parser import parse_config
from paddle.trainer.PyDataProvider2 import sparse_binary_vector

"""
Usage: run following command to show help message.
  python predict.py -h
"""

fea_map = {}
for line in open('./sparse_fea_entropy.20161112.dict', 'r'):
    l_s = line.rstrip('\n\r').split('\t')
    fea_map[int(l_s[0])] = int(l_s[1])

class ModelPrediction():
    def __init__(self, train_conf, model_dir=None):
        """
        train_conf: trainer configure.
        dict_file: word dictionary file name.
        model_dir: directory of model.
        """
        self.train_conf = train_conf
        self.model_dir = model_dir
        conf = parse_config(train_conf, "is_predict=1")
        self.network = swig_paddle.GradientMachine.createFromConfigProto(conf.model_config)
        self.network.loadParameters(self.model_dir)
        slots = [sparse_binary_vector(5000001)]
        self.converter = DataProviderConverter(slots)


    def predict_onebyone(self, data_file):
        import sys
        """
        The main function for loading data.
        Load the batch, iterate all the images and labels in this batch.
        file_name: the batch file name.
        """
        if data_file is None:
            f = sys.stdin
        else:
            f = open(data_file)
        while True:
            line = f.readline()
            if len(line) == 0:
                break
            try:
                l_s = line.rstrip('\n').split()
                user = l_s[0]
                target = l_s[1]
                feature = l_s[2:]
            except:
                print >> sys.stderr, line,
                continue
            try:
                fea = [int(i.split(':')[0]) for i in feature]
            except Exception, e:
                print >> sys.stderr, "fetch data failed",e
                continue

            input = self.converter.convert([[fea]])
            output = self.network.forwardTest(input)

            prediction = output[0]["value"][0][0]

            print_str = user+"\t"+target+"\t"+str(prediction)
            print print_str

def option_parser():
    usage = "python predict.py -n config -w model_dir -i input_file "
    parser = OptionParser(usage="usage: %s [options]" % usage)
    parser.add_option("-n", "--tconf", action="store",
                      dest="train_conf", help="network config")
    parser.add_option("-i", "--data", action="store",
                      dest="data", help="data file to predict")
    parser.add_option("-w", "--model", action="store",
                      dest="model_path", default=None,
                      help="model path")
    return parser.parse_args()

def main():
    options, args = option_parser()
    train_conf = options.train_conf
    data = options.data
    model_path = options.model_path
    swig_paddle.initPaddle("--use_gpu=0")
    predict = ModelPrediction(train_conf, model_path)
    predict.predict_onebyone(data)

trainer_config_gender_sparse.cluster.py

from paddle.trainer_config_helpers import *
import datetime

cluster_config(
        fs_name = "xxx",
        fs_ugi = "xxx",
        output_path="xxx")),
        train_data_path="xxx",
        test_data_path="xxx",
        use_remote_sparse=True,
)

is_predict = get_config_arg("is_predict", bool, False)
input_dim = 5000001
num_classes = 2

####################Data Configuration ##################
if not is_predict:
  data_dir='data/'
  define_py_data_sources2(train_list='train.list',
                          test_list=None,
                          module='ei_fea_provider_gender_sparse',
                          obj='processData')
settings(
    batch_size = 500,
    learning_method = AdaGradOptimizer(),
)
input = data_layer(name='input_fea', size=input_dim)
label = data_layer(name="label", size=num_classes)
#emb = embedding_layer(input=input, size=256, param_attr=ParamAttr(sparse_update=True))
#emb_sum = pooling_layer(input=emb, pooling_type=SumPooling())

hidden = fc_layer(input=input, size=256, act=ReluActivation(), param_attr=ParamAttr(sparse_update=True,l1_rate=0.1))
hidden = fc_layer(input=hidden, size=256, act=ReluActivation())
hidden = fc_layer(input=hidden, size=128, act=ReluActivation())
hidden = fc_layer(input=hidden, size=64, act=ReluActivation())
hidden = fc_layer(input=hidden, size=32, act=ReluActivation())
hidden = fc_layer(input=hidden, size=16, act=ReluActivation())
if not is_predict:
    prediction = fc_layer(input=hidden, size=num_classes, act=SoftmaxActivation())
    outputs(classification_cost(input=prediction,
                                label=label,
                                evaluator=[precision_recall_evaluator, classification_error_evaluator, auc_evaluator]))

    for i in range(num_classes):
        precision_recall_evaluator(name="PreRec of label [{0}]".format(i), input=prediction, label=label, positive_label=i)
else:
    prediction = fc_layer(input=hidden, size=num_classes, act=SoftmaxActivation())
    outputs([prediction])

样本例子:

user_id label0 962870217988607:3 985761982809793:3 838052250556224:2 3096226547944201:11

sjtuwy avatar Dec 21 '16 09:12 sjtuwy

如果方便的话,请print 一下 [[fea]] 是什么?

并且,请print fea的每一个元素的类型。 即 print [type(f) for f in fea]

reyoung avatar Dec 22 '16 03:12 reyoung

@reyoung

[[fea]] = [[[962870217988607, 985761982809793, 838052250556224, 3096226547944201]]]
[type(f) for f in fea] = [<type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>]

谢谢

sjtuwy avatar Dec 22 '16 07:12 sjtuwy

[[fea]] = [[[962870217988607, 985761982809793, 838052250556224, 3096226547944201]]] [type(f) for f in fea] = [<type 'int'>, <type 'int'>, <type 'int'>, <type 'int'>]

似乎,整数溢出了吧?确定词表有这么大么?我看您输入格式只有5000001 维

image

reyoung avatar Dec 26 '16 06:12 reyoung

@reyoung 溢出的问题修改了,在5000001维以内,错误信息如下。

[INFO 2016-12-27 21:25:38,093 networks.py:1466] The input order is [input_fea]
[INFO 2016-12-27 21:25:38,093 networks.py:1472] The output order is [__fc_layer_6__]
I1227 21:25:43.405248 36032 GradientMachine.cpp:124] Loading parameters from ./gender_sparse_model/pass-00019
fea_real=[4232013, 2444940, 3472766, 3402718, 541845, 1321254, 3825839, 2989268, 4993307, 1404956, 3876596, 3776472, 1774050, 1247972, 3915670, 3742419, 1626337, 1781204, 554499, 4578034, 2339924, 3461603, 3164138, 4095874, 2869975, 1307031, 3850338, 1321257, 1410748, 4343706, 3068598, 2246884, 4234774, 3756507, 3572636, 2286628, 4241786, 3781541, 4972651, 1589556, 1564922, 3759691, 3753991, 3850339, 2801540, 1133258, 1175348, 4222518, 1630820, 3405310, 2608973, 2448359, 3368525, 2474557, 4215543, 705703, 1412178, 2443690, 3556956, 1206244, 1649830, 1307882, 3453821, 2304684, 2957258, 3955264, 1889121, 2919762, 2306056, 975241, 833805, 830636, 3379310, 2628196, 1911485, 3151503, 1079508, 1594369, 3850109, 1795437, 1821061, 1940328, 3325302, 795293, 1194376, 2442037, 3174888, 619661, 2815571, 4993308, 2861903, 3107647, 2668888, 1503833, 3619351, 4502890, 1522229, 1106589, 2208151, 1763734, 4095770, 3772952, 1522228, 2298765, 3759823, 4542810, 3639492, 3954818, 2692226, 4143434, 1236958, 3718387, 2990616, 585008, 2296227, 3716563, 4096300, 3451155, 3048794, 3126574, 3915671, 1914599, 2579027, 1847742, 694754, 3167842, 4948656, 889217, 960607, 2176236, 3823212, 902702, 1132708, 3614659, 2875729, 3644832, 4399817, 3836288, 4393398, 2871682, 4212615, 4534326, 2521320, 2167387, 2483547, 2116529, 1259608, 3127001, 1389095, 3736983, 4420789, 1918798, 2220282, 2706597, 1193561, 3410390, 3745063, 4541598, 545315, 2056964, 1367559, 4215104, 2070875]
F1227 21:25:45.462760 36032 SparseRowMatrix.h:65] Check failed: globalIndices_[row] != kUnusedId_ (4294967295 vs. 4294967295) 
*** Check failure stack trace: ***
    @     0x7f10a377f068  google::LogMessage::Fail()
    @     0x7f10a377efc0  google::LogMessage::SendToLog()
    @     0x7f10a377ea55  google::LogMessage::Flush()
    @     0x7f10a3781816  google::LogMessageFatal::~LogMessageFatal()
    @     0x7f10a302bc0c  paddle::CpuMatrix::mul<>()
    @     0x7f10a301ebd7  paddle::CpuMatrix::mul()
    @     0x7f10a2eaa2ce  paddle::FullyConnectedLayer::forward()
    @     0x7f10a2f2ac84  paddle::NeuralNetwork::forward()
    @     0x7f10a2db60c6  _wrap_GradientMachine_forward
    @           0x4b4cb9  PyEval_EvalFrameEx
    @           0x4b6b28  PyEval_EvalCodeEx
    @           0x4b5d10  PyEval_EvalFrameEx
    @           0x4b6b28  PyEval_EvalCodeEx
    @           0x4b5d10  PyEval_EvalFrameEx
    @           0x4b5fb8  PyEval_EvalFrameEx
    @           0x4b5fb8  PyEval_EvalFrameEx
    @           0x4b6b28  PyEval_EvalCodeEx
    @           0x4b6c52  PyEval_EvalCode
    @           0x4e1c7d  PyRun_FileExFlags
    @           0x4e3501  PyRun_SimpleFileExFlags
    @           0x4159dd  Py_Main
    @     0x7f10af01fbd5  __libc_start_main
    @           0x414b71  (unknown)
predict.sh: line 27: 36032 Aborted                 python predict.py -n $config -w $model -i $predict_data > ./gender_sparse_data/20161112.res

sjtuwy avatar Dec 27 '16 13:12 sjtuwy

@sjtuwy 可以把sparse_update在预测的时候关掉。

reyoung avatar Jan 12 '17 04:01 reyoung

长时间没有更新,暂时close;如有进一步更新,欢迎reopen

QiJune avatar Jul 23 '17 01:07 QiJune