Skip to content

Comments

Get output when training#3978

Merged
typhoonzero merged 2 commits intoPaddlePaddle:developfrom
typhoonzero:fix_get_output_when_training
Sep 11, 2017
Merged

Get output when training#3978
typhoonzero merged 2 commits intoPaddlePaddle:developfrom
typhoonzero:fix_get_output_when_training

Conversation

@typhoonzero
Copy link
Contributor

@typhoonzero typhoonzero commented Sep 8, 2017

Fix #3953

Then we can do:

def event_handler(event):
    if isinstance(event, paddle.event.EndIteration):
        if event.batch_id % 100 == 0:
            print "Batch output", event.gm.getLayerOutputs("y_predict")
            print "Label output", event.gm.getLayerOutputs("label")
            print "Pass %d, Batch %d, Cost %f" % (
                event.pass_id, event.batch_id, event.cost)

    if isinstance(event, paddle.event.EndPass):
        print "Pass end: ", event.gm.getLayerOutputs("y_predict")

class EndPass(WithMetric):
"""
Event On One Pass Training Complete.
To get output of specific layer, add "event.gm.getLayerOutputs('predict_layer')"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get the output of a specific layer

class EndIteration(WithMetric):
"""
Event On One Batch Training Complete.
To get output of specific layer, add "event.gm.getLayerOutputs('predict_layer')"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get the output of a specific layer

def __init__(self, pass_id, evaluator):
def __init__(self, pass_id, evaluator, gm):
self.pass_id = pass_id
self.gm = gm
Copy link
Contributor

@lcy-seso lcy-seso Sep 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有没有可能把这个 gm 再封一层,只提供 getLayerOutput 方法,只接受一个layer_name作为参数。如果用户能拿到这个 gm 应该可以操作很多东西,似乎有点危险。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我理解也没必要再wrap好多层了,如果用户期望那到gm做“危险”的事情,那必然也需要对比较底层的hack比较清楚。因为文档只写了调用getLayerOutputs,一般用户也不会调用其他的方法。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯~ 明白了。

Copy link
Contributor

@lcy-seso lcy-seso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@typhoonzero typhoonzero merged commit d34516f into PaddlePaddle:develop Sep 11, 2017
@HynUx
Copy link

HynUx commented Nov 16, 2017

求问,

  1. 请问这个gm是什么? 哪里定义的? 文档和api里似乎都没看到, 只有event这里提及了怎么用?
  2. 我试着用gm输出中间层结果, 为啥似乎event.EndIteration/Pass的event instance下都说没有gm?
    说: AttributeError: 'EndPass' object has no attribute 'gm'

@typhoonzero typhoonzero deleted the fix_get_output_when_training branch December 22, 2017 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants