keras 为什么在填充这些值时只得到零?

vuktfyat  于 2023-05-07  发布在  其他
关注(0)|答案(1)|浏览(160)

我试着做后垫但我得到的所有值都是零。如何从可用值中获取值。

raw_inputs = [
    [-6.7329314e-04, -3.2805078e-04,  9.8458688e-05],
    [-6.7329314e-04, -3.2805078e-04,  9.8458688e-05,-6.7329314e-04, -3.2805078e-04,  9.8458688e-05],
    [-6.7329314e-04, -3.2805078e-04,  9.8458688e-05,-6.7329314e-04, -3.2805078e-04,  9.8458688e-05,-6.7329314e-04, -3.2805078e-04,  9.8458688e-05],
]

# By default, this will pad using 0s; it is configurable via the
# "value" parameter.
# Note that you could "pre" padding (at the beginning) or
# "post" padding (at the end).
# We recommend using "post" padding when working with RNN layers
# (in order to be able to use the
# CuDNN implementation of the layers).
padded_inputs = tf.keras.preprocessing.sequence.pad_sequences(
    raw_inputs, padding="post"
)
print(padded_inputs)

请帮我这个。先谢谢你了

5jvtdoz2

5jvtdoz21#

默认情况下,pad_sequences返回dtype='int32'中的数据,这是因为您的数据被强制转换为零...指定dtype='float64'可以解决这个问题

padded_inputs = tf.keras.preprocessing.sequence.pad_sequences(
    raw_inputs, padding="post", dtype='float64')

相关问题