Skip to content
Snippets Groups Projects
Commit d7da5d90 authored by Anjith GEORGE's avatar Anjith GEORGE
Browse files

specify the names of all layers to adapt in configs and trainer

parent f2356e08
No related branches found
No related tags found
1 merge request!18MCCNN trainer
...@@ -87,7 +87,7 @@ learning_rate=0.0001 ...@@ -87,7 +87,7 @@ learning_rate=0.0001
seed = 3 seed = 3
output_dir = 'training_mccn' output_dir = 'training_mccn'
use_gpu = False use_gpu = False
adapted_layers = 'conv1-block1' adapted_layers = 'conv1-ffc'
adapt_reference_channel = False adapt_reference_channel = False
verbose = 2 verbose = 2
......
...@@ -19,7 +19,7 @@ Options: ...@@ -19,7 +19,7 @@ Options:
--batch-size=<int> Batch size [default: 64] --batch-size=<int> Batch size [default: 64]
--epochs=<int> Number of training epochs [default: 20] --epochs=<int> Number of training epochs [default: 20]
--learning-rate=<float> Learning rate [default: 0.01] --learning-rate=<float> Learning rate [default: 0.01]
--adapted-layers=<string> Layers to adapt in the training [default: conv1-block1-group1] --adapted-layers=<string> Layers to adapt in the training [default: conv1-block1-group1-ffc]
--adapt-reference-channel Flag deciding whether to adapt default channel as well [default: False] --adapt-reference-channel Flag deciding whether to adapt default channel as well [default: False]
-S, --seed=<int> The random seed [default: 3] -S, --seed=<int> The random seed [default: 3]
-o, --output-dir=<path> Dir to save stuff [default: training] -o, --output-dir=<path> Dir to save stuff [default: training]
...@@ -82,7 +82,7 @@ def main(user_input=None): ...@@ -82,7 +82,7 @@ def main(user_input=None):
output_dir = get_parameter(args, configuration, 'output_dir', 'training') output_dir = get_parameter(args, configuration, 'output_dir', 'training')
use_gpu = get_parameter(args, configuration, 'use_gpu', False) use_gpu = get_parameter(args, configuration, 'use_gpu', False)
verbosity_level = get_parameter(args, configuration, 'verbose', 0) verbosity_level = get_parameter(args, configuration, 'verbose', 0)
adapted_layers = get_parameter(args, configuration, 'adapted_layers', 'conv1-block1-group1') adapted_layers = get_parameter(args, configuration, 'adapted_layers', 'conv1-block1-group1-ffc')
adapt_reference_channel = get_parameter(args, configuration, 'adapt_reference_channel', False) adapt_reference_channel = get_parameter(args, configuration, 'adapt_reference_channel', False)
bob.core.log.set_verbosity_level(logger, verbosity_level) bob.core.log.set_verbosity_level(logger, verbosity_level)
......
...@@ -72,7 +72,7 @@ class MCCNNTrainer(object): ...@@ -72,7 +72,7 @@ class MCCNNTrainer(object):
""" """
def __init__(self, network, batch_size=64, use_gpu=False, adapted_layers='conv1-block1-group1',adapt_reference_channel=False, verbosity_level=2): def __init__(self, network, batch_size=64, use_gpu=False, adapted_layers='conv1-block1-group1-ffc',adapt_reference_channel=False, verbosity_level=2):
""" Init function . The layers to be adapted in the network is selected and the gradients are set to `True` """ Init function . The layers to be adapted in the network is selected and the gradients are set to `True`
for the layers which needs to be adapted. for the layers which needs to be adapted.
...@@ -86,7 +86,7 @@ class MCCNNTrainer(object): ...@@ -86,7 +86,7 @@ class MCCNNTrainer(object):
If you would like to use the gpu If you would like to use the gpu
adapted_layers: str adapted_layers: str
The blocks in the CNN to adapt; only the ones listed are adapted in the training. The layers are separated by '-' in the The blocks in the CNN to adapt; only the ones listed are adapted in the training. The layers are separated by '-' in the
string, for example 'conv1-block1-group1'. The fully connected layer in the output part are adapted always. string, for example 'conv1-block1-group1-ffc'. The fully connected layer in the output part are adapted always.
adapt_reference_channel: bool adapt_reference_channel: bool
If this value is `True` then 'ch_0' (which is the reference channel- usually, grayscale image) is also adapted. Otherwise the reference channel If this value is `True` then 'ch_0' (which is the reference channel- usually, grayscale image) is also adapted. Otherwise the reference channel
is not adapted, so that it can be used for Face recognition as well, default: `False`. is not adapted, so that it can be used for Face recognition as well, default: `False`.
...@@ -106,10 +106,14 @@ class MCCNNTrainer(object): ...@@ -106,10 +106,14 @@ class MCCNNTrainer(object):
layers_present = self.network.lcnn_layers layers_present = self.network.lcnn_layers
layers_present.append('ffc')
# select the layers in the network to adapt # select the layers in the network to adapt
adapted_layers_list=adapted_layers.split('-') adapted_layers_list=adapted_layers.split('-')
assert('ffc' in adapted_layers_list)
assert(set(adapted_layers_list)<=set(layers_present)) # to ensure layer names are valid assert(set(adapted_layers_list)<=set(layers_present)) # to ensure layer names are valid
if adapt_reference_channel:# whether to adapt the color channel if adapt_reference_channel:# whether to adapt the color channel
...@@ -124,8 +128,9 @@ class MCCNNTrainer(object): ...@@ -124,8 +128,9 @@ class MCCNNTrainer(object):
for i in range(start_index,self.network.num_channels): for i in range(start_index,self.network.num_channels):
for layer in adapted_layers_list: for layer in adapted_layers_list:
if layer!='ffc':
layers_to_adapt.append("layer_dict.ch_{}_".format(i)+layer) layers_to_adapt.append("layer_dict.ch_{}_".format(i)+layer)
layers_to_adapt = list(np.unique(layers_to_adapt)) layers_to_adapt = list(np.unique(layers_to_adapt))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment