Commit 4b25b6fa authored by Yuxin Wu's avatar Yuxin Wu

update docs

parent c842bf51
...@@ -4,7 +4,7 @@ tensorpack.dataflow.imgaug package ...@@ -4,7 +4,7 @@ tensorpack.dataflow.imgaug package
This package contains Tensorpack's augmentors. This package contains Tensorpack's augmentors.
Note that other image augmentation libraries can be wrapped into Tensorpack's interface as well. Note that other image augmentation libraries can be wrapped into Tensorpack's interface as well.
For example, `imgaug.IAAugmentor <#tensorpack.dataflow.imgaug.IAAugmentor>`_ For example, `imgaug.IAAugmentor <#tensorpack.dataflow.imgaug.IAAugmentor>`_
and `imgaug.Albumentations <#tensorpack.dataflow.imgaug.Albumentations`_ and `imgaug.Albumentations <#tensorpack.dataflow.imgaug.Albumentations>`_
wrap two popular image augmentation libraries. wrap two popular image augmentation libraries.
.. container:: custom-index .. container:: custom-index
......
...@@ -555,7 +555,7 @@ if __name__ == '__main__': ...@@ -555,7 +555,7 @@ if __name__ == '__main__':
train_dataflow = get_train_dataflow() train_dataflow = get_train_dataflow()
# This is what's commonly referred to as "epochs" # This is what's commonly referred to as "epochs"
total_passes = cfg.TRAIN.LR_SCHEDULE[-1] * 8 / train_dataflow.size() total_passes = cfg.TRAIN.LR_SCHEDULE[-1] * 8 / train_dataflow.size()
logger.info("Total passes of the training set is: {}".format(total_passes)) logger.info("Total passes of the training set is: {:.5g}".format(total_passes))
callbacks = [ callbacks = [
PeriodicCallback( PeriodicCallback(
......
...@@ -10,7 +10,7 @@ __all__ = ['IAAugmentor', 'Albumentations'] ...@@ -10,7 +10,7 @@ __all__ = ['IAAugmentor', 'Albumentations']
class IAAugmentor(ImageAugmentor): class IAAugmentor(ImageAugmentor):
""" """
Wrap an augmentor form the IAA library: https://github.com/aleju/imgaug Wrap an augmentor form the IAA library: https://github.com/aleju/imgaug.
Both images and coordinates are supported. Both images and coordinates are supported.
Note: Note:
...@@ -20,6 +20,19 @@ class IAAugmentor(ImageAugmentor): ...@@ -20,6 +20,19 @@ class IAAugmentor(ImageAugmentor):
2. Only uint8 images are supported by the IAA library. 2. Only uint8 images are supported by the IAA library.
3. The IAA library can only produces images of the same shape. 3. The IAA library can only produces images of the same shape.
Example:
.. code-block:: python
from tensorpack import imgaug # this is not the aleju/imgaug library
from imgaug import augmentors as iaa # this is the aleju/imgaug library
myaug = imgaug.IAAugmentor(
iaa.Sequential([
iaa.Sharpen(alpha=(0, 1), lightness=(0.75, 1.5)),
iaa.Fliplr(0.5),
iaa.Crop(px=(0, 100)),
])
""" """
def __init__(self, augmentor): def __init__(self, augmentor):
...@@ -48,8 +61,16 @@ class IAAugmentor(ImageAugmentor): ...@@ -48,8 +61,16 @@ class IAAugmentor(ImageAugmentor):
class Albumentations(ImageAugmentor): class Albumentations(ImageAugmentor):
""" """
Wrap an augmentor form the albumentations library: https://github.com/albu/albumentations Wrap an augmentor form the albumentations library: https://github.com/albu/albumentations.
Coordinate augmentation is not supported by the library. Coordinate augmentation is not supported by the library.
Example:
.. code-block:: python
from tensorpack import imgaug
import albumentations as AB
myaug = imgaug.Albumentations(AB.RandomRotate90(p=1))
""" """
def __init__(self, augmentor): def __init__(self, augmentor):
""" """
......
...@@ -146,6 +146,9 @@ class MultiProcessPrefetchData(ProxyDataFlow): ...@@ -146,6 +146,9 @@ class MultiProcessPrefetchData(ProxyDataFlow):
3. You can nest like this: ``PrefetchDataZMQ(PrefetchData(df, nr_proc=a), nr_proc=b)``. 3. You can nest like this: ``PrefetchDataZMQ(PrefetchData(df, nr_proc=a), nr_proc=b)``.
A total of ``a`` instances of ``df`` worker processes will be created. A total of ``a`` instances of ``df`` worker processes will be created.
4. fork happens in `__init__`. `reset_state()` is a no-op. The worker processes won't get called. 4. fork happens in `__init__`. `reset_state()` is a no-op. The worker processes won't get called.
5. This DataFlow does support windows. However, Windows requires more strict picklability on processes,
which means that some code that's forkable on Linux may not be forkable on Windows. If that happens you'll
need to re-organize some part of code that's not forkable.
""" """
class _Worker(mp.Process): class _Worker(mp.Process):
...@@ -170,9 +173,10 @@ class MultiProcessPrefetchData(ProxyDataFlow): ...@@ -170,9 +173,10 @@ class MultiProcessPrefetchData(ProxyDataFlow):
nr_prefetch (int): size of the queue to hold prefetched datapoints. nr_prefetch (int): size of the queue to hold prefetched datapoints.
nr_proc (int): number of processes to use. nr_proc (int): number of processes to use.
""" """
# https://docs.python.org/3.6/library/multiprocessing.html?highlight=process#the-spawn-and-forkserver-start-methods
if os.name == 'nt': if os.name == 'nt':
logger.warn("MultiProcessPrefetchData does support windows. \ logger.warn("MultiProcessPrefetchData does support Windows. \
However, windows requires more strict picklability on processes, which may \ However, Windows requires more strict picklability on processes, which may \
lead of failure on some of the code.") lead of failure on some of the code.")
super(MultiProcessPrefetchData, self).__init__(ds) super(MultiProcessPrefetchData, self).__init__(ds)
try: try:
...@@ -210,8 +214,7 @@ PrefetchData = MultiProcessPrefetchData ...@@ -210,8 +214,7 @@ PrefetchData = MultiProcessPrefetchData
# TODO renamed to MultiProcessDataFlow{,ZMQ} if separated to a new project # TODO renamed to MultiProcessDataFlow{,ZMQ} if separated to a new project
class PrefetchDataZMQ(_MultiProcessZMQDataFlow): class PrefetchDataZMQ(_MultiProcessZMQDataFlow):
""" """
Prefetch data from a DataFlow using multiple processes, with ZeroMQ for Prefetch data from a DataFlow using multiple processes, with ZeroMQ for communication.
communication.
It will fork the calling process of :meth:`reset_state()`, It will fork the calling process of :meth:`reset_state()`,
and collect datapoints from the given dataflow in each process by ZeroMQ IPC pipe. and collect datapoints from the given dataflow in each process by ZeroMQ IPC pipe.
...@@ -237,7 +240,8 @@ class PrefetchDataZMQ(_MultiProcessZMQDataFlow): ...@@ -237,7 +240,8 @@ class PrefetchDataZMQ(_MultiProcessZMQDataFlow):
it won't be usable in the forked process. Therefore, do not nest two `PrefetchDataZMQ`. it won't be usable in the forked process. Therefore, do not nest two `PrefetchDataZMQ`.
5. (Thread-safety) ZMQ is not thread safe. Therefore, do not call :meth:`get_data` of the same dataflow in 5. (Thread-safety) ZMQ is not thread safe. Therefore, do not call :meth:`get_data` of the same dataflow in
more than 1 threads. more than 1 threads.
6. (For Mac only) A UNIX named pipe will be created in the current directory. 6. This dataflow does not support windows. Use `MultiProcessPrefetchData` which works on windows.
7. (For Mac only) A UNIX named pipe will be created in the current directory.
However, certain non-local filesystem such as NFS/GlusterFS/AFS doesn't always support pipes. However, certain non-local filesystem such as NFS/GlusterFS/AFS doesn't always support pipes.
You can change the directory by ``export TENSORPACK_PIPEDIR=/other/dir``. You can change the directory by ``export TENSORPACK_PIPEDIR=/other/dir``.
In particular, you can use somewhere under '/tmp' which is usually local. In particular, you can use somewhere under '/tmp' which is usually local.
......
...@@ -103,12 +103,13 @@ def BatchNorm(inputs, axis=None, training=None, momentum=0.9, epsilon=1e-5, ...@@ -103,12 +103,13 @@ def BatchNorm(inputs, axis=None, training=None, momentum=0.9, epsilon=1e-5,
It uses the aggregated statistics of the whole batch (across all MPI ranks) to normalize. It uses the aggregated statistics of the whole batch (across all MPI ranks) to normalize.
Note that on single machine this is significantly slower than the "nccl" implementation. Note that on single machine this is significantly slower than the "nccl" implementation.
This implementation averages the per-GPU E[x] and E[x^2] among GPUs to compute If not None, per-GPU E[x] and E[x^2] among all GPUs are averaged to compute
global mean & variance. Therefore each GPU needs to have the same batch size. global mean & variance. Therefore each GPU needs to have the same batch size.
It will match the BatchNorm layer on each GPU by its name (`BatchNorm('name', input)`).
If names do not match, the operation will hang.
This option has no effect when not training. The BatchNorm layer on each GPU needs to use the same name (`BatchNorm('name', input)`), so that
statistics can be reduced. If names do not match, this layer will hang.
This option only has effect in standard training mode.
This option is also known as "Cross-GPU BatchNorm" as mentioned in: This option is also known as "Cross-GPU BatchNorm" as mentioned in:
`MegDet: A Large Mini-Batch Object Detector <https://arxiv.org/abs/1711.07240>`_. `MegDet: A Large Mini-Batch Object Detector <https://arxiv.org/abs/1711.07240>`_.
......
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