import tensorflow as tf
class RNet(tf.keras.Model): def __init__(self): super().__init__() self.conv1 = tf.keras.layers.Conv2D(28, 3, 1, name='conv1') self.prelu1 = tf.keras.layers.PReLU(shared_axes=[1,2], name="prelu1")
self.conv2 = tf.keras.layers.Conv2D(48, 3, 1, name='conv2') self.prelu2 = tf.keras.layers.PReLU(shared_axes=[1,2], name="prelu2")
self.conv3 = tf.keras.layers.Conv2D(64, 2, 1, name='conv3') self.prelu3 = tf.keras.layers.PReLU(shared_axes=[1,2], name="prelu3")
self.dense4 = tf.keras.layers.Dense(128, name='conv4') self.prelu4 = tf.keras.layers.PReLU(shared_axes=None, name="prelu4")
self.dense5_1 = tf.keras.layers.Dense(2, name="conv5-1") self.dense5_2 = tf.keras.layers.Dense(4, name="conv5-2")
self.flatten = tf.keras.layers.Flatten()
def call(self, x, training=False): out = self.prelu1(self.conv1(x)) out = tf.nn.max_pool2d(out, 3, 2, padding="SAME") out = self.prelu2(self.conv2(out)) out = tf.nn.max_pool2d(out, 3, 2, padding="VALID") out = self.prelu3(self.conv3(out)) out = self.flatten(out) out = self.prelu4(self.dense4(out)) score = tf.nn.softmax(self.dense5_1(out), -1) boxes = self.dense5_2(out) return boxes, score
|