Skip to content

Commit d6e0400

Browse files
committed
0.20.x-preview1, add tf.keras namespace.
1 parent c078ef6 commit d6e0400

13 files changed

Lines changed: 233 additions & 18 deletions

File tree

src/TensorFlowNET.Console/TensorFlowNET.Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.2.0.1" />
11+
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.2.0.2" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

src/TensorFlowNET.Core/APIs/c_api.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace Tensorflow
4343
/// </summary>
4444
public partial class c_api
4545
{
46-
public const string TensorFlowLibName = @"D:\SciSharp\tensorflow-google\bazel-bin\tensorflow\tensorflow.dll";
46+
public const string TensorFlowLibName = "tensorflow";
4747

4848
public static string StringPiece(IntPtr handle)
4949
{
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*****************************************************************************
2+
Copyright 2020 The TensorFlow.NET Authors. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
******************************************************************************/
16+
17+
using NumSharp;
18+
19+
namespace Tensorflow
20+
{
21+
public partial class tensorflow
22+
{
23+
public DataOps data { get; } = new DataOps();
24+
25+
public class DataOps
26+
{
27+
public TensorSliceDataset Dataset { get; } = new TensorSliceDataset();
28+
}
29+
}
30+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*****************************************************************************
2+
Copyright 2020 Haiping Chen. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
******************************************************************************/
16+
17+
using NumSharp;
18+
19+
namespace Tensorflow
20+
{
21+
public partial class tensorflow
22+
{
23+
public KerasApi keras { get; } = new KerasApi();
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Tensorflow
6+
{
7+
public class DatasetOps
8+
{
9+
}
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using NumSharp;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Tensorflow
7+
{
8+
public class TensorSliceDataset
9+
{
10+
public TensorSliceDataset(params NDArray[] elements)
11+
{
12+
13+
}
14+
15+
public TensorSliceDataset from_tensor_slices(params NDArray[] elements)
16+
{
17+
throw new NotImplementedException("");
18+
}
19+
}
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using NumSharp;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Tensorflow.Keras.Datasets
7+
{
8+
public class DatasetPass
9+
{
10+
public (NDArray, NDArray) Train { get; set; }
11+
public (NDArray, NDArray) Test { get; set; }
12+
13+
public void Deconstruct(out NDArray x_train, out NDArray y_train, out NDArray x_test, out NDArray y_test)
14+
{
15+
x_train = Train.Item1;
16+
y_train = Train.Item2;
17+
x_test = Test.Item1;
18+
y_test = Test.Item2;
19+
}
20+
21+
public void Deconstruct(out (NDArray, NDArray) train, out (NDArray, NDArray) test)
22+
{
23+
train = Train;
24+
test = Test;
25+
}
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*****************************************************************************
2+
Copyright 2020 Haiping Chen. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
******************************************************************************/
16+
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Text;
20+
21+
namespace Tensorflow.Keras.Datasets
22+
{
23+
public class KerasDataset
24+
{
25+
public Mnist mnist { get; } = new Mnist();
26+
}
27+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*****************************************************************************
2+
Copyright 2020 Haiping Chen. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
******************************************************************************/
16+
17+
using NumSharp;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.IO;
21+
using System.Net;
22+
using System.Text;
23+
24+
namespace Tensorflow.Keras.Datasets
25+
{
26+
public class Mnist
27+
{
28+
string origin_folder = "https://storage.googleapis.com/tensorflow/tf-keras-datasets/";
29+
string file_name = "mnist.npz";
30+
31+
/// <summary>
32+
/// Loads the [MNIST dataset](http://yann.lecun.com/exdb/mnist/).
33+
/// </summary>
34+
/// <returns></returns>
35+
public DatasetPass load_data()
36+
{
37+
var file = Download();
38+
var bytes = File.ReadAllBytes(file);
39+
var datax = LoadX(bytes);
40+
var datay = LoadY(bytes);
41+
return new DatasetPass
42+
{
43+
Train = (datax.Item1, datay.Item1),
44+
Test = (datax.Item2, datay.Item2)
45+
};
46+
}
47+
48+
(NDArray, NDArray) LoadX(byte[] bytes)
49+
{
50+
var y = np.Load_Npz<byte[,,]>(bytes);
51+
return (y["x_train.npy"], y["x_test.npy"]);
52+
}
53+
54+
(NDArray, NDArray) LoadY(byte[] bytes)
55+
{
56+
var y = np.Load_Npz<byte[]>(bytes);
57+
return (y["y_train.npy"], y["y_test.npy"]);
58+
}
59+
60+
string Download()
61+
{
62+
var fileSaveTo = Path.Combine(Path.GetTempPath(), file_name);
63+
64+
if (File.Exists(fileSaveTo))
65+
{
66+
Console.WriteLine($"The file {fileSaveTo} already exists");
67+
return fileSaveTo;
68+
}
69+
70+
using var wc = new WebClient();
71+
wc.DownloadFileTaskAsync(origin_folder + file_name, fileSaveTo).Wait();
72+
73+
return fileSaveTo;
74+
}
75+
}
76+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Data;
2+
using Tensorflow.Keras;
3+
using Tensorflow.Keras.Datasets;
4+
5+
namespace Tensorflow
6+
{
7+
public class KerasApi
8+
{
9+
public KerasDataset datasets { get; } = new KerasDataset();
10+
public Initializers initializers { get; } = new Initializers();
11+
}
12+
}

0 commit comments

Comments
 (0)