Skip to content

Commit ea0d834

Browse files
committed
release supixel conv 1d
1 parent d90ed50 commit ea0d834

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

docs/modules/layers.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ Layer list
284284
MaxPool3d
285285
MeanPool3d
286286

287+
SubpixelConv1d
287288
SubpixelConv2d
288289

289290
SpatialTransformer2dAffineLayer
@@ -498,6 +499,13 @@ APIs may better for you.
498499
.. autofunction:: MeanPool3d
499500

500501
Super-resolution layer
502+
------------------------
503+
504+
1D Supixel Convolutional
505+
^^^^^^^^^^^^^^^^^^^^^^^^^^
506+
.. autofunction:: SubpixelConv1d
507+
508+
2D Supixel Convolutional
501509
^^^^^^^^^^^^^^^^^^^^^^^^^^
502510
.. autofunction:: SubpixelConv2d
503511

tensorlayer/layers.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,49 @@ def _PS(X, r, n_out_channel):
23012301
return net_new
23022302

23032303

2304+
def SubpixelConv1d(net, scale=2, act=tf.identity, name='subpixel_conv1d'):
2305+
"""One-dimensional subpixel upsampling layer.
2306+
Calls a tensorflow function that directly implements this functionality.
2307+
We assume input has dim (batch, width, r)
23042308
2309+
Parameters
2310+
------------
2311+
net : TensorLayer layer.
2312+
scale : int, upscaling ratio, a wrong setting will lead to Dimension size error.
2313+
act : activation function.
2314+
name : string.
2315+
An optional name to attach to this layer.
2316+
2317+
Examples
2318+
----------
2319+
>>> t_signal = tf.placeholder('float32', [10, 100, 4], name='x')
2320+
>>> n = InputLayer(t_signal, name='in')
2321+
>>> n = SubpixelConv1d(n, scale=2, name='s')
2322+
>>> print(n.outputs.shape)
2323+
... (10, 200, 2)
2324+
2325+
References
2326+
-----------
2327+
- `Audio Super Resolution Implementation <https://github.com/kuleshov/audio-super-res/blob/master/src/models/layers/subpixel.py>`_.
2328+
"""
2329+
def _PS(I, r):
2330+
X = tf.transpose(I, [2,1,0]) # (r, w, b)
2331+
X = tf.batch_to_space_nd(X, [r], [[0,0]]) # (1, r*w, b)
2332+
X = tf.transpose(X, [2,1,0])
2333+
return X
2334+
2335+
print(" [TL] SubpixelConv1d %s: scale: %d act: %s" % (name, scale, act.__name__))
2336+
2337+
inputs = net.outputs
2338+
net_new = Layer(inputs, name=name)
2339+
with tf.name_scope(name):
2340+
net_new.outputs = act(_PS(inputs, r=scale))
2341+
2342+
net_new.all_layers = list(net.all_layers)
2343+
net_new.all_params = list(net.all_params)
2344+
net_new.all_drop = dict(net.all_drop)
2345+
net_new.all_layers.extend( [net_new.outputs] )
2346+
return net_new
23052347

23062348
## Spatial Transformer Nets
23072349
def transformer(U, theta, out_size, name='SpatialTransformer2dAffine', **kwargs):

0 commit comments

Comments
 (0)