Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

bad argument #1 to 'topk' #184

Open
bemoregt opened this issue Jul 4, 2017 · 3 comments
Open

bad argument #1 to 'topk' #184

bemoregt opened this issue Jul 4, 2017 · 3 comments

Comments

@bemoregt
Copy link

bemoregt commented Jul 4, 2017

Hi, @zpao @iassael @maraoz @achao @gfosco

I have met this error:

./train.lua:137: bad argument #1 to 'topk' (k not in range for dimension

What's wrong with me?

Thanks at any rate...

@nizhib
Copy link

nizhib commented Jul 11, 2017

You must be retraining for less then 5 classes, then this diff should work for you:

diff --git a/train.lua b/train.lua
index 9f43e0b..a21f1d2 100644
--- a/train.lua
+++ b/train.lua
@@ -134,7 +134,7 @@ function Trainer:computeScore(output, target, nCrops)
    -- Coputes the top1 and top5 error rate
    local batchSize = output:size(1)
 
-   local _ , predictions = output:float():topk(5, 2, true, true) -- descending
+   local _ , predictions = output:float():topk(math.min(5, output:size(2)), 2, true, true) -- descending
 
    -- Find which predictions match the target
    local correct = predictions:eq(

@bemoregt
Copy link
Author

bemoregt commented Jul 11, 2017 via email

@bemoregt
Copy link
Author

bemoregt commented Jul 12, 2017

I just using 2 classes.

Thanks at any rate.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants