import tensorflow.contrib.eager as tfe
from tensorflow.examples.tutorials.mnist import input_data
+layers = tf.keras.layers
FLAGS = None
else:
assert data_format == 'channels_last'
self._input_shape = [-1, 28, 28, 1]
- self.conv1 = tf.layers.Conv2D(
+ self.conv1 = layers.Conv2D(
64, 5, padding='SAME', data_format=data_format, activation=tf.tanh)
- self.pool1 = tf.layers.AveragePooling2D(2, 2, data_format=data_format)
- self.conv2 = tf.layers.Conv2D(
+ self.pool1 = layers.AveragePooling2D(2, 2, data_format=data_format)
+ self.conv2 = layers.Conv2D(
128, 5, data_format=data_format, activation=tf.tanh)
- self.pool2 = tf.layers.AveragePooling2D(2, 2, data_format=data_format)
- self.flatten = tf.layers.Flatten()
- self.fc1 = tf.layers.Dense(1024, activation=tf.tanh)
- self.fc2 = tf.layers.Dense(1, activation=None)
+ self.pool2 = layers.AveragePooling2D(2, 2, data_format=data_format)
+ self.flatten = layers.Flatten()
+ self.fc1 = layers.Dense(1024, activation=tf.tanh)
+ self.fc2 = layers.Dense(1, activation=None)
def call(self, inputs):
"""Return two logits per image estimating input authenticity.
else:
assert data_format == 'channels_last'
self._pre_conv_shape = [-1, 6, 6, 128]
- self.fc1 = tf.layers.Dense(6 * 6 * 128, activation=tf.tanh)
+ self.fc1 = layers.Dense(6 * 6 * 128, activation=tf.tanh)
# In call(), we reshape the output of fc1 to _pre_conv_shape
# Deconvolution layer. Resulting image shape: (batch, 14, 14, 64)
- self.conv1 = tf.layers.Conv2DTranspose(
+ self.conv1 = layers.Conv2DTranspose(
64, 4, strides=2, activation=None, data_format=data_format)
# Deconvolution layer. Resulting image shape: (batch, 28, 28, 1)
- self.conv2 = tf.layers.Conv2DTranspose(
+ self.conv2 = layers.Conv2DTranspose(
1, 2, strides=2, activation=tf.nn.sigmoid, data_format=data_format)
def call(self, inputs):
import tensorflow as tf
+layers = tf.keras.layers
+
class _IdentityBlock(tf.keras.Model):
"""_IdentityBlock is the block that has no conv layer at shortcut.
bn_name_base = 'bn' + str(stage) + block + '_branch'
bn_axis = 1 if data_format == 'channels_first' else 3
- self.conv2a = tf.layers.Conv2D(
+ self.conv2a = layers.Conv2D(
filters1, (1, 1), name=conv_name_base + '2a', data_format=data_format)
- self.bn2a = tf.layers.BatchNormalization(
+ self.bn2a = layers.BatchNormalization(
axis=bn_axis, name=bn_name_base + '2a')
- self.conv2b = tf.layers.Conv2D(
+ self.conv2b = layers.Conv2D(
filters2,
kernel_size,
padding='same',
data_format=data_format,
name=conv_name_base + '2b')
- self.bn2b = tf.layers.BatchNormalization(
+ self.bn2b = layers.BatchNormalization(
axis=bn_axis, name=bn_name_base + '2b')
- self.conv2c = tf.layers.Conv2D(
+ self.conv2c = layers.Conv2D(
filters3, (1, 1), name=conv_name_base + '2c', data_format=data_format)
- self.bn2c = tf.layers.BatchNormalization(
+ self.bn2c = layers.BatchNormalization(
axis=bn_axis, name=bn_name_base + '2c')
def call(self, input_tensor, training=False):
bn_name_base = 'bn' + str(stage) + block + '_branch'
bn_axis = 1 if data_format == 'channels_first' else 3
- self.conv2a = tf.layers.Conv2D(
+ self.conv2a = layers.Conv2D(
filters1, (1, 1),
strides=strides,
name=conv_name_base + '2a',
data_format=data_format)
- self.bn2a = tf.layers.BatchNormalization(
+ self.bn2a = layers.BatchNormalization(
axis=bn_axis, name=bn_name_base + '2a')
- self.conv2b = tf.layers.Conv2D(
+ self.conv2b = layers.Conv2D(
filters2,
kernel_size,
padding='same',
name=conv_name_base + '2b',
data_format=data_format)
- self.bn2b = tf.layers.BatchNormalization(
+ self.bn2b = layers.BatchNormalization(
axis=bn_axis, name=bn_name_base + '2b')
- self.conv2c = tf.layers.Conv2D(
+ self.conv2c = layers.Conv2D(
filters3, (1, 1), name=conv_name_base + '2c', data_format=data_format)
- self.bn2c = tf.layers.BatchNormalization(
+ self.bn2c = layers.BatchNormalization(
axis=bn_axis, name=bn_name_base + '2c')
- self.conv_shortcut = tf.layers.Conv2D(
+ self.conv_shortcut = layers.Conv2D(
filters3, (1, 1),
strides=strides,
name=conv_name_base + '1',
data_format=data_format)
- self.bn_shortcut = tf.layers.BatchNormalization(
+ self.bn_shortcut = layers.BatchNormalization(
axis=bn_axis, name=bn_name_base + '1')
def call(self, input_tensor, training=False):
return _IdentityBlock(
3, filters, stage=stage, block=block, data_format=data_format)
- self.conv1 = tf.layers.Conv2D(
+ self.conv1 = layers.Conv2D(
64, (7, 7),
strides=(2, 2),
data_format=data_format,
padding='same',
name='conv1')
bn_axis = 1 if data_format == 'channels_first' else 3
- self.bn_conv1 = tf.layers.BatchNormalization(axis=bn_axis, name='bn_conv1')
- self.max_pool = tf.layers.MaxPooling2D(
+ self.bn_conv1 = layers.BatchNormalization(axis=bn_axis, name='bn_conv1')
+ self.max_pool = layers.MaxPooling2D(
(3, 3), strides=(2, 2), data_format=data_format)
self.l2a = conv_block([64, 64, 256], stage=2, block='a', strides=(1, 1))
self.l5b = id_block([512, 512, 2048], stage=5, block='b')
self.l5c = id_block([512, 512, 2048], stage=5, block='c')
- self.avg_pool = tf.layers.AveragePooling2D(
+ self.avg_pool = layers.AveragePooling2D(
(7, 7), strides=(7, 7), data_format=data_format)
if self.include_top:
- self.fc1000 = tf.layers.Dense(classes, name='fc1000')
+ self.flatten = layers.Flatten()
+ self.fc1000 = layers.Dense(classes, name='fc1000')
else:
reduction_indices = [1, 2] if data_format == 'channels_last' else [2, 3]
reduction_indices = tf.constant(reduction_indices)
x = self.avg_pool(x)
if self.include_top:
- return self.fc1000(tf.layers.flatten(x))
+ return self.fc1000(self.flatten(x))
elif self.global_pooling:
return self.global_pooling(x)
else:
from tensorflow.contrib.cudnn_rnn.python.layers import cudnn_rnn
from tensorflow.contrib.eager.python import tfe
+layers = tf.keras.layers
+
class RNN(tf.keras.Model):
"""A static RNN.
def _add_cells(self, cells):
# "Magic" required for keras.Model classes to track all the variables in
- # a list of tf.layers.Layer objects.
+ # a list of Layer objects.
# TODO(ashankar): Figure out API so user code doesn't have to do this.
for i, c in enumerate(cells):
setattr(self, "cell-%d" % i, c)
return cells
-class Embedding(tf.layers.Layer):
+class Embedding(layers.Layer):
"""An Embedding layer."""
def __init__(self, vocab_size, embedding_dim, **kwargs):
else:
self.rnn = RNN(hidden_dim, num_layers, self.keep_ratio)
- self.linear = tf.layers.Dense(
+ self.linear = layers.Dense(
vocab_size, kernel_initializer=tf.random_uniform_initializer(-0.1, 0.1))
self._output_shape = [-1, embedding_dim]