Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

Error loading topology file generated by book/fit_a_line.py 不能正确load图结构文件

Open rulai-huiyingl opened this issue 8 years ago • 2 comments

I used the following code to load the graph topology file generated by fit_a_line.py

import paddle.v2 as paddle
params = paddle.parameters.Parameters.from_tar(open('params_pass_0.tar'))
inferer = paddle.inference.Inference(parameters=params, fileobj=open('inference_topology.pkl'))

and the output is as follows:

WARNING: Logging before InitGoogleLogging() is written to STDERR
F1206 19:09:04.177959 21204 ClassRegistrar.h:65] Check failed: mapGet(type, creatorMap_, &creator) Unknown class type: data
*** Check failure stack trace: ***
Aborted (core dumped)

I wrote the code following the instruction in paddle/v2/inference.py:

 class Inference(object):
     """
     Inference combines neural network output and parameters together
     to do inference.
 
     ..  code-block:: python
 
         inferer = Inference(output_layer=prediction, parameters=parameters)
         for data_batch in batches:
             print inferer.infer(data_batch)
 
 
     :param output_layer: The neural network that should be inferenced.
     :type output_layer: paddle.v2.config_base.Layer or the sequence
                         of paddle.v2.config_base.Layer
     :param parameters: The parameters dictionary.
     :type parameters: paddle.v2.parameters.Parameters
     """
 
     def __init__(self, parameters, output_layer=None, fileobj=None):
         import py_paddle.swig_paddle as api
 
         if output_layer is not None:
             topo = topology.Topology(output_layer)
             gm = api.GradientMachine.createFromConfigProto(
                 topo.proto(), api.CREATE_MODE_TESTING, [api.PARAMETER_VALUE])
             self.__data_types__ = topo.data_type()
         elif fileobj is not None:
             tmp = cPickle.load(fileobj)
             gm = api.GradientMachine.createByConfigProtoStr(
                 tmp['protobin'], api.CREATE_MODE_TESTING,
                 [api.PARAMETER_VALUE])
             self.__data_types__ = tmp['data_type']
         else:
             raise ValueError("Either output_layer or fileobj must be set")
 
        ...

Could you please let me know where I did wrong that the topology file won't load? Same issue with topology file saved by other paddle programs I wrote.... Thank you! 多谢多谢!

rulai-huiyingl avatar Dec 07 '17 04:12 rulai-huiyingl

你好 有个类似的issue 请先check一下 https://github.com/PaddlePaddle/Paddle/issues/3533

peterzhang2029 avatar Dec 07 '17 05:12 peterzhang2029

好的谢谢。 测试了一下,实际上是因为没有paddle.init 只要init成功了use_gpu是true还是false都是好使的。 谢谢你的pointer!鞠躬!

rulai-huiyingl avatar Dec 07 '17 05:12 rulai-huiyingl