def create_loss(): """Creates loss tensor for resnet model.""" images = tf.random_uniform((BATCH_SIZE, HEIGHT, WIDTH, DEPTH)) labels = tf.random_uniform((BATCH_SIZE, NUM_CLASSES)) # channels_last for CPU if USE_TINY: network = resnet_model.tiny_cifar10_resnet_v2_generator(RESNET_SIZE, NUM_CLASSES, data_format='channels_last') else: network = resnet_model.cifar10_resnet_v2_generator(RESNET_SIZE, NUM_CLASSES, data_format='channels_last') inputs = tf.reshape(images, [BATCH_SIZE, HEIGHT, WIDTH, DEPTH]) logits = network(inputs,True) cross_entropy = tf.losses.softmax_cross_entropy(logits=logits, onehot_labels=labels) l2_penalty = tf.add_n([tf.nn.l2_loss(v) for v in tf.trainable_variables()]) loss = cross_entropy + _WEIGHT_DECAY * l2_penalty return loss
def create_loss(): """Creates loss tensor for resnet model.""" images = tf.random_uniform((BATCH_SIZE, HEIGHT, WIDTH, DEPTH)) labels = tf.random_uniform((BATCH_SIZE, NUM_CLASSES)) # channels_last for CPU if USE_TINY: network = resnet_model.tiny_cifar10_resnet_v2_generator(RESNET_SIZE, NUM_CLASSES, data_format='channels_last') else: network = resnet_model.cifar10_resnet_v2_generator(RESNET_SIZE, NUM_CLASSES, data_format='channels_last') inputs = tf.reshape(images, [BATCH_SIZE, HEIGHT, WIDTH, DEPTH]) logits = network(inputs,True) cross_entropy = tf.losses.softmax_cross_entropy(logits=logits, onehot_labels=labels) l2_penalty = tf.add_n([tf.nn.l2_loss(v) for v in tf.trainable_variables()]) loss = cross_entropy + _WEIGHT_DECAY * l2_penalty return loss
def _create_cifar_resnet_loss(): """Creates loss tensor for resnet model.""" HEIGHT = 32 WIDTH = 32 DEPTH = 3 NUM_CLASSES = 10 BATCH_SIZE=1 _WEIGHT_DECAY = 2e-4 _INITIAL_LEARNING_RATE = 0.1 * BATCH_SIZE / 128 _MOMENTUM = 0.9 RESNET_SIZE=8 images = tf.random_uniform((BATCH_SIZE, HEIGHT, WIDTH, DEPTH)) labels = tf.random_uniform((BATCH_SIZE, NUM_CLASSES)) # channels_last for CPU network = resnet_model.tiny_cifar10_resnet_v2_generator(RESNET_SIZE, NUM_CLASSES, data_format='channels_last') inputs = tf.reshape(images, [BATCH_SIZE, HEIGHT, WIDTH, DEPTH]) logits = network(inputs,True) cross_entropy = tf.losses.softmax_cross_entropy(logits=logits, onehot_labels=labels) l2_penalty = tf.add_n([tf.nn.l2_loss(v) for v in tf.trainable_variables()]) loss = cross_entropy + _WEIGHT_DECAY * l2_penalty return loss