Tensorflow Keras中的Concat不规则阵列

Tensorflow Keras中的Concat不规则阵列,tensorflow,keras,keras-layer,tf.keras,ragged,Tensorflow,Keras,Keras Layer,Tf.keras,Ragged,我有几个破旧的传感器,我想连接;我正在使用Keras。Vanilla Tensorflow很乐意将它们连接起来,因此我尝试了以下代码: card_feature = layers.concatenate([ragged1, ragged2, ragged3]) 但它给出了一个错误: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "

我有几个破旧的传感器,我想连接;我正在使用Keras。Vanilla Tensorflow很乐意将它们连接起来,因此我尝试了以下代码:

card_feature = layers.concatenate([ragged1, ragged2, ragged3])
但它给出了一个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/timeroot/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 925, in __call__
    return self._functional_construction_call(inputs, args, kwargs,
  File "/home/timeroot/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1084, in _functional_construction_call
    base_layer_utils.create_keras_history(inputs)
  File "/home/timeroot/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 191, in create_keras_history
    _, created_layers = _create_keras_history_helper(tensors, set(), [])
  File "/home/timeroot/.local/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 222, in _create_keras_history_helper
    raise ValueError('Tensorflow ops that generate ragged or sparse tensor '
ValueError: Tensorflow ops that generate ragged or sparse tensor outputs are currently not supported by Keras automatic op wrapping. Please wrap these ops in a Lambda layer: 

```

      weights_mult = lambda x: tf.sparse.sparse_dense_matmul(x, weights)
      output = tf.keras.layers.Lambda(weights_mult)(input)
      
```

但它给出了完全相同的错误,尽管我已经包装好了。这是一个错误/有解决方法吗?

连接3个不规则张量的代码如下所示:

import tensorflow as tf

print(tf.__version__)

Ragged_Tensor1 = tf.ragged.constant([[3, 1, 4, 1], [], [5, 9, 2], [6], []])
Ragged_Tensor2 = tf.ragged.constant([[5, 3]])
Ragged_Tensor3 = tf.ragged.constant([[6,7,8], [9,10]])
print(tf.concat([Ragged_Tensor1, Ragged_Tensor2, Ragged_Tensor3], axis=0))
2.3.0
<tf.RaggedTensor [[3, 1, 4, 1], [], [5, 9, 2], [6], [], [5, 3], [6, 7, 8], [9, 10]]>
输出如下所示:

import tensorflow as tf

print(tf.__version__)

Ragged_Tensor1 = tf.ragged.constant([[3, 1, 4, 1], [], [5, 9, 2], [6], []])
Ragged_Tensor2 = tf.ragged.constant([[5, 3]])
Ragged_Tensor3 = tf.ragged.constant([[6,7,8], [9,10]])
print(tf.concat([Ragged_Tensor1, Ragged_Tensor2, Ragged_Tensor3], axis=0))
2.3.0
<tf.RaggedTensor [[3, 1, 4, 1], [], [5, 9, 2], [6], [], [5, 3], [6, 7, 8], [9, 10]]>
2.3.0

但看起来你在尝试连接不规则的张量运算。请共享您的完整代码,以便我们可以尝试帮助您。

连接
3个不规则张量的代码如下所示:

import tensorflow as tf

print(tf.__version__)

Ragged_Tensor1 = tf.ragged.constant([[3, 1, 4, 1], [], [5, 9, 2], [6], []])
Ragged_Tensor2 = tf.ragged.constant([[5, 3]])
Ragged_Tensor3 = tf.ragged.constant([[6,7,8], [9,10]])
print(tf.concat([Ragged_Tensor1, Ragged_Tensor2, Ragged_Tensor3], axis=0))
2.3.0
<tf.RaggedTensor [[3, 1, 4, 1], [], [5, 9, 2], [6], [], [5, 3], [6, 7, 8], [9, 10]]>
输出如下所示:

import tensorflow as tf

print(tf.__version__)

Ragged_Tensor1 = tf.ragged.constant([[3, 1, 4, 1], [], [5, 9, 2], [6], []])
Ragged_Tensor2 = tf.ragged.constant([[5, 3]])
Ragged_Tensor3 = tf.ragged.constant([[6,7,8], [9,10]])
print(tf.concat([Ragged_Tensor1, Ragged_Tensor2, Ragged_Tensor3], axis=0))
2.3.0
<tf.RaggedTensor [[3, 1, 4, 1], [], [5, 9, 2], [6], [], [5, 3], [6, 7, 8], [9, 10]]>
2.3.0
但看起来你在尝试连接不规则的张量运算。请分享您的完整代码,以便我们可以尝试帮助您