soumith / imagenet-multiGPU.torch

an imagenet example in torch.
BSD 2-Clause "Simplified" License
401 stars 158 forks source link

Multi Label Example #33

Closed lolz0r closed 7 years ago

lolz0r commented 8 years ago

Hi, This example framework has been super useful! It is possible to showcase a classifier where each photo has 1 or more appropriate labels (not per pixel, but rather overall)

It would be a departure from the 1 folder = 1 class approach - perhaps instead a text file could be supplied where its in the form of: imageFileName 1 2 3 4 5 ... where each number indicates an appropriate class.

Thanks again and keep up the good work!

lolz0r commented 7 years ago

For others, the solution: Use a nn.ConcatTable. This layer will create multiple outputs from a single input. The identical outputs are passed to each direct-child of this layer.

input 512 -> nn.ConcatTable ->
     child A: nn.Linear(512, 1)
     child B: nn.Linear(512, 5)
     child C: nn.Linear(512, 11)

Output will be { A(1), B(5), C(11) }

From here you can use a nn.ParallelCriterion which will correspond index wise with each table element.

You will have to write your own data loader to create appropriate labels as the default one within this project is single label only.