python - 混洗具有可变长度特征的张量批处理

标签 python tensorflow neural-network

我在 TensorFlow 中对数据进行采样时遇到问题。我有一堆样本,每个样本由 15 个不同长度的信号组成。我想从这个组中随机抽取样本。这样做的正确方法是什么?

当我尝试打乱这批张量时出现此错误:

ValueError: Dimension 0 in both shapes must be equal, but are 30 and 5 From merging shape 9 with other shapes. for 'shuffle_batch/packed' (op: 'Pack') with input shapes: [1185], [1185], [7500], [7500], [15000], [15000], [150], [150], [30], [30], [5], [5], [5], [5], [5].

错误发生在这里:

example, label = tf.train.shuffle_batch(
    [example, label],
    batch_size=batch_size,
    capacity=capacity,
    min_after_dequeue=min_after_dequeue,
    num_threads=num_preprocess_threads)

谢谢

最佳答案

tf.train.shuffle_batch() 采用可选的 enqueue_many 参数,我认为它可以满足您的需求。它允许您传递多个不同形状的张量,其中每个张量代表一批输入的一部分。

"如果 enqueue_many 为 True,假设张量表示一批示例,其中第一维由示例索引,并且张量的所有成员在第一维应具有相同的大小。如果输入张量具有形状 [ *, x, y, z],输出的形状为 [batch_size, x, y, z]。”

https://www.tensorflow.org/api_docs/python/tf/train/shuffle_batch

希望对您有所帮助!

关于python - 混洗具有可变长度特征的张量批处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43838357/

相关文章:

python - 删除django tastypie中的对象

python - 将多个列中的匹配对分组在一起 Python

python - 月亮/月相算法

python - 如何在 Linux 上使用没有 CUDA 的 TensorFlow?

python - Tensorflow2.4 NotFoundError : No algorithm worked! 与 Keras Conv1D 层

tensorflow - 使用预训练的 word2vec 初始化 Seq2seq 嵌入

lua - 如何使用 Torch 生成的模型进行预测?

python - 使用 tf.while_loop 对张量进行切片

neural-network - 输出体积的大小(卷积神经网络)

machine-learning - 识别机器学习数据以做出预测