@@ -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
23072349def transformer (U , theta , out_size , name = 'SpatialTransformer2dAffine' , ** kwargs ):
0 commit comments