Python 制作Keras';无';批量大小不变,使用tf.scatter\n

Python 制作Keras';无';批量大小不变,使用tf.scatter\n,python,tensorflow,keras,deep-learning,Python,Tensorflow,Keras,Deep Learning,我需要向LSTM解码器输入一个池模块,我正在使用一个自定义层构建它,其中编码器LSTM状态和Keras输入层作为输入。在此自定义层中,我需要将更新分散到索引: updates: <tf.Tensor --- shape=(None, 225, 5, 32) dtype=float32> indices: <tf.Tensor --- shape=(None, 225) dtype=int32> 但问题是,这样做会因为形状不类型而产生错误,我不想在其中声明batch\u

我需要向LSTM解码器输入一个池模块,我正在使用一个自定义层构建它,其中编码器LSTM状态和Keras输入层作为输入。在此自定义层中,我需要将更新分散到索引:

updates: <tf.Tensor --- shape=(None, 225, 5, 32) dtype=float32>
indices: <tf.Tensor --- shape=(None, 225) dtype=int32>
但问题是,这样做会因为形状不类型而产生错误,我不想在其中声明
batch\u size
,因为它是一个Keras层,只有在学习过程中才是确定的。在此状态下,代码的工作版本如下:

tf.scatter_nd(tf.expand_dims(indices, 2), updates, shape=[960, 5, 32])
        >>> <tf.Tensor 'ScatterNd_4:0' shape=(960, 5, 32) dtype=float32>
tf.scatter\u nd(tf.expand\u dims(索引,2),更新,shape=[960,5,32])
>>> 
这忽略了输出中的批处理大小。
是否有其他方法来构造所需的输出张量,而不是
tf.scatter\u nd
或使其正常工作的方法?

我有一个类似的问题,如果您找到了解决方案,请与我们分享。。非常感谢。
tf.scatter_nd(tf.expand_dims(indices, 2), updates, shape=[960, 5, 32])
        >>> <tf.Tensor 'ScatterNd_4:0' shape=(960, 5, 32) dtype=float32>