天天看點

register_forward_hook

Torch Hook(鈎子)

register_forward_hook()

主要的作用是在不改變torch網絡的情況下擷取某一層的輸出

register_forward_hook

步驟:

  1. 對于網絡中的某一個層使用

    register_forward_hook

    方法,方法中傳入一個func函數,包裹了model,input,outpu。
  2. 函數回傳回一個handle,存在remove方法可以删除hook。