Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is meaning of hook that used in tensorflow

I couldn't understand the exact meaning of Hook in python, tensorflow

_LearningRateSetterHook(tf.train.SessionRun**Hook**):

I would greatly appreciate it if you explain it to me. Thank you

like image 685
Soulduck Avatar asked Sep 10 '17 02:09

Soulduck


People also ask

What is hook in Python?

A hook can tell about additional source files or data files to import, or files not to import. A hook file is a Python script, and can use all Python features. It can also import helper methods from PyInstaller. utils. hooks and useful variables from PyInstaller.

What is a hook in machine learning?

A hook is like a one of those devices that many heroes leave behind in the villain's den to get all the information. You can register a hook on a Tensor or a nn. Module . A hook is basically a function that is executed when the either forward or backward is called.


1 Answers

This could be a more general question about what hooks are.

Hooks are named appropriately in that they allow a way to 'hook into' certain points of the execution of a program. Thus you could trigger a function or logging after a certain part of the code executes.

To give an example I have listed the description of the SessionRunHook that you mentioned along with a link to its documentation. It specifically allows you to 'hook' into the mentioned points.

SessionRunHooks are useful to track training, report progress, request early stopping and more. SessionRunHooks use the observer pattern and notify at the following points:

  • when a session starts being used
  • before a call to the session.run()
  • after a call to the session.run()
  • when the session closed

A SessionRunHook encapsulates a piece of reusable/composable computation that can piggyback a call to MonitoredSession.run(). A hook can add any ops-or-tensor/feeds to the run call, and when the run call finishes with success gets the outputs it requested. Hooks are allowed to add ops to the graph in hook.begin(). The graph is finalized after the begin() method is called.

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/training/session_run_hook.py

like image 55
Lucas Hendren Avatar answered Oct 05 '22 22:10

Lucas Hendren