-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from YeongHyeon/0.2.6
0.2.6
- Loading branch information
Showing
4 changed files
with
112 additions
and
111 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
setup( | ||
name = 'whiteboxlayer', | ||
version = '0.2.5', | ||
version = '0.2.6', | ||
description = 'TensorFlow based custom layers', | ||
author = 'YeongHyeon Park', | ||
author_email = '[email protected]', | ||
|
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,111 @@ | ||
import tensorflow as tf | ||
|
||
def conv1d(layer, x, stride, \ | ||
filter_size=[3, 16, 32], dilations=[1, 1, 1], \ | ||
padding='SAME', batch_norm=False, trainable=True, activation=None, usebias=True, name='', verbose=True): | ||
|
||
w = layer.get_variable(shape=filter_size, \ | ||
trainable=trainable, name='%s_w' %(name)) | ||
if(usebias): b = layer.get_variable(shape=[filter_size[-1]], \ | ||
trainable=trainable, name='%s_b' %(name)) | ||
|
||
wx = tf.nn.conv1d( | ||
input=x, | ||
filters=w, | ||
stride=stride, | ||
padding=padding, | ||
data_format='NWC', | ||
dilations=None, | ||
name='%s_cv' %(name) | ||
) | ||
|
||
if(usebias): y = tf.math.add(wx, b, name='%s_add' %(name)) | ||
else: y = wx | ||
if(verbose): print("Conv (%s)" %(name), x.shape, "->", y.shape) | ||
|
||
if(batch_norm): y = layer.batch_normalization(x=y, \ | ||
trainable=trainable, name='%s_bn' %(name), verbose=verbose) | ||
return layer.activation(x=y, activation=activation, name=name) | ||
|
||
def convt1d(layer, x, stride, output_shape, \ | ||
filter_size=[3, 16, 32], dilations=[1, 1, 1], \ | ||
padding='SAME', batch_norm=False, trainable=True, activation=None, usebias=True, name='', verbose=True): | ||
|
||
w = layer.get_variable(shape=filter_size, \ | ||
trainable=trainable, name='%s_w' %(name)) | ||
if(usebias): b = layer.get_variable(shape=[filter_size[-2]], \ | ||
trainable=trainable, name='%s_b' %(name)) | ||
|
||
wx = tf.nn.conv1d_transpose( | ||
input=x, | ||
filters=w, | ||
output_shape=output_shape, | ||
strides=stride, | ||
padding=padding, | ||
data_format='NWC', | ||
dilations=dilations, | ||
name='%s_cvt' %(name) | ||
) | ||
|
||
if(usebias): y = tf.math.add(wx, b, name='%s_add' %(name)) | ||
else: y = wx | ||
if(verbose): print("ConvT (%s)" %(name), x.shape, "->", y.shape) | ||
|
||
if(batch_norm): y = layer.batch_normalization(x=y, \ | ||
trainable=trainable, name='%s_bn' %(name), verbose=verbose) | ||
return layer.activation(x=y, activation=activation, name=name) | ||
|
||
def conv2d(layer, x, stride, \ | ||
filter_size=[3, 3, 16, 32], dilations=[1, 1, 1, 1], \ | ||
padding='SAME', batch_norm=False, trainable=True, activation=None, usebias=True, name='', verbose=True): | ||
|
||
w = layer.get_variable(shape=filter_size, \ | ||
trainable=trainable, name='%s_w' %(name)) | ||
if(usebias): b = layer.get_variable(shape=[filter_size[-1]], \ | ||
trainable=trainable, name='%s_b' %(name)) | ||
|
||
wx = tf.nn.conv2d( | ||
input=x, | ||
filters=w, | ||
strides=[1, stride, stride, 1], | ||
padding=padding, | ||
data_format='NHWC', | ||
dilations=dilations, | ||
name='%s_cv' %(name) | ||
) | ||
|
||
if(usebias): y = tf.math.add(wx, b, name='%s_add' %(name)) | ||
else: y = wx | ||
if(verbose): print("Conv (%s)" %(name), x.shape, "->", y.shape) | ||
|
||
if(batch_norm): y = layer.batch_normalization(x=y, \ | ||
trainable=trainable, name='%s_bn' %(name), verbose=verbose) | ||
return layer.activation(x=y, activation=activation, name=name) | ||
|
||
def convt2d(layer, x, stride, output_shape, \ | ||
filter_size=[3, 3, 16, 32], dilations=[1, 1, 1, 1], \ | ||
padding='SAME', batch_norm=False, trainable=True, activation=None, usebias=True, name='', verbose=True): | ||
|
||
w = layer.get_variable(shape=filter_size, \ | ||
trainable=trainable, name='%s_w' %(name)) | ||
if(usebias): b = layer.get_variable(shape=[filter_size[-2]], \ | ||
trainable=trainable, name='%s_b' %(name)) | ||
|
||
wx = tf.nn.conv2d_transpose( | ||
input=x, | ||
filters=w, | ||
output_shape=output_shape, | ||
strides=[1, stride, stride, 1], | ||
padding=padding, | ||
data_format='NHWC', | ||
dilations=dilations, | ||
name='%s_cvt' %(name) | ||
) | ||
|
||
if(usebias): y = tf.math.add(wx, b, name='%s_add' %(name)) | ||
else: y = wx | ||
if(verbose): print("ConvT (%s)" %(name), x.shape, "->", y.shape) | ||
|
||
if(batch_norm): y = layer.batch_normalization(x=y, \ | ||
trainable=trainable, name='%s_bn' %(name), verbose=verbose) | ||
return layer.activation(x=y, activation=activation, name=name) |
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