forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_utils.cs
More file actions
43 lines (37 loc) · 1.29 KB
/
data_utils.cs
File metadata and controls
43 lines (37 loc) · 1.29 KB
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
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Tensorflow.Keras.Utils
{
public class data_utils
{
public static string get_file(string fname, string origin,
bool untar = false,
string md5_hash = null,
string file_hash = null,
string cache_subdir = "datasets",
string hash_algorithm = "auto",
bool extract = false,
string archive_format = "auto",
string cache_dir = null)
{
if (string.IsNullOrEmpty(cache_dir))
cache_dir = Path.GetTempPath();
var datadir_base = cache_dir;
Directory.CreateDirectory(datadir_base);
var datadir = Path.Combine(datadir_base, cache_subdir);
Directory.CreateDirectory(datadir);
Web.Download(origin, datadir, fname);
var archive = Path.Combine(datadir, fname);
if (untar)
Compress.ExtractTGZ(archive, datadir);
else if (extract && fname.EndsWith(".gz"))
Compress.ExtractGZip(archive, datadir);
else if (extract && fname.EndsWith(".zip"))
Compress.UnZip(archive, datadir);
return datadir;
}
}
}