You can do this in numpy/python outside of Theano. That would be the
simplest way.

Otherwise, you would need to put your data in 2 shared variables and use
indexing with concatenation to create you batch inside the Theano graph.
Your Theano function will then take as input the index you want for each
group of classes. Something like:


shared_positive = theano.shared(your_positive_examples)
shared_negative = theano.shared(your_negative_examples)

idx_pos = theano.tensor.ivector()
idx_neg = theano.tensor.ivector()

mini_batch_pos = shared_positive[idx_pos]
mini_batch_neg = shared_positive[idx_neg]
mini_batch = theano.tensor.concatenate(mini_batch_pos, mini_batch_neg)

output = .... your theano graph that use mini_batch for computation.

thano.function([idx_pos, idx_neg], output)

Hope this help.

Fred

On Sat, May 13, 2017 at 9:54 AM 'Nikolaj Weh' via theano-users <
[email protected]> wrote:

> Hey guys,
>
> I have a CNN which I train using Lasagne. Now I have a different number of
> positive classes, let's say 5. And I have one negative class, let's call it
> background. Currently, my background-class has way more samples than my
> positive classes, i.e. there's 1000 negative samples with 100 positive
> samples per class. I want to use a batch size of 40 and evenly distribute
> positive samples (20 positive samples) and negative samples (20 negative
> samples), so my batch size is always 40 samples. For this I know that I
> need to train some positive samples multiple times while avoiding the same
> for negative samples.
> How do I achieve something like this with Theano?
> Thanks a lot in advance!
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "theano-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to