|
| 1 | +""" |
| 2 | + classnames() -> Vector{Int} |
| 3 | +
|
| 4 | +Return the 10 digits for the SVHN classes as a vector of integers. |
| 5 | +""" |
| 6 | +classnames() = CLASSES |
| 7 | + |
| 8 | +""" |
| 9 | + traindata([T = N0f8], [indices]; [dir]) -> images, labels |
| 10 | +
|
| 11 | +Returns the SVHN **trainset** corresponding to the given |
| 12 | +`indices` as a two-element tuple. If `indices` is omitted the |
| 13 | +full trainset is returned. The first element of the return values |
| 14 | +will be the images as a multi-dimensional array, and the second |
| 15 | +element the corresponding labels as integers. |
| 16 | +
|
| 17 | +The image(s) is/are returned in the native vertical-major memory |
| 18 | +layout as a single numeric array of eltype `T`. If `T <: |
| 19 | +Integer`, then all values will be within `0` and `255`, otherwise |
| 20 | +the values are scaled to be between `0` and `1`. You can use the |
| 21 | +utility function [`convert2image`](@ref) to convert an SVHN array |
| 22 | +into a Julia image with the appropriate `RGB` eltype. The integer |
| 23 | +values of the labels correspond 1-to-1 the digit that they |
| 24 | +represent with the exception of 0 which is encoded as `10`. |
| 25 | +
|
| 26 | +Note that because of the nature of how the dataset is stored on |
| 27 | +disk, `SVHN2.traindata` will always load the full trainset, |
| 28 | +regardless of which observations are requested. In the case |
| 29 | +`indices` are provided by the user, it will simply result in a |
| 30 | +sub-setting. This option is just provided for convenience. |
| 31 | +
|
| 32 | +```julia |
| 33 | +train_x, train_y = SVHN2.traindata() # full dataset |
| 34 | +train_x, train_y = SVHN2.traindata(2) # only second observation |
| 35 | +train_x, train_y = SVHN2.traindata(dir="./SVHN") # custom folder |
| 36 | +``` |
| 37 | +
|
| 38 | +$(download_docstring("SVHN", DEPNAME)) |
| 39 | +""" |
| 40 | +function traindata(args...; dir = nothing) |
| 41 | + traindata(N0f8, args...; dir = dir) |
| 42 | +end |
| 43 | + |
| 44 | +function traindata(::Type{T}; dir = nothing) where T |
| 45 | + path = datafile(DEPNAME, TRAINDATA, dir) |
| 46 | + vars = matread(path) |
| 47 | + images, labels = vars["X"], vars["y"] |
| 48 | + bytes_to_type(T, images), Vector{Int}(vec(labels)) |
| 49 | +end |
| 50 | + |
| 51 | +function traindata(::Type{T}, indices; dir = nothing) where T |
| 52 | + images, labels = traindata(T, dir = dir) |
| 53 | + images[:,:,:,indices], labels[indices] |
| 54 | +end |
| 55 | + |
| 56 | +""" |
| 57 | + testdata([T = N0f8], [indices]; [dir]) -> images, labels |
| 58 | +
|
| 59 | +Returns the SVHN **testset** corresponding to the given |
| 60 | +`indices` as a two-element tuple. If `indices` is omitted the |
| 61 | +full testset is returned. The first element of the return |
| 62 | +values will be the images as a multi-dimensional array, and the |
| 63 | +second element the corresponding labels as integers. |
| 64 | +
|
| 65 | +The image(s) is/are returned in the native vertical-major memory |
| 66 | +layout as a single numeric array of eltype `T`. If `T <: |
| 67 | +Integer`, then all values will be within `0` and `255`, otherwise |
| 68 | +the values are scaled to be between `0` and `1`. You can use the |
| 69 | +utility function [`convert2image`](@ref) to convert an SVHN array |
| 70 | +into a Julia image with the appropriate `RGB` eltype. The integer |
| 71 | +values of the labels correspond 1-to-1 the digit that they |
| 72 | +represent with the exception of 0 which is encoded as `10`. |
| 73 | +
|
| 74 | +Note that because of the nature of how the dataset is stored on |
| 75 | +disk, `SVHN2.testdata` will always load the full testset, |
| 76 | +regardless of which observations are requested. In the case |
| 77 | +`indices` are provided by the user, it will simply result in a |
| 78 | +sub-setting. This option is just provided for convenience. |
| 79 | +
|
| 80 | +```julia |
| 81 | +test_x, test_y = SVHN2.testdata() # full dataset |
| 82 | +test_x, test_y = SVHN2.testdata(2) # only second observation |
| 83 | +test_x, test_y = SVHN2.testdata(dir="./SVHN") # custom folder |
| 84 | +``` |
| 85 | +
|
| 86 | +$(download_docstring("SVHN", DEPNAME)) |
| 87 | +""" |
| 88 | +function testdata(args...; dir = nothing) |
| 89 | + testdata(N0f8, args...; dir = dir) |
| 90 | +end |
| 91 | + |
| 92 | +function testdata(::Type{T}; dir = nothing) where T |
| 93 | + path = datafile(DEPNAME, TESTDATA, dir) |
| 94 | + vars = matread(path) |
| 95 | + images, labels = vars["X"], vars["y"] |
| 96 | + bytes_to_type(T, images), Vector{Int}(vec(labels)) |
| 97 | +end |
| 98 | + |
| 99 | +function testdata(::Type{T}, indices; dir = nothing) where T |
| 100 | + images, labels = testdata(T, dir = dir) |
| 101 | + images[:,:,:,indices], labels[indices] |
| 102 | +end |
| 103 | + |
| 104 | +""" |
| 105 | + extradata([T = N0f8], [indices]; [dir]) -> images, labels |
| 106 | +
|
| 107 | +Returns the SVHN **extra trainset** corresponding to the given |
| 108 | +`indices` as a two-element tuple. If `indices` is omitted the |
| 109 | +full dataset is returned. The first element of the return values |
| 110 | +will be the images as a multi-dimensional array, and the second |
| 111 | +element the corresponding labels as integers. |
| 112 | +
|
| 113 | +The image(s) is/are returned in the native vertical-major memory |
| 114 | +layout as a single numeric array of eltype `T`. If `T <: |
| 115 | +Integer`, then all values will be within `0` and `255`, otherwise |
| 116 | +the values are scaled to be between `0` and `1`. You can use the |
| 117 | +utility function [`convert2image`](@ref) to convert an SVHN array |
| 118 | +into a Julia image with the appropriate `RGB` eltype. The integer |
| 119 | +values of the labels correspond 1-to-1 the digit that they |
| 120 | +represent with the exception of 0 which is encoded as `10`. |
| 121 | +
|
| 122 | +Note that because of the nature of how the dataset is stored on |
| 123 | +disk, `SVHN2.extradata` will always load the full extra trainset, |
| 124 | +regardless of which observations are requested. In the case |
| 125 | +`indices` are provided by the user, it will simply result in a |
| 126 | +sub-setting. This option is just provided for convenience. |
| 127 | +
|
| 128 | +```julia |
| 129 | +extra_x, extra_y = SVHN2.extradata() # full dataset |
| 130 | +extra_x, extra_y = SVHN2.extradata(2) # only second observation |
| 131 | +extra_x, extra_y = SVHN2.extradata(dir="./SVHN") # custom folder |
| 132 | +``` |
| 133 | +
|
| 134 | +$(download_docstring("SVHN", DEPNAME)) |
| 135 | +""" |
| 136 | +function extradata(args...; dir = nothing) |
| 137 | + extradata(N0f8, args...; dir = dir) |
| 138 | +end |
| 139 | + |
| 140 | +function extradata(::Type{T}; dir = nothing) where T |
| 141 | + path = datafile(DEPNAME, EXTRADATA, dir) |
| 142 | + vars = matread(path) |
| 143 | + images, labels = vars["X"], vars["y"] |
| 144 | + bytes_to_type(T, images), Vector{Int}(vec(labels)) |
| 145 | +end |
| 146 | + |
| 147 | +function extradata(::Type{T}, indices; dir = nothing) where T |
| 148 | + images, labels = extradata(T, dir = dir) |
| 149 | + images[:,:,:,indices], labels[indices] |
| 150 | +end |
0 commit comments