@@ -12,21 +12,35 @@ namespace Microsoft.ML.SamplesUtils
12
12
{
13
13
public static class DatasetUtils
14
14
{
15
- /// <summary>
16
- /// Downloads the housing dataset from the ML.NET repo.
17
- /// </summary>
18
- public static string DownloadHousingRegressionDataset ( )
15
+ public static string GetFilePathFromDataDirectory ( string fileName )
19
16
{
20
- var fileName = "housing.txt" ;
21
- if ( ! File . Exists ( fileName ) )
22
- Download ( "https://raw.githubusercontent.com/dotnet/machinelearning/024bd4452e1d3660214c757237a19d6123f951ca/test/data/housing.txt" , fileName ) ;
23
- return fileName ;
17
+ #if NETFRAMEWORK
18
+ string directory = AppDomain . CurrentDomain . BaseDirectory ;
19
+ #else
20
+ string directory = AppContext . BaseDirectory ;
21
+ #endif
22
+
23
+ while ( ! Directory . Exists ( Path . Combine ( directory , ".git" ) ) && directory != null )
24
+ {
25
+ directory = Directory . GetParent ( directory ) . FullName ;
26
+ }
27
+
28
+ if ( directory == null )
29
+ {
30
+ throw new DirectoryNotFoundException ( "Could not find the ML.NET repository" ) ;
31
+ }
32
+ return Path . Combine ( directory , "test" , "data" , fileName ) ;
24
33
}
25
34
35
+ /// <summary>
36
+ /// Returns the path to the housing dataset from the ML.NET repo.
37
+ /// </summary>
38
+ public static string GetHousingRegressionDataset ( ) => GetFilePathFromDataDirectory ( "housing.txt" ) ;
39
+
26
40
public static IDataView LoadHousingRegressionDataset ( MLContext mlContext )
27
41
{
28
- // Download the file
29
- string dataFile = DownloadHousingRegressionDataset ( ) ;
42
+ // Obtains the path to the file
43
+ string dataFile = GetHousingRegressionDataset ( ) ;
30
44
31
45
// Define the columns to load
32
46
var loader = mlContext . Data . CreateTextLoader (
@@ -55,13 +69,12 @@ public static IDataView LoadHousingRegressionDataset(MLContext mlContext)
55
69
}
56
70
57
71
/// <summary>
58
- /// Downloads the adult dataset from the ML.NET repo.
72
+ /// Returns the path to the adult dataset from the ML.NET repo.
59
73
/// </summary>
60
- public static string DownloadAdultDataset ( )
61
- => Download ( "https://raw.githubusercontent.com/dotnet/machinelearning/244a8c2ac832657af282aa312d568211698790aa/test/data/adult.train" , "adult.txt" ) ;
74
+ public static string GetAdultDataset ( ) => GetFilePathFromDataDirectory ( "adult.txt" ) ;
62
75
63
76
/// <summary>
64
- /// Downloads the Adult UCI dataset and featurizes it to be suitable for classification tasks.
77
+ /// Returns the path to the Adult UCI dataset and featurizes it to be suitable for classification tasks.
65
78
/// </summary>
66
79
/// <param name="mlContext"><see cref="MLContext"/> used for data loading and processing.</param>
67
80
/// <returns>Featurized dataset.</returns>
@@ -70,8 +83,8 @@ public static string DownloadAdultDataset()
70
83
/// </remarks>
71
84
public static IDataView LoadFeaturizedAdultDataset ( MLContext mlContext )
72
85
{
73
- // Download the file
74
- string dataFile = DownloadAdultDataset ( ) ;
86
+ // Obtains the path to the file
87
+ string dataFile = GetAdultDataset ( ) ;
75
88
76
89
// Define the columns to load
77
90
var loader = mlContext . Data . CreateTextLoader (
@@ -120,30 +133,14 @@ public static IDataView LoadFeaturizedAdultDataset(MLContext mlContext)
120
133
}
121
134
122
135
/// <summary>
123
- /// Downloads the breast cancer dataset from the ML.NET repo.
136
+ /// Returns the path to the breast cancer dataset from the ML.NET repo.
124
137
/// </summary>
125
- public static string DownloadBreastCancerDataset ( )
126
- => Download ( "https://raw.githubusercontent.com/dotnet/machinelearning/76cb2cdf5cc8b6c88ca44b8969153836e589df04/test/data/breast-cancer.txt" , "breast-cancer.txt" ) ;
138
+ public static string GetBreastCancerDataset ( ) => GetFilePathFromDataDirectory ( "breast-cancer.txt" ) ;
127
139
128
140
/// <summary>
129
- /// Downloads 4 images, and a tsv file with their names from the dotnet/machinelearning repo.
141
+ /// Returns the path to 4 sample images, and a tsv file with their names from the dotnet/machinelearning repo.
130
142
/// </summary>
131
- public static string DownloadImages ( )
132
- {
133
- string path = "images" ;
134
-
135
- var dirInfo = Directory . CreateDirectory ( path ) ;
136
-
137
- string pathEscaped = $ "{ path } { Path . DirectorySeparatorChar } ";
138
-
139
- Download ( "https://raw.githubusercontent.com/dotnet/machinelearning/284e02cadf5342aa0c36f31d62fc6fa15bc06885/test/data/images/banana.jpg" , $ "{ pathEscaped } banana.jpg") ;
140
- Download ( "https://raw.githubusercontent.com/dotnet/machinelearning/284e02cadf5342aa0c36f31d62fc6fa15bc06885/test/data/images/hotdog.jpg" , $ "{ pathEscaped } hotdog.jpg") ;
141
- Download ( "https://raw.githubusercontent.com/dotnet/machinelearning/284e02cadf5342aa0c36f31d62fc6fa15bc06885/test/data/images/images.tsv" , $ "{ pathEscaped } images.tsv") ;
142
- Download ( "https://raw.githubusercontent.com/dotnet/machinelearning/284e02cadf5342aa0c36f31d62fc6fa15bc06885/test/data/images/tomato.bmp" , $ "{ pathEscaped } tomato.bmp") ;
143
- Download ( "https://raw.githubusercontent.com/dotnet/machinelearning/284e02cadf5342aa0c36f31d62fc6fa15bc06885/test/data/images/tomato.jpg" , $ "{ pathEscaped } tomato.jpg") ;
144
-
145
- return $ "{ path } { Path . DirectorySeparatorChar } images.tsv";
146
- }
143
+ public static string GetSampleImages ( ) => GetFilePathFromDataDirectory ( "images/images.tsv" ) ;
147
144
148
145
/// <summary>
149
146
/// Downloads sentiment_model from the dotnet/machinelearning-testdata repo.
0 commit comments