def __init__(self, batch=64, use_cpus=False): image_shape = [batch, 224, 224, 3] labels_shape = [batch] # Synthetic image should be within [0, 255]. images = tf.truncated_normal(image_shape, dtype=tf.float32, mean=127, stddev=60, name='synthetic_images') # Minor hack to avoid H2D copy when using synthetic data inputs = tf.contrib.framework.local_variable(images, name='gpu_cached_images') labels = tf.random_uniform(labels_shape, minval=0, maxval=999, dtype=tf.int32, name='synthetic_labels') model = model_config.get_model_config("resnet101", MockDataset()) logits, aux = model.build_network(inputs, data_format=use_cpus and "NHWC" or "NCHW") loss = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=labels) # Implement model interface self.loss = tf.reduce_mean(loss, name='xentropy-loss') self.optimizer = tf.train.GradientDescentOptimizer(1e-6)
def __init__(self, batch=64, use_cpus=False): image_shape = [batch, 224, 224, 3] labels_shape = [batch] # Synthetic image should be within [0, 255]. images = tf.truncated_normal( image_shape, dtype=tf.float32, mean=127, stddev=60, name='synthetic_images') # Minor hack to avoid H2D copy when using synthetic data inputs = tf.contrib.framework.local_variable( images, name='gpu_cached_images') labels = tf.random_uniform( labels_shape, minval=0, maxval=999, dtype=tf.int32, name='synthetic_labels') model = model_config.get_model_config("resnet101", MockDataset()) logits, aux = model.build_network( inputs, data_format=use_cpus and "NHWC" or "NCHW") loss = tf.nn.sparse_softmax_cross_entropy_with_logits( logits=logits, labels=labels) # Implement model interface self.loss = tf.reduce_mean(loss, name='xentropy-loss') self.optimizer = tf.train.GradientDescentOptimizer(1e-6) self.variables = ray_tf_utils.TensorFlowVariables( self.loss, tf.get_default_session())
def _get_logits(self, image): ctx = get_current_tower_context() with maybe_freeze_updates(ctx.index > 0): network = ConvNetBuilder( image, 3, True, use_tf_layers=True, data_format=self.data_format, dtype=tf.float16 if args.use_fp16 else tf.float32, variable_dtype=tf.float32) with custom_getter_scope(network.get_custom_getter()): dataset = lambda: 1 dataset.name = 'imagenet' model_conf = model_config.get_model_config('resnet50', dataset) model_conf.set_batch_size(args.batch) model_conf.add_inference(network) return network.affine(1000, activation='linear', stddev=0.001)