private void DownloadDataset(string path) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (File.Exists(Path.Combine(path, MnistTrainingImages)) && File.Exists(Path.Combine(path, MnistTrainingLabels))) { Console.WriteLine("Dataset already downloaded."); return; } string downloadPath = Path.Combine(path, "mnist.zip"); var downloader = new FileDownloader(ConsoleProgressWriter.Instance); if (!downloader.DownloadAndExtract(MnistUrl, downloadPath, file => { file.ExtractAll(path, ExtractExistingFileAction.OverwriteSilently); })) { throw new InvalidOperationException("Failed to download MNIST"); } }
/// <summary> /// Tries to enable Math.NET native MKL provider. If not found and download is enabled, downloads /// and exctracts MKL into [Retia.dll location]\x64. /// </summary> /// <param name="tryDownload">Whether MKL download is enabled.</param> /// <param name="progressWriter">Progress writer.</param> /// <returns>True if could use MKL provider, false otherwise.</returns> public static bool TryUseMkl(bool tryDownload = true, IProgressWriter progressWriter = null) { if (Control.TryUseNativeMKL()) { progressWriter?.Message("Using MKL."); return(true); } if (!tryDownload) { progressWriter?.Message("Couldn't use MKL and download is disabled. Using slow math provider."); return(false); } progressWriter?.Message("Couldn't use MKL right away, trying to download..."); string tempPath = Path.Combine(Path.GetTempPath(), FileName); string extractDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "x64"); var downloader = new FileDownloader(progressWriter); if (!Directory.Exists(extractDir)) { Directory.CreateDirectory(extractDir); } if (!downloader.DownloadAndExtract(MKLPackage, tempPath, file => { var files = file.SelectEntries("*.*", @"build/x64"); foreach (var entry in files) { using (var stream = new FileStream(Path.Combine(extractDir, Path.GetFileName(entry.FileName)), FileMode.Create, FileAccess.Write)) { entry.Extract(stream); } } }, true)) { return(false); } if (!Control.TryUseNativeMKL()) { progressWriter?.Message("Still can't use MKL, giving up."); return(false); } return(true); }