x = inputs x = builder.conv2d(x, 32, 3, 2, 'VALID') x = builder.conv2d(x, 32, 3, 1, 'VALID') x = builder.conv2d(x, 64, 3, 1, 'SAME') x = builder.max_pooling2d(x, 3, 2, 'VALID') x = builder.conv2d(x, 80, 1, 1, 'VALID') x = builder.conv2d(x, 192, 3, 1, 'VALID') x = builder.max_pooling2d(x, 3, 2, 'VALID') x = inception_v3_a(builder, x, 32) x = inception_v3_a(builder, x, 64) x = inception_v3_a(builder, x, 64) x = inception_v3_b(builder, x) x = inception_v3_c(builder, x, 128) x = inception_v3_c(builder, x, 160) x = inception_v3_c(builder, x, 160) x = inception_v3_c(builder, x, 192) x = inception_v3_d(builder, x) x = inception_v3_e(builder, x, 'AVG') x = inception_v3_e(builder, x, 'MAX') return builder.spatial_average2d(x) if args['predict']: if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.predict(inception_v3, args) else: nvutils.train(inception_v3, args) if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.validate(inception_v3, args)
default_args = { 'image_width': 224, 'image_height': 224, 'distort_color': False, 'momentum': 0.9, 'loss_scale': 128.0, # The following params can be changed by cmdline options. 'image_format': 'channels_last', 'data_dir': None, 'data_idx_dir': None, 'batch_size': 256, 'num_iter': 300, 'iter_unit': 'batch', 'log_dir': None, 'export_dir': None, 'tensorboard_dir': None, 'display_every': 10, 'precision': 'fp16', 'dali_mode': None, 'use_xla': False, 'predict': False, 'use_dali': "GPU", } args = nvutils.parse_cmdline(default_args) if args['predict']: nvutils.predict(args) else: nvutils.train(resnet50, args)
return x residual_scale = 0.2 x = inputs x = builder.conv2d(x, 32, 3, 2, 'VALID') x = builder.conv2d(x, 32, 3, 1, 'VALID') x = builder.conv2d(x, 64, 3, 1, 'SAME') x = inception_v4_sa(x) x = inception_v4_sb(x) x = inception_v4_sc(x) for _ in range(5): x = builder.residual2d(x, inception_resnet_v2_a, scale=residual_scale) x = inception_v4_ra(x, 256, 256, 384, 384) for _ in range(10): x = builder.residual2d(x, inception_resnet_v2_b, scale=residual_scale) x = inception_resnet_v2_rb(x) for _ in range(5): x = builder.residual2d(x, inception_resnet_v2_c, scale=residual_scale) x = builder.spatial_average2d(x) x = builder.dropout(x, 0.8) return x if args['predict']: if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.predict(inception_resnet_v2, args) else: nvutils.train(inception_resnet_v2, args) if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.validate(inception_resnet_v2, args)
'learning_rate_power': 2.0, 'weight_decay': 1e-4, 'loss_scale': None, 'larc_eta': None, 'larc_mode': None, 'num_iter': 500, 'checkpoint_secs': None, 'display_every': 10, 'iter_unit': 'batch' } args, _ = nvutils.parse_cmdline(default_args) def trivial(inputs, training=False): """A trivial model for benchmarking input pipeline performance""" builder = nvutils.LayerBuilder(tf.nn.relu, args['image_format'], training) x = inputs x = builder.flatten2d(x) x = builder.dense_linear(x, 1) return x if args['predict']: if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.predict(trivial, args) else: nvutils.train(trivial, args) if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.validate(trivial, args)
for _ in range(layer_counts[3]): x = builder.conv2d(x, 512, 3, 1, 'SAME') x = builder.max_pooling2d(x, 2, 2) for _ in range(layer_counts[4]): x = builder.conv2d(x, 512, 3, 1, 'SAME') x = builder.max_pooling2d(x, 2, 2) x = builder.flatten2d(x) x = builder.dense(x, 4096) x = builder.dense(x, 4096) return x def vgg(inputs, training=False): """Visual Geometry Group's family of models https://arxiv.org/abs/1409.1556 """ builder = nvutils.LayerBuilder(tf.nn.relu, args['image_format'], training) if flags.layers == 11: return inference_vgg_impl(builder, inputs, [1,1,2,2,2]) # A elif flags.layers == 13: return inference_vgg_impl(builder, inputs, [2,2,2,2,2]) # B elif flags.layers == 16: return inference_vgg_impl(builder, inputs, [2,2,3,3,3]) # D elif flags.layers == 19: return inference_vgg_impl(builder, inputs, [2,2,4,4,4]) # E else: raise ValueError("Invalid nlayer (%i); must be one of: 11,13,16,19" % flags.layers) if args['predict']: if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.predict(vgg, args) else: nvutils.train(vgg, args) if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.validate(vgg, args)
builder = nvutils.LayerBuilder(tf.nn.relu, args['image_format'], training) x = inputs x = builder.conv2d(x, 64, 7, 2, 'SAME') x = builder.max_pooling2d(x, 3, 2, 'SAME') x = builder.conv2d(x, 64, 1, 1, 'SAME') x = builder.conv2d(x, 192, 3, 1, 'SAME') x = builder.max_pooling2d(x, 3, 2, 'SAME') x = inception_v1(builder, x, 64, 96, 128, 16, 32, 32) x = inception_v1(builder, x, 128, 128, 192, 32, 96, 64) x = builder.max_pooling2d(x, 3, 2, 'SAME') x = inception_v1(builder, x, 192, 96, 208, 16, 48, 64) x = inception_v1(builder, x, 160, 112, 224, 24, 64, 64) x = inception_v1(builder, x, 128, 128, 256, 24, 64, 64) x = inception_v1(builder, x, 112, 144, 288, 32, 64, 64) x = inception_v1(builder, x, 256, 160, 320, 32, 128, 128) x = builder.max_pooling2d(x, 3, 2, 'SAME') x = inception_v1(builder, x, 256, 160, 320, 32, 128, 128) x = inception_v1(builder, x, 384, 192, 384, 48, 128, 128) x = builder.spatial_average2d(x) return x if args['predict']: if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.predict(googlenet, args) else: nvutils.train(googlenet, args) if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.validate(googlenet, args)
def alexnet_owt(inputs, training): """Alexnet One Weird Trick model https://arxiv.org/abs/1404.5997 """ builder = nvutils.LayerBuilder(tf.nn.relu, args['image_format'], training) # Note: VALID requires padding the images by 3 in width and height x = inputs x = builder.conv2d(x, 64, 11, 4, 'VALID') x = builder.max_pooling2d(x, 3, 2) x = builder.conv2d(x, 192, 5, 1, 'SAME') x = builder.max_pooling2d(x, 3, 2) x = builder.conv2d(x, 384, 3, 1, 'SAME') x = builder.conv2d(x, 256, 3, 1, 'SAME') x = builder.conv2d(x, 256, 3, 1, 'SAME') x = builder.max_pooling2d(x, 3, 2) x = builder.flatten2d(x) x = builder.dense(x, 4096) x = builder.dropout(x) x = builder.dense(x, 4096) x = builder.dropout(x) return x if args['predict']: if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.predict(alexnet_owt, args) else: nvutils.train(alexnet_owt, args) if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.validate(alexnet_owt, args)
x = resnet_bottleneck_v1(builder, x, 256, 64, 1, basic) for i in range(layer_counts[1]): x = resnet_bottleneck_v1(builder, x, 512, 128, 2 if i==0 else 1, basic) for i in range(layer_counts[2]): x = resnet_bottleneck_v1(builder, x, 1024, 256, 2 if i==0 else 1, basic) for i in range(layer_counts[3]): x = resnet_bottleneck_v1(builder, x, 2048, 512, 2 if i==0 else 1, basic) return builder.spatial_average2d(x) def resnet_v1(inputs, training=False): """Deep Residual Networks family of models https://arxiv.org/abs/1512.03385 """ builder = nvutils.LayerBuilder(tf.nn.relu, args['image_format'], training, use_batch_norm=True) if flags.layers == 18: return inference_resnet_v1_impl(builder, inputs, [2,2, 2,2], basic=True) elif flags.layers == 34: return inference_resnet_v1_impl(builder, inputs, [3,4, 6,3], basic=True) elif flags.layers == 50: return inference_resnet_v1_impl(builder, inputs, [3,4, 6,3]) elif flags.layers == 101: return inference_resnet_v1_impl(builder, inputs, [3,4,23,3]) elif flags.layers == 152: return inference_resnet_v1_impl(builder, inputs, [3,8,36,3]) else: raise ValueError("Invalid layer count (%i); must be one of: 18,34,50,101,152" % flags.layers) if args['predict']: if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.predict(resnet_v1, args) else: nvutils.train(resnet_v1, args) if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.validate(resnet_v1, args)
} args, _ = nvutils.parse_cmdline(default_args) def overfeat(inputs, training=False): builder = nvutils.LayerBuilder(tf.nn.relu, args['image_format'], training) x = inputs x = builder.conv2d(x, 96, 11, 4, 'VALID') x = builder.max_pooling2d(x, 2, 2, 'VALID') x = builder.conv2d(x, 256, 5, 1, 'VALID') x = builder.max_pooling2d(x, 2, 2, 'VALID') x = builder.conv2d(x, 512, 3, 1, 'SAME') x = builder.conv2d(x, 1024, 3, 1, 'SAME') x = builder.conv2d(x, 1024, 3, 1, 'SAME') x = builder.max_pooling2d(x, 2, 2, 'VALID') x = builder.flatten2d(x) x = builder.dense(x, 3072) x = builder.dense(x, 4096) return x if args['predict']: if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.predict(overfeat, args) else: nvutils.train(overfeat, args) if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.validate(overfeat, args)
x = builder.activate(x) x = builder.separable_conv2d( x, 728, 3, 1, 'SAME') x = builder.separable_conv2d_linear(x, 1024, 3, 1, 'SAME') x = builder.max_pooling2d( x, 3, 2, 'SAME') return x x = inputs x = builder.conv2d(x, 32, 3, 2, 'VALID') x = builder.conv2d(x, 64, 3, 1, 'VALID') x = builder.residual2d(x, make_xception_entry(128, False), 128) x = builder.residual2d(x, make_xception_entry(256), 256) x = builder.residual2d(x, make_xception_entry(728), 728) for _ in range(8): x = builder.residual2d(x, xception_middle) x = builder.residual2d(x, xception_exit, 1024) x = builder.separable_conv2d(x, 1536, 3, 1, 'SAME') x = builder.separable_conv2d(x, 2048, 3, 1, 'SAME') x = builder.spatial_average2d(x) # Note: Optional FC layer not included x = builder.dropout(x, 0.5) return x if args['predict']: if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.predict(xception, args) else: nvutils.train(xception, args) if args['log_dir'] is not None and args['data_dir'] is not None: nvutils.validate(xception, args)