Commit 8f8ae315 authored by Yuxin Wu's avatar Yuxin Wu

update docs

parent ea0f1b90
...@@ -25,58 +25,54 @@ Therefore these features can be reused with one single line, as long as you are ...@@ -25,58 +25,54 @@ Therefore these features can be reused with one single line, as long as you are
For example, these are the callbacks I used when training a ResNet: For example, these are the callbacks I used when training a ResNet:
```python ```python
TrainConfig( callbacks=[
# ... # save the model every epoch
callbacks=[ ModelSaver(),
# save the model every epoch # backup the model with best validation error
ModelSaver(), MinSaver('val-error-top1'),
# backup the model with best validation error # run inference on another Dataflow every epoch, compute classification error and log to monitors
MinSaver('val-error-top1'), InferenceRunner(dataset_val, [
# run inference on another Dataflow every epoch, compute classification error and log to monitors ClassificationError('wrong-top1', 'val-error-top1'),
InferenceRunner(dataset_val, [ ClassificationError('wrong-top5', 'val-error-top5')]),
ClassificationError('wrong-top1', 'val-error-top1'), # schedule the learning rate based on epoch number
ClassificationError('wrong-top5', 'val-error-top5')]), ScheduledHyperParamSetter('learning_rate',
# schedule the learning rate based on epoch number [(30, 1e-2), (60, 1e-3), (85, 1e-4), (95, 1e-5)]),
ScheduledHyperParamSetter('learning_rate', # can manually change the learning rate through a file during training
[(30, 1e-2), (60, 1e-3), (85, 1e-4), (95, 1e-5)]), HumanHyperParamSetter('learning_rate'),
# can manually set the learning rate during training # send validation error to my phone through pushbullet
HumanHyperParamSetter('learning_rate'), SendStat('curl -u your_id_xxx: https://api.pushbullet.com/v2/pushes \\
# send validation error to my phone through pushbullet -d type=note -d title="validation error" \\
SendStat('curl -u your_id_xxx: https://api.pushbullet.com/v2/pushes \\ -d body={val-error-top1} > /dev/null 2>&1',
-d type=note -d title="validation error" \\ 'val-error-top1'),
-d body={val-error-top1} > /dev/null 2>&1', # record GPU utilizations during training
'val-error-top1'), GPUUtilizationTracker(),
# record GPU utilizations during training # can pause the training and start a debug shell, to observe what's going on
GPUUtilizationTracker(), InjectShell(shell='ipython')
# can pause the training and start a debug shell, to observe what's going on ] + [ # these callbacks are enabled by default already, though you can customize them
InjectShell(shell='ipython') # maintain those moving average summaries already defined in the model (e.g. training loss, training error)
], MovingAverageSummary(),
extra_callbacks=[ # these callbacks are enabled by default already # draw a nice progress bar
# maintain those moving average summaries already defined in the model (e.g. training loss, training error) ProgressBar(),
MovingAverageSummary(), # run `tf.summary.merge_all` every epoch and log to monitors
# draw a nice progress bar MergeAllSummaries(),
ProgressBar(), # run ops in GraphKeys.UPDATE_OPS collection along with training, if any
# run `tf.summary.merge_all` every epoch and log to monitors RunUpdateOps(),
MergeAllSummaries(), ],
# run ops in GraphKeys.UPDATE_OPS collection along with training, if any monitors=[ # monitors are a special kind of callbacks. these are also enabled by default
RunUpdateOps(), # write everything to tensorboard
], TFEventWriter(),
monitors=[ # monitors are a special kind of callbacks. these are also enabled by default # write all scalar data to a json file, for easy parsing
# write everything to tensorboard JSONWriter(),
TFEventWriter(), # print all scalar data every epoch (can be configured differently)
# write all scalar data to a json file, for easy parsing ScalarPrinter(),
JSONWriter(), ]
# print all scalar data every epoch (can be configured differently)
ScalarPrinter(),
]
)
``` ```
Notice that callbacks cover every detail of training, ranging from graph operations to the progress bar. Notice that callbacks cover every detail of training, ranging from graph operations to the progress bar.
This means you can customize every part of the training to your preference, e.g. display something This means you can customize every part of the training to your preference, e.g. display something
different in the progress bar, evaluating part of the summaries at a different frequency, etc. different in the progress bar, evaluating part of the summaries at a different frequency, etc.
These features may not be always useful, but think about how messy the main loop would look like if you These features may not be always useful, but think about how messy the main loop would look like if you
were to write the logic together with the loops, and how easy your life will be if you could enable were to write these logic together with the loops, and how easy your life will be if you could enable
these features with one line when you need them. these features with one line when you need them.
See [Write a callback](http://tensorpack.readthedocs.io/en/latest/tutorial/extend/callback.html) See [Write a callback](http://tensorpack.readthedocs.io/en/latest/tutorial/extend/callback.html)
......
## Write a Trainer ## Write a Trainer
**These contents are subject to change in later versions soon**. The existing trainers should be enough for single-tower single-cost optimization tasks.
If you just want to do some extra work during training, first consider writing it as a callback,
The existing trainers should be enough for single-cost optimization tasks.
If you want to do something different during training, first consider writing it as a callback,
or write an issue to see if there is a better solution than creating new trainers. or write an issue to see if there is a better solution than creating new trainers.
If your task is fundamentally different from single-cost optimization, you may need to write a trainer. If your task is fundamentally different from single-cost optimization, you will need to write a trainer.
Trainers are recently being redesigned, the they best wayt to customize the trainer will likely to change.
We leave the tutorial empty for now. Trainers just run __some__ iterations, so there is no limit in where the data come from or what to do in an iteration.
The existing common trainers all implement two things:
<!-- 1. Setup the graph and input pipeline, using the given `InputSource` and `get_cost_fn`.
-Trainers just run __some__ iterations, so there is no limit in where the data come from or what to do in an iteration. 2. Minimize `model.cost` in each iteration.
-The existing common trainers all implement two things:
-1. Setup the graph and input pipeline, using the given `TrainConfig`. But you can customize it by using or inheriting the base `Trainer` class.
-2. Minimize `model.cost` in each iteration. You will need to define two things for a new Trainer:
-
-But you can customize it by using the base `Trainer` class. 1. What is the graph.
- Add any tensors and ops you like, either before creating the trainer or inside `Trainer.__init__`.
-* To customize the graph:
- * What is the iteration. There are 2 ways to define an iteration:
- Add any tensors and ops you like, either before creating the trainer or inside `Trainer.__init__`. 1. Set `Trainer.train_op`. This op will be run by default.
- In this case you don't need to set model/data in `TrainConfig` any more. 2. Subclass `Trainer` and override the `run_step()` method. This way you can do something more than running an op.
-
-* Two ways to customize the iteration: There are several different [GAN trainers](../../examples/GAN/GAN.py) for reference.
-
- 1. Set `Trainer.train_op`. This op will be run by default.
- 2. Subclass `Trainer` and override the `run_step()` method. This way you can do something more than running an op.
-
-There are several different [GAN trainers](../../examples/GAN/GAN.py) for reference.
-The implementation of [SimpleTrainer](../../tensorpack/train/simple.py) may also be helpful.
-->
...@@ -8,7 +8,7 @@ from ..input_source import ( ...@@ -8,7 +8,7 @@ from ..input_source import (
InputSource, FeedInput, QueueInput, StagingInput, DummyConstantInput) InputSource, FeedInput, QueueInput, StagingInput, DummyConstantInput)
from ..trainv1.config import TrainConfig from ..trainv1.config import TrainConfig
from .base import SingleCostTrainer from .tower import SingleCostTrainer
from .trainers import SimpleTrainer, DistributedTrainerReplicated from .trainers import SimpleTrainer, DistributedTrainerReplicated
__all__ = ['launch_train_with_config', 'apply_default_prefetch'] __all__ = ['launch_train_with_config', 'apply_default_prefetch']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment