'Filter out layers based on the current phase.'

def filter_layers(self, layers):

    phase_map = {0: 'train', 1: 'test'}
    filtered_layer_names = set()
    filtered_layers = []
    for layer in layers:
        phase = self.phase
        if len(layer.include):
            phase = phase_map[layer.include[0].phase]
        if len(layer.exclude):
            phase = phase_map[(1 - layer.include[0].phase)]
        exclude = (phase != self.phase)
        if ((not exclude) and (phase == 'test')):
            exclude = (layer.type == LayerType.Dropout)
        if (not exclude):
            filtered_layers.append(layer)
            assert (layer.name not in filtered_layer_names)
            filtered_layer_names.add(layer.name)
    return filtered_layers
