Skip to content

Commit 87f667c

Browse files
committed
update imdb data.
1 parent 317740a commit 87f667c

5 files changed

Lines changed: 27 additions & 8 deletions

File tree

data/imdb.zip

123 KB
Binary file not shown.

src/TensorFlowNET.Utility/Compress.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.IO;
55
using System.IO.Compression;
6+
using System.Linq;
67
using System.Threading;
78
using System.Threading.Tasks;
89

@@ -12,6 +13,9 @@ public class Compress
1213
{
1314
public static void UnZip(String gzArchiveName, String destFolder)
1415
{
16+
var flag = gzArchiveName.Split(Path.DirectorySeparatorChar).Last().Split('.').First() + ".bin";
17+
if (File.Exists(Path.Combine(destFolder, flag))) return;
18+
1519
Console.WriteLine($"Extracting.");
1620
var task = Task.Run(() =>
1721
{
@@ -24,12 +28,16 @@ public static void UnZip(String gzArchiveName, String destFolder)
2428
Console.Write(".");
2529
}
2630

31+
File.Create(Path.Combine(destFolder, flag));
2732
Console.WriteLine("");
2833
Console.WriteLine("Extracting is completed.");
2934
}
3035

3136
public static void ExtractTGZ(String gzArchiveName, String destFolder)
3237
{
38+
var flag = gzArchiveName.Split(Path.DirectorySeparatorChar).Last().Split('.').First() + ".bin";
39+
if (File.Exists(Path.Combine(destFolder, flag))) return;
40+
3341
Console.WriteLine($"Extracting.");
3442
var task = Task.Run(() =>
3543
{
@@ -49,6 +57,7 @@ public static void ExtractTGZ(String gzArchiveName, String destFolder)
4957
Console.Write(".");
5058
}
5159

60+
File.Create(Path.Combine(destFolder, flag));
5261
Console.WriteLine("");
5362
Console.WriteLine("Extracting is completed.");
5463
}

test/TensorFlowNET.Examples/ImageRecognition.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ private void PrepareData()
8888
string zipFile = Path.Join(dir, "inception5h.zip");
8989
Utility.Web.Download(url, zipFile);
9090

91-
if (!File.Exists(Path.Join(dir, pbFile)))
92-
Utility.Compress.UnZip(zipFile, dir);
91+
Utility.Compress.UnZip(zipFile, dir);
9392

9493
// download sample picture
9594
string pic = Path.Join(dir, "img", "grace_hopper.jpg");

test/TensorFlowNET.Examples/LabelImage.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ private void PrepareData()
106106
string zipFile = Path.Join(dir, $"{pbFile}.tar.gz");
107107
Utility.Web.Download(url, zipFile);
108108

109-
if (!File.Exists(Path.Join(dir, pbFile)))
110-
Utility.Compress.ExtractTGZ(zipFile, dir);
109+
Utility.Compress.ExtractTGZ(zipFile, dir);
111110

112111
// download sample picture
113112
string pic = "grace_hopper.jpg";

test/TensorFlowNET.Examples/TextClassificationWithMovieReviews.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
using System.IO;
44
using System.Text;
55
using Tensorflow;
6+
using NumSharp.Core;
67

78
namespace TensorFlowNET.Examples
89
{
910
public class TextClassificationWithMovieReviews : Python, IExample
1011
{
1112
string dir = "text_classification_with_movie_reviews";
13+
string dataFile = "imdb.zip";
1214

1315
public void Run()
1416
{
@@ -17,17 +19,27 @@ public void Run()
1719

1820
private void PrepareData()
1921
{
20-
2122
Directory.CreateDirectory(dir);
2223

2324
// get model file
24-
string url = "https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz";
25+
string url = $"https://github.com/SciSharp/TensorFlow.NET/raw/master/data/{dataFile}";
2526

2627
string zipFile = Path.Join(dir, $"imdb.zip");
2728
Utility.Web.Download(url, zipFile);
29+
Utility.Compress.UnZip(zipFile, dir);
30+
31+
// prepare training dataset
32+
NDArray x_train = File.ReadAllLines(Path.Join(dir, "x_train.txt"));
33+
NDArray labels_train = File.ReadAllLines(Path.Join(dir, "y_train.txt"));
34+
NDArray indices_train = File.ReadAllLines(Path.Join(dir, "indices_train.txt"));
35+
x_train = x_train[indices_train];
36+
labels_train = labels_train[indices_train];
2837

29-
if (!File.Exists(Path.Join(dir, zipFile)))
30-
Utility.Compress.ExtractTGZ(zipFile, dir);
38+
NDArray x_test = File.ReadAllLines(Path.Join(dir, "x_test.txt"));
39+
NDArray labels_test = File.ReadAllLines(Path.Join(dir, "y_test.txt"));
40+
NDArray indices_test = File.ReadAllLines(Path.Join(dir, "indices_test.txt"));
41+
x_test = x_test[indices_test];
42+
labels_test = labels_test[indices_test];
3143
}
3244
}
3345
}

0 commit comments

Comments
 (0)