Skip to content

Commit

Permalink
EfficinetNet initial
Browse files Browse the repository at this point in the history
  • Loading branch information
qubvel committed May 31, 2019
1 parent f945b35 commit 2a78829
Show file tree
Hide file tree
Showing 5 changed files with 640 additions and 0 deletions.
3 changes: 3 additions & 0 deletions efficientnet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .model import *
from .preprocessing import center_crop_and_resize
from .preprocessing import preprocess_input
43 changes: 43 additions & 0 deletions efficientnet/layers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import tensorflow as tf
import keras.backend as K
import keras.layers as KL
from keras.utils.generic_utils import get_custom_objects


class Swish(KL.Layer):

def call(self, inputs):
return tf.nn.swish(inputs)


class DropConnect(KL.Layer):

def __init__(self, drop_connect_rate=0.):
super().__init__()
self.drop_connect_rate = drop_connect_rate

def call(self, inputs, training=None):

def drop_connect():
keep_prob = 1.0 - self.drop_connect_rate

# Compute drop_connect tensor
batch_size = tf.shape(inputs)[0]
random_tensor = keep_prob
random_tensor += tf.random_uniform([batch_size, 1, 1, 1], dtype=inputs.dtype)
binary_tensor = tf.floor(random_tensor)
output = tf.div(inputs, keep_prob) * binary_tensor
return output


return K.in_train_phase(drop_connect, inputs, training=training)

def get_config(self):
config = super().get_config()
config['drop_connect_rate'] = drop_connect_rate


get_custom_objects().update({
'DropConnect': DropConnect,
'Swish': Swish,
})
Loading

0 comments on commit 2a78829

Please sign in to comment.