Использование SVD в пользовательском слое в Keras / tenorflow - PullRequest
0 голосов
/ 09 февраля 2020

Я пытаюсь создать пользовательский слой в керасе, где svd выполняется на промежуточном этапе внутри слоя. Однако я получаю следующую ошибку -

Файл "/home/sandeep/anaconda3/envs/kerasenv/lib/python3.7/site-packages/tensorflow_core/python/ops/linalg_grad .py ", строка 404, в _SvdGrad" Градиент SVD не реализован для abs (m - n)> 1 "

NotImplementedError: Градиент SVD не реализован для abs (m - n)> 1, когда full_matrices является True

Фрагмент моего пользовательского слоя -

class ResLayer(Layer):

def __init__(self, output_dim, **kwargs):
    self.output_dim = output_dim
    super(ResLayer, self).__init__(**kwargs)

def build(self, input_shape):
    print(len(input_shape))
    # Create a trainable weight variable for this layer.
    assert len(input_shape) >= 3
    input_dim = input_shape[1:]
    print(input_shape)

    super(ResLayer, self).build(input_shape)  # Be sure to call this at the end

def call(self, x):
     print(x.shape)
     x_shape=K.int_shape(x)
     # operations on mode1
     mode1_mat = reshape2(x,mode=1)
     mode1_mat.set_shape([x_shape[0],x_shape[1],x_shape[2]])
     factor_u1 = Lambda(lambda x: my_svd(x))(mode1_mat)
     #factor_u1 =  my_svd(mode1_mat)
     reduced_cols = self.output_dim[0]
     reduced_u1 =  reduce_factor(factor_u1,reduced_cols)

        # operations on mode2
     mode2_mat = reshape2(x,mode=2)
     mode2_mat.set_shape([x_shape[0],x_shape[2],x_shape[1]])
     factor_u2 = Lambda(lambda x: my_svd(x))(mode2_mat)
     #factor_u2 =  my_svd(mode2_mat)
     reduced_cols = self.output_dim[1]
     reduced_u2 = reduce_factor(factor_u2,reduced_cols)

        # projecting the reduced factor matrices on input tensor to get core
     first_projection = ttm_new(x,reduced_u1,n=1)
     reduced_core = ttm_new(first_projection,reduced_u2,n=2)



     return reduced_core
     #return feed_forward_product
   # return K.dot(x, self.kernel)

def compute_output_shape(self, input_shape):

    return (input_shape[0],self.output_dim[0],self.output_dim[1])

my_svd использует внутри него tf.linalg.svd. Помогите пожалуйста как побороть эту ошибку

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...