facebookarchive / fb.resnet.torch

Torch implementation of ResNet from http://arxiv.org/abs/1512.03385 and training scripts
Other
2.29k stars 664 forks source link

bad argument #1 to 'topk' #184

Open bemoregt opened 7 years ago

bemoregt commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Many thanks !

나의 iPhone에서 보냄

      1. 오후 8:12 Evgeny Nizhibitsky notifications@github.com 작성:

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( — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

bemoregt commented 7 years ago

I just using 2 classes.

Thanks at any rate.