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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// @generated by tool/gen/ds/generate.py — edit tool/gen/ds/schema/packs.json instead.
use crate::core::IdxSplit;
use crate::core::pack::{FetchProgress, Pack, PackFile};
use oa::{Engine, Result};
use std::path::PathBuf;
pub(crate) const STL10_PACK: Pack = Pack {
name: "stl10",
version: "1.0.0",
license: "unspecified",
files: &[PackFile {
name: "stl10_binary.tar.gz",
size: 2_640_397_119,
shake256: "7cc3c2e49b06e72f77d77d4c788a9177f6ee6035e5a4689e0c04582269f90d9e",
urls: &["http://ai.stanford.edu/~acoates/stl10/stl10_binary.tar.gz"],
}],
};
/// Class names in canonical order; label index `i` names `CLASSES[i]`.
pub const CLASSES: [&str; 10] = [
"airplane", "bird", "car", "cat", "deer", "dog", "horse", "monkey", "ship", "truck",
];
/// Square image extent in pixels.
pub const IMAGE_SIDE: usize = 96;
/// Official STL-10 labeled split selection.
pub type Stl10Split = IdxSplit;
/// Load options for [`Stl10`][crate::image::stl10::Stl10].
#[derive(Clone, Debug)]
pub struct Stl10Config {
/// Which official split to materialize.
pub split: Stl10Split,
/// Cache root override. `None` resolves `OA_DATA_DIR`, then the platform
/// cache directory; see [`data_root`](crate::pack::data_root).
pub cache_dir: Option<PathBuf>,
/// Scale pixels into `[0, 1]`. `false` keeps raw `0..=255` values.
pub normalize: bool,
}
impl Default for Stl10Config {
fn default() -> Self {
Self {
split: Stl10Split::Train,
cache_dir: None,
normalize: true,
}
}
}
impl Stl10Config {
/// Construct the record with its default state.
#[inline]
#[must_use]
pub fn new() -> Self {
Self::default()
}
}
impl super::Stl10 {
/// Decode the selected split and upload it on this thread's
/// default engine.
///
/// # Errors
///
/// Returns an error when the default engine cannot be
/// initialized, plus the errors of
/// [`load_on`](Self::load_on).
#[inline]
pub fn load(config: &Stl10Config) -> Result<Self> {
Self::load_on(&Engine::current()?, config)
}
/// Decode the selected split and upload it on `engine`.
///
/// This is the [`load`](Self::load) contract evaluated on
/// `engine` instead of this thread's default engine.
///
/// # Errors
///
/// Returns the errors of
/// [`load_with_progress_on`](Self::load_with_progress_on).
#[inline]
pub fn load_on(engine: &Engine, config: &Stl10Config) -> Result<Self> {
Self::load_with_progress_on(engine, config, &mut |_| true)
}
/// [`load`](Self::load) with a fetch progress callback.
///
/// # Errors
///
/// Returns an error when the default engine cannot be
/// initialized, plus the errors of
/// [`load_with_progress_on`](Self::load_with_progress_on).
#[inline]
pub fn load_with_progress(
config: &Stl10Config,
progress: &mut impl FnMut(FetchProgress) -> bool,
) -> Result<Self> {
Self::load_with_progress_on(&Engine::current()?, config, progress)
}
}