Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to choose which blocks have SE units #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tf/tfprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def __init__(self, cfg):
loss_scale = self.cfg['training'].get('loss_scale', 128)
self.virtual_batch_size = self.cfg['model'].get(
'virtual_batch_size', None)
self.SE_blocks = self.cfg['model'].get('se_blocks', None)

if precision == 'single':
self.model_dtype = tf.float32
Expand Down Expand Up @@ -1036,7 +1037,9 @@ def batch_norm(self, input, name, scale=False):
virtual_batch_size=self.virtual_batch_size,
name=name)(input)

def squeeze_excitation(self, inputs, channels, name):
def squeeze_excitation(self, inputs, channels, block_num, name):
if self.SE_blocks is not None and block_num not in self.SE_blocks:
return inputs
assert channels % self.SE_ratio == 0

pooled = tf.keras.layers.GlobalAveragePooling2D(
Expand Down Expand Up @@ -1069,7 +1072,7 @@ def conv_block(self,
return tf.keras.layers.Activation('relu')(self.batch_norm(
conv, name=name + '/bn', scale=bn_scale))

def residual_block(self, inputs, channels, name):
def residual_block(self, inputs, channels, block_num, name):
conv1 = tf.keras.layers.Conv2D(channels,
3,
use_bias=False,
Expand All @@ -1094,6 +1097,7 @@ def residual_block(self, inputs, channels, name):
name + '/2/bn',
scale=True),
channels,
block_num,
name=name + '/se')
return tf.keras.layers.Activation('relu')(tf.keras.layers.add(
[inputs, out2]))
Expand All @@ -1107,6 +1111,7 @@ def construct_net(self, inputs):
for i in range(self.RESIDUAL_BLOCKS):
flow = self.residual_block(flow,
self.RESIDUAL_FILTERS,
i + 1,
name='residual_{}'.format(i + 1))

# Policy head
Expand Down