use oa::{Error, Result};
use crate::IdxSplit;
use crate::decode::{DecodeConfig, Decoded};
use crate::pack::{FetchProgress, Pack};
pub(crate) fn manifest_of(name: &str) -> Result<&'static Pack> {
match name {
"mnist" => Ok(&crate::image::mnist::MNIST_PACK),
"fashion_mnist" => Ok(&crate::image::fashion_mnist::FASHION_MNIST_PACK),
"kmnist" => Ok(&crate::image::kmnist::KMNIST_PACK),
"cifar10" => Ok(&crate::image::cifar10::CIFAR10_PACK),
"mini_speech_commands" => Ok(&crate::audio::mini_speech_commands::MINI_SPEECH_COMMANDS_PACK),
"maestro" => Ok(&crate::audio::maestro::MAESTRO_PACK),
"tiny_shakespeare" => Ok(&crate::text::tiny_shakespeare::SHAKESPEARE_PACK),
"moving_mnist" => Ok(&crate::video::moving_mnist::MOVING_MNIST_PACK),
"cifar100" => Ok(&crate::image::cifar100::CIFAR100_PACK),
"emnist" => Ok(&crate::image::emnist::EMNIST_PACK),
"ag_news" => Ok(&crate::text::ag_news::AG_NEWS_PACK),
"imdb" => Ok(&crate::text::imdb::IMDB_PACK),
"yelp_polarity" => Ok(&crate::text::yelp_polarity::YELP_POLARITY_PACK),
"speech_commands" => Ok(&crate::audio::speech_commands::SPEECH_COMMANDS_PACK),
"groove" => Ok(&crate::audio::groove::GROOVE_PACK),
"iris" => Ok(&crate::tabular::iris::IRIS_PACK),
"titanic" => Ok(&crate::tabular::titanic::TITANIC_PACK),
"stl10" => Ok(&crate::image::stl10::STL10_PACK),
"movielens_100k" => Ok(&crate::tabular::movielens_100k::MOVIELENS_100K_PACK),
"movielens_1m" => Ok(&crate::tabular::movielens_1m::MOVIELENS_1M_PACK),
"ljspeech" => Ok(&crate::audio::ljspeech::LJSPEECH_PACK),
"crema_d" => Ok(&crate::audio::crema_d::CREMA_D_PACK),
"vctk" => Ok(&crate::audio::vctk::VCTK_PACK),
_ => Err(Error::invalid_argument(format!(
"unknown dataset pack '{name}'"
))),
}
}
pub(crate) fn load_of(
name: &str,
config: &DecodeConfig,
progress: &mut impl FnMut(FetchProgress) -> bool,
) -> Result<Decoded> {
match name {
"mnist" => crate::image::mnist::Mnist::decode_with_progress(
&crate::image::mnist::MnistConfig {
split: config.split,
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
progress,
),
"fashion_mnist" => crate::image::fashion_mnist::FashionMnist::decode(
&crate::image::fashion_mnist::FashionMnistConfig {
split: config.split,
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
),
"kmnist" => crate::image::kmnist::KMnist::decode_with_progress(
&crate::image::kmnist::KMnistConfig {
split: config.split,
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
progress,
),
"cifar10" => crate::image::cifar10::Cifar10::decode_with_progress(
&crate::image::cifar10::Cifar10Config {
split: config.split,
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
progress,
),
"mini_speech_commands" => {
crate::audio::mini_speech_commands::MiniSpeechCommands::decode_with_progress(
&crate::audio::mini_speech_commands::MiniSpeechCommandsConfig {
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
progress,
)
}
"maestro" => crate::audio::maestro::Maestro::decode_with_progress(
&crate::audio::maestro::MaestroConfig {
split: match config.split {
IdxSplit::Train => crate::audio::maestro::MaestroSplit::Train,
IdxSplit::Test => crate::audio::maestro::MaestroSplit::Test,
},
seq_len: crate::audio::maestro::DEFAULT_SEQ_LEN,
cache_dir: config.cache_dir.clone(),
},
progress,
),
"tiny_shakespeare" => crate::text::tiny_shakespeare::TinyShakespeare::decode(
&crate::text::tiny_shakespeare::TinyShakespeareConfig {
seq_len: 1,
cache_dir: config.cache_dir.clone(),
},
),
"moving_mnist" => crate::video::moving_mnist::MovingMnist::decode(
&crate::video::moving_mnist::MovingMnistConfig {
count: config.count,
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
),
"cifar100" => crate::image::cifar100::Cifar100::decode_with_progress(
&crate::image::cifar100::Cifar100Config {
split: config.split,
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
progress,
),
"emnist" => crate::image::emnist::Emnist::decode_with_progress(
&crate::image::emnist::EmnistConfig {
split: config.split,
variant: crate::image::emnist::EmnistVariant::Balanced,
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
progress,
),
"ag_news" => crate::text::ag_news::AgNews::decode_with_progress(
&crate::text::ag_news::AgNewsConfig {
split: config.split,
text_len: 512,
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
progress,
),
"imdb" => crate::text::imdb::Imdb::decode_with_progress(
&crate::text::imdb::ImdbConfig {
split: config.split,
text_len: 512,
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
progress,
),
"yelp_polarity" => crate::text::yelp_polarity::YelpPolarity::decode_with_progress(
&crate::text::yelp_polarity::YelpPolarityConfig {
split: config.split,
text_len: 512,
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
progress,
),
"speech_commands" => crate::audio::speech_commands::SpeechCommands::decode_with_progress(
&crate::audio::speech_commands::SpeechCommandsConfig {
split: match config.split {
IdxSplit::Train => crate::audio::speech_commands::SpeechCommandsSplit::Train,
IdxSplit::Test => crate::audio::speech_commands::SpeechCommandsSplit::Test,
},
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
progress,
),
"groove" => crate::audio::groove::Groove::decode_with_progress(
&crate::audio::groove::GrooveConfig {
split: match config.split {
IdxSplit::Train => crate::audio::groove::GrooveSplit::Train,
IdxSplit::Test => crate::audio::groove::GrooveSplit::Test,
},
seq_len: crate::audio::groove::DEFAULT_SEQ_LEN,
cache_dir: config.cache_dir.clone(),
},
progress,
),
"iris" => crate::tabular::iris::Iris::decode_with_progress(
&crate::tabular::iris::IrisConfig {
normalize: config.normalize,
cache_dir: config.cache_dir.clone(),
},
progress,
),
"titanic" => crate::tabular::titanic::Titanic::decode_with_progress(
&crate::tabular::titanic::TitanicConfig {
normalize: config.normalize,
cache_dir: config.cache_dir.clone(),
},
progress,
),
"stl10" => crate::image::stl10::Stl10::decode_with_progress(
&crate::image::stl10::Stl10Config {
split: config.split,
cache_dir: config.cache_dir.clone(),
normalize: config.normalize,
},
progress,
),
"movielens_100k" => crate::tabular::movielens_100k::Movielens100k::decode_with_progress(
&crate::tabular::movielens_100k::Movielens100kConfig {
split: config.split,
cache_dir: config.cache_dir.clone(),
},
progress,
),
"movielens_1m" => crate::tabular::movielens_1m::Movielens1m::decode_with_progress(
&crate::tabular::movielens_1m::Movielens1mConfig {
cache_dir: config.cache_dir.clone(),
},
progress,
),
"ljspeech" => crate::audio::ljspeech::LjSpeech::decode_with_progress(
&crate::audio::ljspeech::LjSpeechConfig {
cache_dir: config.cache_dir.clone(),
},
progress,
),
"crema_d" => crate::audio::crema_d::CremaD::decode_with_progress(
&crate::audio::crema_d::CremaDConfig {
split: match config.split {
IdxSplit::Train => crate::audio::crema_d::CremaDSplit::Train,
IdxSplit::Test => crate::audio::crema_d::CremaDSplit::Test,
},
cache_dir: config.cache_dir.clone(),
},
progress,
),
"vctk" => crate::audio::vctk::Vctk::decode_with_progress(
&crate::audio::vctk::VctkConfig {
mic: crate::audio::vctk::VctkMic::Mic1,
cache_dir: config.cache_dir.clone(),
},
progress,
),
_ => Err(Error::invalid_argument(format!(
"unknown dataset pack '{name}'"
))),
}
}