我在 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/