|
| 1 | +package vision |
| 2 | + |
| 3 | +import ( |
| 4 | + "path" |
| 5 | + "path/filepath" |
| 6 | + "strings" |
| 7 | + |
| 8 | + "github.com/rai-project/config" |
| 9 | + "github.com/rai-project/dldataset" |
| 10 | + "github.com/rai-project/image/types" |
| 11 | + context "golang.org/x/net/context" |
| 12 | +) |
| 13 | + |
| 14 | +var iLSVRC2012Validation *ILSVRC2012Validation |
| 15 | + |
| 16 | +type ILSVRC2012Validation struct { |
| 17 | + base |
| 18 | + baseURL string |
| 19 | + filePaths []string |
| 20 | + data map[string]ILSVRC2012ValidationLabeledImage |
| 21 | +} |
| 22 | + |
| 23 | +type ILSVRC2012ValidationLabeledImage struct { |
| 24 | + label string |
| 25 | + data *types.RGBImage |
| 26 | +} |
| 27 | + |
| 28 | +func (l ILSVRC2012ValidationLabeledImage) Label() string { |
| 29 | + return l.label |
| 30 | +} |
| 31 | + |
| 32 | +func (l ILSVRC2012ValidationLabeledImage) Data() (interface{}, error) { |
| 33 | + return l.data, nil |
| 34 | +} |
| 35 | + |
| 36 | +func (d *ILSVRC2012Validation) New(ctx context.Context) (dldataset.Dataset, error) { |
| 37 | + return iLSVRC2012Validation, nil |
| 38 | +} |
| 39 | + |
| 40 | +func (d *ILSVRC2012Validation) Name() string { |
| 41 | + return "ilsvrc2012_validation" |
| 42 | +} |
| 43 | + |
| 44 | +func (d *ILSVRC2012Validation) CanonicalName() string { |
| 45 | + category := strings.ToLower(d.Category()) |
| 46 | + name := strings.ToLower(d.Name()) |
| 47 | + key := path.Join(category, name) |
| 48 | + return key |
| 49 | +} |
| 50 | + |
| 51 | +func (d *ILSVRC2012Validation) Download(ctx context.Context) error { |
| 52 | + return nil |
| 53 | +} |
| 54 | + |
| 55 | +func (d *ILSVRC2012Validation) List(ctx context.Context) ([]string, error) { |
| 56 | + return d.filePaths, nil |
| 57 | +} |
| 58 | + |
| 59 | +func (d *ILSVRC2012Validation) Get(ctx context.Context, name string) (dldataset.LabeledData, error) { |
| 60 | + |
| 61 | +} |
| 62 | + |
| 63 | +func (d *ILSVRC2012Validation) Close() error { |
| 64 | + return nil |
| 65 | +} |
| 66 | + |
| 67 | +func init() { |
| 68 | + config.AfterInit(func() { |
| 69 | + const fileListPath = "/vision/support/ilsvrc2012_validation_file_list.txt" |
| 70 | + filePaths := strings.Split(_escFSMustString(false, fileListPath), "\n") |
| 71 | + iLSVRC2012Validation = &ILSVRC2012Validation{ |
| 72 | + base: base{ |
| 73 | + ctx: context.Background(), |
| 74 | + baseWorkingDir: filepath.Join(dldataset.Config.WorkingDirectory, "dldataset"), |
| 75 | + }, |
| 76 | + baseURL: "http://store.carml.org.s3.amazonaws.com/datasets/ilsvrc2012_validation/", |
| 77 | + filePaths: filePaths, |
| 78 | + } |
| 79 | + dldataset.Register(iLSVRC2012Validation) |
| 80 | + }) |
| 81 | +} |
0 commit comments