示例#1
0
        public static async Task <ITestDataset> GetTestDatasetAsync([CanBeNull] Action <TrainingProgressEventArgs> progress = null, CancellationToken token = default)
        {
            Func <Stream>[] factories = await Task.WhenAll(
                DatasetsDownloader.GetFileAsync($"{MnistHttpRootPath}{TestSetValuesFilename}", null, token),
                DatasetsDownloader.GetFileAsync($"{MnistHttpRootPath}{TestSetLabelsFilename}", null, token));

            if (factories.Any(s => s == null))
            {
                return(null);
            }
            (float[,] X, float[,] Y)data = ParseSamples((factories[0], factories[1]), TestSamples);
            return(data.X == null || data.Y == null
                ? null
                : DatasetLoader.Test(data, progress));
        }
示例#2
0
        public static async Task <ITrainingDataset> GetTrainingDatasetAsync(int size, CancellationToken token = default)
        {
            Func <Stream>[] factories = await Task.WhenAll(
                DatasetsDownloader.GetFileAsync($"{MnistHttpRootPath}{TrainingSetValuesFilename}", null, token),
                DatasetsDownloader.GetFileAsync($"{MnistHttpRootPath}{TrainingSetLabelsFilename}", null, token));

            if (factories.Any(s => s == null))
            {
                return(null);
            }
            (float[,] X, float[,] Y)data = ParseSamples((factories[0], factories[1]), TrainingSamples);
            return(data.X == null || data.Y == null
                ? null
                : DatasetLoader.Training(data, size));
        }
示例#3
0
        public static async Task <bool> ExportDatasetAsync([NotNull] DirectoryInfo directory, CancellationToken token = default)
        {
            Func <Stream>[] factories = await Task.WhenAll(
                DatasetsDownloader.GetFileAsync($"{MnistHttpRootPath}{TrainingSetValuesFilename}", null, token),
                DatasetsDownloader.GetFileAsync($"{MnistHttpRootPath}{TrainingSetLabelsFilename}", null, token),
                DatasetsDownloader.GetFileAsync($"{MnistHttpRootPath}{TestSetValuesFilename}", null, token),
                DatasetsDownloader.GetFileAsync($"{MnistHttpRootPath}{TestSetLabelsFilename}", null, token));

            if (factories.Any(s => s == null) || token.IsCancellationRequested)
            {
                return(false);
            }
            if (!directory.Exists)
            {
                directory.Create();
            }
            ParallelLoopResult result = Parallel.ForEach(new (string Name, Func <Stream> X, Func <Stream> Y, int Count)[]