Giter Club home page Giter Club logo

Comments (8)

wangzhen38 avatar wangzhen38 commented on August 28, 2024

暂不支持该功能哈,你可以转成numpy,然后训练的时候参考这个load进来,

tmp_param = np.load(out_vec_path, encoding="bytes").astype(np.float32)

from paddlerec.

arbitraryking avatar arbitraryking commented on August 28, 2024

暂不支持该功能哈,你可以转成numpy,然后训练的时候参考这个load进来,

tmp_param = np.load(out_vec_path, encoding="bytes").astype(np.float32)

我不需要在后续训练导入,比如我的一条训练样本是[用户_id,特征1,...,特征n],模型最后一层会输出一个256维的向量,我要将这个向量和用户_id绑定存到本地

from paddlerec.

wangzhen38 avatar wangzhen38 commented on August 28, 2024

可以参考这个方式保存下来,print(numpy.array(scope.find_var("fc_0.w_0").get_tensor()))

from paddlerec.

arbitraryking avatar arbitraryking commented on August 28, 2024

这是我的static_model.py里net函数,cust_embedding是我要保存的,static_trainer.py里dataloader_train函数返回的net函数里的fetch_var

    def net(self, input, is_infer=False):
        self.label_input = input[0]
        self.sparse_inputs = input[1:self.sparse_inputs_slots]
        self.dense_input = input[-1]

        dnn_model = DNNLayer(
            self.sparse_feature_number,
            self.sparse_feature_dim,
            self.dense_input_dim,
            self.sparse_inputs_slots-1,
            self.fc_sizes,
            sync_mode=self.sync_mode)
        cust_embedding = dnn_model.forward(self.sparse_inputs,
                                           self.dense_input)

        output = paddle.matmul(cust_embedding,dnn_model.embedding[0].weight,transpose_y=True)
        predict = paddle.nn.functional.softmax(output)
        self.predict = predict
        accuracy = paddle.static.accuracy(input=self.predict,
                                              label=self.label_input,
                                              k = 100
                                              )


        self.inference_target_var = accuracy
        if is_infer:
            fetch_dict = {'accuracy': accuracy}
            return fetch_dict

        cost = fluid.layers.sampled_softmax_with_cross_entropy(logits=output,label=self.label_input,num_samples=400)
        avg_cost = paddle.mean(x=cost)
        self._cost = avg_cost
        fetch_dict = {'cost': avg_cost, 'accuracy': accuracy}
        return fetch_dict

我要把cust_embedding加到fetch_var里吗,还是说一个batch训练完后模型的这些计算结果在临时变量里
比如这样?

prog = paddle.static.default_main_program()
prog.list_vars()

from paddlerec.

wangzhen38 avatar wangzhen38 commented on August 28, 2024

应该不用放到fetch var里,训练完一个batch直接打印就行

from paddlerec.

arbitraryking avatar arbitraryking commented on August 28, 2024

打印不出来值呢,我参考了issue #28139

prog = paddle.static.default_main_program()
for var in prog.list_vars():
    if var.name=="relu_3.tmp_0":
        print(numpy.array(var))

打印出来是
var relu_3.tmp_0 : LOD_TENSOR.shape(8, 256).dtype(float32).stop_gradient(False)
没有值,var的type是<class 'paddle.fluid.framework.Variable'>
paddle.static.global_scope().find_var("relu_3.tmp_0").get_tensor()会报错

Traceback (most recent call last):
  File "tools/static_trainer.py", line 321, in <module>
    main(args)
  File "tools/static_trainer.py", line 175, in main    
    config, use_visual, log_visual, step_num)
  File "tools/static_trainer.py", line 309, in dataloader_train
    print(numpy.array(paddle.fluid.global_scope().find_var("relu_3.tmp_0").get_tensor()))
AttributeError: 'NoneType' object has no attribute 'get_tensor'

from paddlerec.

arbitraryking avatar arbitraryking commented on August 28, 2024

我试了很多,只有static.Print能打印出来,但是我保存不了具体的数值怎么办呢

prog = paddle.static.default_main_program()
for var in prog.list_vars():
if var.name=="relu_3.tmp_0":
       paddle.static.Print(var,summarize=-1)
       break
Variable: relu_3.tmp_0
  - lod: {}
  - place: Place(gpu:0)
  - shape: [8, 256]
  - layout: NCHW
  - dtype: float
  - data: [0.591841 0 0 0 0 0.422471 0 0 0 0 0 0.577771 0 0.399299 0 0 0 0 0 0 0 0 0 0 0 0 0 0.644693 0 0 0 0 0 0 0 0 0.243837 0 0.53221 0.503004 0 0 0 0 0.546784 
0 0 0 0 0 0 0 0 0 0 0 0 0 0.446295 0 0 0 0 0 0 0 0 0.425638 0.593102 0.573454 0 0 0 0 0 0 0 0 0 0 0.384188 0 0 0 0 0.476036 0 0 0 0 0 0 0.475764 0.676034 0 0 0 0 0 0 0 0.346013 0 0 0 0 0.670505 0 0 0 0 0.388909 0 0 0 0 0 0 0 0 0 0.552485 0 0 0 0.438703 0 0 0.532311 0 0 0 0 0 0.603588 0 0 0 0 0.498062 0 0 0 0.595748 0.202045 
0 0 0 0 0 0.274415 0 0 0 0 0 0 0 0 0.524153 0 0 0 0 0 0.374015 0 0.578514 0 0 0.0918211 0 0 0.556775 0.524173 0.602912 0 0 0 0 0 0.622055 0 0 0 0 0 0.454071 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.627964 0.369186 0 0 0 0 0.397849 0 0.398027 0 0 0.278987 0 0.47857 0.213926 0 0 0 0 0 0 0 0 0 0 0 0 0.339255 0 0 0 0 0 0 0 0 0 0.680945 0 0 0.462458 0 0 0.534009 0 0 0 0 0.515437 0 0.583943 0 0 0 0 0.419721 0 0 0 0 0 0.574524 0 0.393245 0 0 0 0 0 0 0 0 0 0 0 0 0 0.640296 0 0 0 0 0 0 0 0 0.241458 0 0.528706 0.497437 0 0 0 0 0.541945 0 0 0 0 0 0 0 0 0 0 0 0 0 0.445343 0 0 0 0 0 0 0 0 0.421288 0.588766 0.567267 0 0 0 0 0 0 0 0 0 0 0.381096 0 0 0 0 0.469899 0 0 0 0 0 0 0.474496 0.669303 0 0 0 0 0 0 0 0.340045 0 0 0 0 0.663732 0 0 0 0 0.384797 0 0 0 0 0 0 0 0 0 0.547808 0 0 0 0.432584 0 0 0.52691 0 0 0 0 0 0.597421 0 
0 0 0 0.493462 0 0 0 0.589367 0.200028 0 0 0 0 0 0.268497 0 0 0 0 0 0 0 0 0.518621 0 0 0 0 0 0.371784 0 0.570989 0 0 0.0915776 0 0 0.550141 0.520689 0.598367 0 0 0 0 0 0.616859 0 0 0 0 0 0.447525 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.619557 0.364891 0 0 0 0 0.393911 0 0.39721 0 0 0.277348 0 0.474247 0.212561 0 0 0 0 0 0 0 0 
0 0 0 0 0.339134 0 0 0 0 0 0 0 0 0 0.674615 0 0 0.459826 0 0 0.532574 0 0 0 0 0.511291 0 0.70059 0 0 0 0 0.502179 0 0 0 0 0 0.688526 0 0.477744 0 0 0 0 0 0 0 0 0 0 0 0 0 0.765217 0 0 0 0 0 0 0 0 0.291319 0 0.632337 0.587904 0 0 0 0 0.647348 0 0 0 0 0 0 0 0 0 0 0 0 0 0.529485 0 0 0 0 0 0 0 0 0.508437 0.697854 0.675243 0 0 0 0 0 0 0 0 0 0 0.455152 0 0 0 0 0.55737 0 0 0 0 0 0 0.568463 0.803233 0 0 0 0 0 0 0 0.415023 0 0 0 0 0.790647 0 0 0 0 0.46527 0 0 0 0 0 0 0 0 0 0.659385 0 0 0 0.523154 0 0 0.625451 0 0 0 0 0 0.709431 0 0 0 0 0.58988 0 0 0 0.70968 0.24299 0 0 0 0 0 0.325651 0 0 0 0 0 0 0 0 0.616455 0 0 0 0 0 0.443072 0 0.681783 0 0 0.107956 0 0 0.64796 0.622473 0.713836 0 0 0 0 0 0.736686 0 0 0 0 0 0.53423 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.739227 0.441721 0 0 0 0 0.473822 0 0.470344 0 0 0.331139 0 0.559957 0.25259 0 0 0 0 0 0 0 0 0 0 0 0 0.403075 0 0 0 0 0 0 0 0 0 0.80277 0 0 0.553409 0 0 0.641562 0 0 0 0 0.610591 0 0.700062 0 0 0 0 0.500978 0 0 0 0 0 0.686209 0 0.477366 0 0 0 0 0 0 0 0 0 0 0 0 0 0.762156 0 0 0 0 0 0 0 0 0.291737 0 0.630097 0.589682 0 0 0 0 0.645637 0 0 0 0 0 0 0 0 0 0 0 0 0 0.527443 0 0 0 0 0 0 0 0 0.507652 0.698653 0.674392 0 0 0 0 0 0 0 0 0 0 0.454083 0 0 0 0 0.558295 0 0 0 0 0 0 0.565034 0.804305 0 0 0 0 0 0 0 0.415691 0 0 0 0 0.791483 0 0 0 0 0.464821 0 0 0 
0 0 0 0 0 0 0.657266 0 0 0 0.522755 0 0 0.62504 0 0 0 0 0 0.708926 0 0 0 0 0.588849 0 0 0 0.708668 0.240515 0 0 0 0 0 0.326169 0 0 0 0 0 0 0 0 0.616607 0 0 0 0 0 0.442876 0 0.68312 0 0 0.108106 0 0 0.650403 0.621137 0.712252 0 0 0 0 0 0.734606 0 0 0 0 0 0.536753 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.739435 0.441011 0 0 0 0 0.472094 0 0.46934 0 0 0.329163 0 0.561221 0.249391 0 0 0 0 0 0 0 0 0 0 0 0 0.401199 0 0 0 0 0 0 0 0 0 0.801923 0 0 0.550233 0 0 0.639611 0 0 0 0 0.609856 0 0.697952 0 0 0 0 0.499118 0 0 0 0 0 0.683327 0 0.475479 0 0 0 0 0 0 0 0 0 0 0 0 0 0.760383 0 0 0 0 0 0 0 0 0.289123 0 0.629048 0.584536 0 0 0 0 0.643267 0 0 0 0 0 0 0 0 0 0 0 0 0 0.526257 0 0 0 0 0 0 0 0 0.505167 0.693324 0.670351 0 0 0 0 0 0 0 0 0 0 0.452829 0 0 0 0 0.553255 0 0 0 0 0 0 0.56648 0.798985 0 0 0 0 0 0 0 0.412436 0 0 
0 0 0.786091 0 0 0 0 0.462708 0 0 0 0 0 0 0 0 0 0.654136 0 0 0 0.520566 0 0 0.622236 0 0 0 0 0 0.703397 0 0 0 0 0.585099 0 0 0 0.705446 0.241919 0 0 0 0 0 0.323563 0 0 0 0 0 0 0 0 0.612963 0 0 0 0 0 0.441055 0 0.67726 0 0 0.107742 0 0 0.643705 0.618665 0.707939 0 0 0 0 0 0.730799 0 0 0 0 0 0.529778 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0.733767 0.437558 0 0 0 0 0.468927 0 0.466522 0 0 0.330259 0 0.555481 0.250603 0 0 0 0 0 0 0 0 0 0 0 0 0.399306 0 0 0 0 0 0 0 0 0 0.797389 0 0 0.54862 0 
0 0.637103 0 0 0 0 0.606564 0 0.692788 0 0 0 0 0.499238 0 0 0 0 0 0.680596 0 0.469897 0 0 0 0 0 0 0 0 0 0 0 0 0 0.757742 0 0 0 0 0 0 0 0 0.2846 0 0.623601 0.582739 0 0 0 0 0.640332 0 0 0 0 0 0 0 0 0 0 0 0 0 0.521159 0 0 0 0 0 0 0 0 0.501036 0.688789 0.669911 0 0 0 0 0 0 0 0 0 0 0.446946 0 0 0 0 0.555907 0 0 0 0 0 0 0.560088 
0.796207 0 0 0 0 0 0 0 0.409527 0 0 0 0 0.785173 0 0 0 0 0.459692 0 0 0 0 0 0 0 0 0 0.653767 0 0 0 0.519335 0 0 0.623501 0 0 0 0 0 0.704599 0 0 0 0 0.582874 0 0 0 
0.699861 0.239578 0 0 0 0 0 0.324583 0 0 0 0 0 0 0 0 0.611112 0 0 0 0 0 0.438169 0 0.674729 0 0 0.105543 0 0 0.644508 0.615558 0.707815 0 0 0 0 0 0.727699 0 0 0 0 
0 0.529077 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.735893 0.433837 0 0 0 0 0.46857 0 0.466794 0 0 0.32816 0 0.555955 0.250008 0 0 0 0 0 0 0 0 0 0 0 0 0.398219 0 0 0 
0 0 0 0 0 0 0.795853 0 0 0.545563 0 0 0.633068 0 0 0 0 0.603729 0 0.750238 0 0 0 0 0.538376 0 0 0 0 0 0.738288 0 0.508358 0 0 0 0 0 0 0 0 0 0 0 0 0 0.820285 0 0 0 
0 0 0 0 0 0.313744 0 0.67502 0.63042 0 0 0 0 0.694357 0 0 0 0 0 0 0 0 0 0 0 0 0 0.564091 0 0 0 0 0 0 0 0 0.543606 0.74995 0.727073 0 0 0 0 0 0 0 0 0 0 0.485892 0 0 0 0 0.603291 0 0 0 0 0 0 0.602375 0.862737 0 0 0 0 0 0 0 0.447118 0 0 0 0 0.851866 0 0 0 0 0.499503 0 0 0 0 0 0 0 0 0 0.708074 0 0 0 0.562059 0 0 0.673609 0 0 0 0 0 0.763987 0 0 0 0 0.633585 0 0 0 0.760494 0.259873 0 0 0 0 0 0.353016 0 0 0 0 0 0 0 0 0.662725 0 0 0 0 0 0.474067 0 0.734971 0 0 0.115309 0 0 0.699016 0.667346 0.7678 0 0 0 0 0 0.788295 0 0 0 0 0 0.576898 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.797185 0.473616 0 0 0 0 0.51173 0 0.505376 0 0 0.351449 0 0.606932 0.266331 0 0 0 0 0 0 0 0 0 0 0 0 0.429488 0 0 0 0 0 0 0 0 0 0.86464 0 0 0.592836 0 0 0.68797 0 0 0 0 0.652404 0 0.568288 0 0 0 0 0.40479 0 0 0 0 0 0.553955 0 0.384181 0 0 0 0 0 
0 0 0 0 0 0 0 0 0.61893 0 0 0 0 0 0 0 0 0.234182 0 0.512378 0.483637 0 0 0 0 0.524125 0 0 0 0 0 0 0 0 0 0 0 0 0 0.430674 0 0 0 0 0 0 0 0 0.410513 0.569897 0.547468 0 0 0 0 0 0 0 0 0 0 0.367886 0 0 0 0 0.454049 0 0 0 0 0 0 0.461358 0.650509 0 0 0 0 0 0 0 0.330241 0 0 0 0 0.640599 0 0 0 0 0.374114 0 0 0 0 0 0 0 0 0 0.528162 0 
0 0 0.42029 0 0 0.512172 0 0 0 0 0 0.575738 0 0 0 0 0.47623 0 0 0 0.571212 0.19036 0 0 0 0 0 0.260553 0 0 0 0 0 0 0 0 0.503375 0 0 0 0 0 0.358485 0 0.55339 0 0 0.0875142 0 0 0.532793 0.503212 0.577534 0 0 0 0 0 0.596736 0 0 0 0 0 0.435336 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.600359 0.352147 0 0 0 0 0.377728 0 0.380957 0 0 0.270135 0 0.456722 0.205839 0 0 0 0 0 0 0 0 0 0 0 0 0.327369 0 0 0 0 0 0 0 0 0 0.649936 0 0 0.44349 0 0 0.513619 0 0 0 0 0.496125 0]

from paddlerec.

arbitraryking avatar arbitraryking commented on August 28, 2024

持久化variable都可以通过名字直接打印具体值,非持久化的我只发现放到fetch_dict可行。

from paddlerec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.