-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
640 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) |
Oops, something went wrong.