Commit 641c4b25 authored by Yuxin Wu's avatar Yuxin Wu

add some docs

parent fc0f6fca
...@@ -20,10 +20,11 @@ Models can be [downloaded here](http://models.tensorpack.com/ResNet/). ...@@ -20,10 +20,11 @@ Models can be [downloaded here](http://models.tensorpack.com/ResNet/).
| ResNet101 | 6.04% | 21.95% | | ResNet101 | 6.04% | 21.95% |
| ResNet152 | 5.78% | 21.51% | | ResNet152 | 5.78% | 21.51% |
To train, just run: To train, first decompress ImageNet data into [this structure](http://tensorpack.readthedocs.io/en/latest/modules/dataflow.dataset.html#tensorpack.dataflow.dataset.ILSVRC12), then:
```bash ```bash
./imagenet-resnet.py --data /path/to/original/ILSVRC --gpu 0,1,2,3 -d 50 [--mode resnet/preact/se] ./imagenet-resnet.py --data /path/to/original/ILSVRC --gpu 0,1,2,3 -d 50 [--mode resnet/preact/se]
``` ```
You should be able to see good GPU utilization (95%~99%), if your data is fast enough. You should be able to see good GPU utilization (95%~99%), if your data is fast enough.
The default data pipeline is probably OK for most systems. The default data pipeline is probably OK for most systems.
See the [tutorial](http://tensorpack.readthedocs.io/en/latest/tutorial/efficient-dataflow.html) on other options to speed up your data. See the [tutorial](http://tensorpack.readthedocs.io/en/latest/tutorial/efficient-dataflow.html) on other options to speed up your data.
......
...@@ -173,17 +173,17 @@ class ILSVRC12(ILSVRC12Files): ...@@ -173,17 +173,17 @@ class ILSVRC12(ILSVRC12Files):
shuffle=None, dir_structure=None): shuffle=None, dir_structure=None):
""" """
Args: Args:
dir (str): A directory containing a subdir named ``name``, where the dir (str): A directory containing a subdir named ``name``,
original ``ILSVRC12_img_{name}.tar`` gets decompressed. containing the images in a structure described below.
name (str): 'train' or 'val' or 'test'. name (str): One of 'train' or 'val' or 'test'.
shuffle (bool): shuffle the dataset. shuffle (bool): shuffle the dataset.
Defaults to True if name=='train'. Defaults to True if name=='train'.
dir_structure (str): The directory structure of 'val' and 'test' directory. dir_structure (str): One of 'original' or 'train'.
'original' means the original decompressed The directory structure for the 'val' directory.
directory, which only has list of image files (as below). 'original' means the original decompressed directory, which only has list of image files (as below).
If set to 'train', it expects the same two-level If set to 'train', it expects the same two-level directory structure simlar to 'dir/train/'.
directory structure simlar to 'train/'.
By default, it tries to automatically detect the structure. By default, it tries to automatically detect the structure.
You probably do not need to care about this option because 'original' is what people usually have.
Examples: Examples:
...@@ -213,6 +213,25 @@ class ILSVRC12(ILSVRC12Files): ...@@ -213,6 +213,25 @@ class ILSVRC12(ILSVRC12Files):
mkdir test && tar xvf ILSVRC12_img_test.tar -C test mkdir test && tar xvf ILSVRC12_img_test.tar -C test
mkdir train && tar xvf ILSVRC12_img_train.tar -C train && cd train mkdir train && tar xvf ILSVRC12_img_train.tar -C train && cd train
find -type f -name '*.tar' | parallel -P 10 'echo {} && mkdir -p {/.} && tar xf {} -C {/.}' find -type f -name '*.tar' | parallel -P 10 'echo {} && mkdir -p {/.} && tar xf {} -C {/.}'
When `dir_structure=='train'`, `dir` should have the following structure:
.. code-block:: none
dir/
train/
n02134418/
n02134418_198.JPEG
...
...
val/
n01440764/
ILSVRC2012_val_00000293.JPEG
...
...
test/
ILSVRC2012_test_00000001.JPEG
...
""" """
super(ILSVRC12, self).__init__( super(ILSVRC12, self).__init__(
dir, name, meta_dir, shuffle, dir_structure) dir, name, meta_dir, shuffle, dir_structure)
......
...@@ -14,8 +14,8 @@ __all__ = ['regularize_cost', 'l2_regularizer', 'l1_regularizer', 'Dropout'] ...@@ -14,8 +14,8 @@ __all__ = ['regularize_cost', 'l2_regularizer', 'l1_regularizer', 'Dropout']
@graph_memoized @graph_memoized
def _log_regularizer(name): def _log_once(msg):
logger.info("Apply regularizer for {}".format(name)) logger.info(msg)
l2_regularizer = tf.contrib.layers.l2_regularizer l2_regularizer = tf.contrib.layers.l2_regularizer
...@@ -56,7 +56,7 @@ def regularize_cost(regex, func, name='regularize_cost'): ...@@ -56,7 +56,7 @@ def regularize_cost(regex, func, name='regularize_cost'):
else: else:
params = tf.trainable_variables() params = tf.trainable_variables()
to_regularize = [] names = []
with tf.name_scope(name + '_internals'): with tf.name_scope(name + '_internals'):
costs = [] costs = []
...@@ -64,7 +64,7 @@ def regularize_cost(regex, func, name='regularize_cost'): ...@@ -64,7 +64,7 @@ def regularize_cost(regex, func, name='regularize_cost'):
para_name = p.op.name para_name = p.op.name
if re.search(regex, para_name): if re.search(regex, para_name):
costs.append(func(p)) costs.append(func(p))
to_regularize.append(p.name) names.append(p.name)
if not costs: if not costs:
return tf.constant(0, dtype=tf.float32, name='empty_' + name) return tf.constant(0, dtype=tf.float32, name='empty_' + name)
...@@ -77,9 +77,9 @@ def regularize_cost(regex, func, name='regularize_cost'): ...@@ -77,9 +77,9 @@ def regularize_cost(regex, func, name='regularize_cost'):
if name.startswith(prefix): if name.startswith(prefix):
return name[prefixlen:] return name[prefixlen:]
return name return name
to_regularize = list(map(f, to_regularize)) names = list(map(f, names))
to_print = ', '.join(to_regularize) logger.info("regularize_cost() found {} tensors.".format(len(names)))
_log_regularizer(to_print) _log_once("Applying regularizer for {}".format(', '.join(names)))
return tf.add_n(costs, name=name) return tf.add_n(costs, name=name)
...@@ -106,7 +106,7 @@ def regularize_cost_from_collection(name='regularize_cost'): ...@@ -106,7 +106,7 @@ def regularize_cost_from_collection(name='regularize_cost'):
else: else:
losses = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES) losses = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
if len(losses) > 0: if len(losses) > 0:
logger.info("Add REGULARIZATION_LOSSES of {} tensors on the total cost.".format(len(losses))) logger.info("regularize_cost_from_collection() found {} tensors in REGULARIZATION_LOSSES.".format(len(losses)))
reg_loss = tf.add_n(losses, name=name) reg_loss = tf.add_n(losses, name=name)
return reg_loss return reg_loss
else: else:
......
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