Get a block through a string notation of arguments. Args: block_string (str): A string notation of arguments. Examples: 'r1_k3_s11_e1_i32_o16_se0.25_noskip'. Returns: BlockArgs: The namedtuple defined at the top of this file.
(block_string)
| 296 | |
| 297 | @staticmethod |
| 298 | def _decode_block_string(block_string): |
| 299 | """Get a block through a string notation of arguments. |
| 300 | Args: |
| 301 | block_string (str): A string notation of arguments. |
| 302 | Examples: 'r1_k3_s11_e1_i32_o16_se0.25_noskip'. |
| 303 | Returns: |
| 304 | BlockArgs: The namedtuple defined at the top of this file. |
| 305 | """ |
| 306 | assert isinstance(block_string, str) |
| 307 | |
| 308 | ops = block_string.split('_') |
| 309 | options = {} |
| 310 | for op in ops: |
| 311 | splits = re.split(r'(\d.*)', op) |
| 312 | if len(splits) >= 2: |
| 313 | key, value = splits[:2] |
| 314 | options[key] = value |
| 315 | |
| 316 | # Check stride |
| 317 | assert (('s' in options and len(options['s']) == 1) or |
| 318 | (len(options['s']) == 2 and options['s'][0] == options['s'][1])) |
| 319 | |
| 320 | return BlockArgs( |
| 321 | num_repeat=int(options['r']), |
| 322 | kernel_size=int(options['k']), |
| 323 | stride=[int(options['s'][0])], |
| 324 | expand_ratio=int(options['e']), |
| 325 | input_filters=int(options['i']), |
| 326 | output_filters=int(options['o']), |
| 327 | se_ratio=float(options['se']) if 'se' in options else None, |
| 328 | id_skip=('noskip' not in block_string)) |
| 329 | |
| 330 | @staticmethod |
| 331 | def _encode_block_string(block): |