forked from facebookarchive/fb.resnet.torch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svhn255.lua
68 lines (59 loc) · 1.61 KB
/
svhn255.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
--
-- Copyright (c) 2016, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
--
-- CIFAR-10 dataset loader
--
local t = require 'datasets/transforms'
local M = {}
local SVHNDataset = torch.class('resnet.SVHNDataset', M)
function SVHNDataset:__init(imageInfo, opt, split)
assert(imageInfo[split], split)
self.imageInfo = imageInfo[split]
self.split = split
end
function SVHNDataset:get(i)
local image = self.imageInfo.data[i]:float()
local label = self.imageInfo.labels[i]
return {
input = image,
target = label,
}
end
function SVHNDataset:size()
return self.imageInfo.data:size(1)
end
-- Computed from entire CIFAR-10 training set
--local meanstd = {
-- mean = {125.3, 123.0, 113.9},
-- std = {63.0, 62.1, 66.7},
--}
function SVHNDataset:preprocess(isRandCrop)
if self.split == 'train' then
if isRandCrop then
return function (input)
return input
end
--return t.Compose{
--t.ColorNormalize(meanstd),
--t.HorizontalFlip(0.5),
--t.RandomCrop(32, 4),
--}
else
return function (input)
return input
end--t.HorizontalFlip(0)
end
elseif self.split == 'val' then
return function (input)
return input
end--t.HorizontalFlip(0)
else
error('invalid split: ' .. self.split)
end
end
return M.SVHNDataset