|
| 1 | + |
| 2 | + |
| 3 | +# This function is to parse strings from argparse into bool |
| 4 | +def str2bool(v): |
| 5 | + '''Convert string to boolean value |
| 6 | +
|
| 7 | + This function is from stackoverflow: |
| 8 | + https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse |
| 9 | +
|
| 10 | + Arguments: |
| 11 | + v {str} -- [description] |
| 12 | +
|
| 13 | + Returns: |
| 14 | + bool -- [description] |
| 15 | +
|
| 16 | + Raises: |
| 17 | + argparse -- [description] |
| 18 | + ''' |
| 19 | + if v.lower() in ('yes', 'true', 't', 'y', '1'): |
| 20 | + return True |
| 21 | + elif v.lower() in ('no', 'false', 'f', 'n', '0'): |
| 22 | + return False |
| 23 | + else: |
| 24 | + raise argparse.ArgumentTypeError('Boolean value expected.') |
| 25 | + |
| 26 | + |
| 27 | +class UResNetConfig(object): |
| 28 | + |
| 29 | + def __init__(self): |
| 30 | + self._name = "UResNet" |
| 31 | + self._help = "Tensorflow Implementation of multi-plane UResNet" |
| 32 | + |
| 33 | + def build_parser(self, parser): |
| 34 | + |
| 35 | + ################################################################## |
| 36 | + # Parameters to control the network implementation |
| 37 | + ################################################################## |
| 38 | + |
| 39 | + # Layerwise parameters: |
| 40 | + parser.add_argument('-ub','--use-bias', |
| 41 | + type = str2bool, |
| 42 | + default = True, |
| 43 | + help = "Whether or not to include bias terms in all learned layers.") |
| 44 | + |
| 45 | + parser.add_argument('-bn','--batch-norm', |
| 46 | + type = str2bool, |
| 47 | + default = True, |
| 48 | + help = "Whether or not to use batch normalization in all mlp layers.") |
| 49 | + |
| 50 | + # Network Architecture parameters: |
| 51 | + parser.add_argument('--n-initial-filters', |
| 52 | + type = int, |
| 53 | + default = 16, |
| 54 | + help = "Number of filters applied, per plane, for the initial convolution.") |
| 55 | + |
| 56 | + parser.add_argument('--blocks-per-layer', |
| 57 | + type = int, |
| 58 | + default = 2, |
| 59 | + help = "Number of blocks per layer.") |
| 60 | + |
| 61 | + parser.add_argument('--blocks-deepest-layer', |
| 62 | + type = int, |
| 63 | + default = 5, |
| 64 | + help = "Number of blocks applied at the deepest, merged layer.") |
| 65 | + |
| 66 | + parser.add_argument('--blocks-final', |
| 67 | + type = int, |
| 68 | + default = 0, |
| 69 | + help = "Number of blocks applied at full, final resolution.") |
| 70 | + |
| 71 | + parser.add_argument('--network-depth', |
| 72 | + type = int, |
| 73 | + default = 6, |
| 74 | + help = "Total number of downsamples to apply. Note: ensure depth + downsample =< 8") |
| 75 | + |
| 76 | + parser.add_argument("--filter-size-deepest", |
| 77 | + type = int, |
| 78 | + default = 5, |
| 79 | + help = "Convolutional window size for the deepest layer convolution.") |
| 80 | + |
| 81 | + parser.add_argument("--bottleneck-deepest", |
| 82 | + type = int, |
| 83 | + default = 256, |
| 84 | + help = "Bottleneck size for deepest layer convolution.") |
| 85 | + |
| 86 | + parser.add_argument('--connections', |
| 87 | + type = str, |
| 88 | + choices = ['sum', 'concat', 'none'], |
| 89 | + default = 'sum', |
| 90 | + help = "Connect shortcuts with sums, concat+bottleneck, or no connections.") |
| 91 | + |
| 92 | + parser.add_argument('--upsampling', |
| 93 | + type = str, |
| 94 | + choices = ["convolutional", "interpolation"], |
| 95 | + default = "interpolation", |
| 96 | + help = "Which operation to use for upsamplign.") |
| 97 | + |
| 98 | + parser.add_argument('--downsampling', |
| 99 | + type = str, |
| 100 | + choices = ["convolutional", "max_pooling"], |
| 101 | + default = "max_pooling", |
| 102 | + help = "Which operation to use for downsamplign.") |
| 103 | + |
| 104 | + parser.add_argument('--residual', |
| 105 | + type = str2bool, |
| 106 | + default = True, |
| 107 | + help = "Use residual units instead of convolutions.") |
| 108 | + |
| 109 | + |
| 110 | + parser.add_argument('-gr', '--growth-rate', |
| 111 | + type = str, |
| 112 | + choices = ['multiplicative','additive'], |
| 113 | + default = "additive", |
| 114 | + help = "Either double at each layer, or add a constant factor, to the number of filters.") |
| 115 | + |
| 116 | + parser.add_argument('--block-concat', |
| 117 | + type = str2bool, |
| 118 | + default = False, |
| 119 | + help = "Block the concatenations at the deepest layer (2D only).") |
| 120 | + |
| 121 | + |
| 122 | + |
0 commit comments