我正在keras中实现一个操作,这样它就可以同时处理theano和tensorflow后端.假设操作的输入是:
array([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11]], dtype=int64)
Run Code Online (Sandbox Code Playgroud)
那么它的输出应该是:
array([[ 0, 1, 2, 3, 4, 5],
[ 3, 4, 5, 0, 1, 2],
[ 6, 7, 8, 9, 10, 11],
[ 9, 10, 11, 6, 7, 8]], dtype=int64)
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
from keras import backend as K
def pairreshape(x,target_dim,input_shape):
x1, x2 = x[0::2,], x[1::2,]
x1_concate = K.concatenate((x1,x2), axis=target_dim)
x2_concate = K.concatenate((x2,x1), axis=target_dim)
if K.image_dim_ordering() == 'th':
import theano.tensor as T
x_new = …Run Code Online (Sandbox Code Playgroud)