Mixing batches of variable length tensors

I am having trouble fetching my data in TensorFlow. I have a set of samples, each with 15 signals of different lengths. I want to randomly pull samples from this group. What is the correct way to do this?

I get this error when I try to shuffle the tensor package:

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

This is where the error occurs:

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)

      

thank

+3


source to share


1 answer


tf.train.shuffle_batch()

takes an optional argument enqueue_many

, which I think does what you want. It allows you to transfer multiple tensors of different shapes, where each tensor represents one part of a batch of inputs.

"If enqueue_many is True, tensors are assumed to be a batch of examples, where the first dimension is indexed in the example, and all tensor members must have the same size in the first dimension. If the input tensor is of the form [*, x, y, z], the output will be of the form [batch_size, x, y, z]. "



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

Hope it helps!

+1


source







All Articles