mlverse / torchvision

R interface to torchvision
https://torchvision.mlverse.org
Other
63 stars 15 forks source link

MNIST labels seem off by one #107

Closed ExplainableMachines closed 2 months ago

ExplainableMachines commented 7 months ago

I just stumbled upon an oddity with MNIST. The labels seem to be off by one: Annotated labels are 1..10 rather than 0..9 and indeed visualizing the images shows that all labels are off by one. I loaded mnist the usual way:

`library(torchvision)

ds <- mnist_dataset( '~/Documents/Projects/data/', download = T, transform = function(x) { x <- x$to(dtype = torch_float())/256 x[newaxis,..] } )`

cregouby commented 3 months ago

Hello @ExplainableMachines,

The targets are like factors, they are 1-indexed in R, but classes, their label, are correct on MNIST Dataset :

library(torchvision)

ds <- mnist_dataset(
  '~/R/dataset/MNIST',
  download = T
)
ds$classes
#>  [1] "0 - zero"  "1 - one"   "2 - two"   "3 - three" "4 - four"  "5 - five" 
#>  [7] "6 - six"   "7 - seven" "8 - eight" "9 - nine"
ds$targets
#>     [1]  6  1  5  2 10  3  2  4  2  5  4  6  4  7  2  8  3  9  7 10  5  1 10  2
#>    [25]  2  3  5  4  3  8  4  9  7 10  1  6  7  1  8  7  2  9  8 10  4 10  9  6
#>    [49] 10  4  4  1  8  5 10  9  1 10  5  2  5  5  7  1  5  6  7  2  1  1  2  8
#>    [73]  2  7  4  1  3  2  2  8 10  1  3  7  8  9  4 10  1  5  7  8  5  7  9  1
#>    [97]  8  9  4  2  6  8  2  8  2  2  7  4  1  3 10  4  2  2  1  5 10  3  1  1
#>   [121]  3  1  3  8  2  9  7  5  2  7  4  5  6 10  2  4  4  9  6  5  8  8  5  3
#>   [145]  9  6  9  7  8  4  5  7  2 10 10  7  1  4  8  3  9  3 10  5  5  7  5 10
...
#> [59881]  6  5  2  4  9  7  4 10 10  6 10  4  7  5  8  7  3  3  1 10  5  1  2  3
#> [59905]  4  5  6  7  8  9 10  1  2  3  4  5  9 10  1  2  3  4  5  6  7  8  9 10
#> [59929]  7  1  4  5  2  5  1  8  9  8  8 10  1  5 10  5  1  6  9  6 10  9  9  5
#> [59953]  1  8  2  4  6  4  2  7  6  4  9  8  4  2  7  9  6 10  3  3  1 10  3  5
#> [59977]  7  8  4  2  4  7  7  3  2  3  7  1  8  9 10  3 10  6  2  9  4  6  7  9

Created on 2024-09-01 with reprex v2.1.1

ExplainableMachines commented 2 months ago

Thank you for the clarification! That solves my issue.