2017-01-26 3 views
3

Ich möchte Tensor Achse von Bildstapel von (Batch_size, Zeile, Spalte, ch) zu (Batch_size, ch, Zeile, col) tauschen.tauschen Tensor-Achse in Keras

in numpy, kann dies mit

X_batch = np.moveaxis(X_batch, 3, 1) 

erfolgen Wie würde ich in Keras das tun?

Antwort

8

Sie können K.permute_dimensions() verwenden, die genau np.transpose() ähnlich ist.

Beispiel:

import numpy as np 
from keras import backend as K 

A = np.random.random((1000,32,64,3)) 
# B = np.moveaxis(A, 3, 1) 
C = np.transpose(A, (0,3,1,2)) 

print A.shape 
print C.shape 

A_t = K.variable(A) 
C_t = K.permute_dimensions(A_t, (0,3,1,2)) 

print K.eval(A_t).shape 
print K.eval(C_t).shape