Skip to content

Commit 3370723

Browse files
committed
Define Keras interface in core project (WIP).
1 parent 19363cd commit 3370723

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+610
-205
lines changed

src/SciSharp.TensorFlow.Redist/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Related merged [commits](https://github.com/SciSharp/TensorFlow.NET/commit/854a5
2626

2727
#### Download pre-build package
2828

29-
[Mac OSX CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-2.4.0.tar.gz), [Linux CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.4.0.tar.gz), [Linux GPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.4.0.tar.gz), [Windows CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-2.4.0.tar.gz), [Windows GPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-2.4.0.zip)
29+
[Mac OSX CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-2.10.0.tar.gz), [Linux CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.10.0.tar.gz), [Linux GPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.10.0.tar.gz), [Windows CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-2.10.0.zip), [Windows GPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-2.10.0.zip)
3030

3131

3232

@@ -35,6 +35,6 @@ Related merged [commits](https://github.com/SciSharp/TensorFlow.NET/commit/854a5
3535
On Windows, the tar command does not support extracting archives with symlinks. So when `dotnet pack` runs on Windows it will only package the Windows binaries.
3636

3737
1. Run `dotnet pack SciSharp.TensorFlow.Redist.nupkgproj` under `src/SciSharp.TensorFlow.Redist` directory in Linux.
38-
2. Run `dotnet nuget push SciSharp.TensorFlow.Redist.2.4.0.nupkg -k APIKEY -s https://api.nuget.org/v3/index.json -t 600`
38+
2. Run `dotnet nuget push SciSharp.TensorFlow.Redist.2.10.0.nupkg -k APIKEY -s https://api.nuget.org/v3/index.json -t 600`
3939

4040

src/TensorFlowNET.Console/Program.cs

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ static void Main(string[] args)
1010
var diag = new Diagnostician();
1111
// diag.Diagnose(@"D:\memory.txt");
1212

13+
var rnn = new SimpleRnnTest();
14+
rnn.Run();
15+
1316
// this class is used explor new features.
1417
var exploring = new Exploring();
1518
// exploring.Run();
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Tensorflow.Keras;
5+
using Tensorflow.NumPy;
6+
using static Tensorflow.Binding;
7+
using static Tensorflow.KerasApi;
8+
9+
namespace Tensorflow
10+
{
11+
public class SimpleRnnTest
12+
{
13+
public void Run()
14+
{
15+
tf.keras = new KerasInterface();
16+
var inputs = np.random.random((32, 10, 8)).astype(np.float32);
17+
var simple_rnn = tf.keras.layers.SimpleRNN(4);
18+
var output = simple_rnn.Apply(inputs); // The output has shape `[32, 4]`.
19+
if (output.shape == (32, 4))
20+
{
21+
22+
}
23+
/*simple_rnn = tf.keras.layers.SimpleRNN(
24+
4, return_sequences = True, return_state = True)
25+
26+
# whole_sequence_output has shape `[32, 10, 4]`.
27+
# final_state has shape `[32, 4]`.
28+
whole_sequence_output, final_state = simple_rnn(inputs)*/
29+
}
30+
}
31+
}

src/TensorFlowNET.Console/Tensorflow.Console.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<RootNamespace>Tensorflow</RootNamespace>
77
<AssemblyName>Tensorflow</AssemblyName>
88
<Platforms>AnyCPU;x64</Platforms>
9-
<LangVersion>9.0</LangVersion>
9+
<LangVersion>11.0</LangVersion>
1010
</PropertyGroup>
1111

1212
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -20,7 +20,7 @@
2020
</PropertyGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="SciSharp.TensorFlow.Redist-Windows-GPU" Version="2.7.0" />
23+
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.10.0" />
2424
</ItemGroup>
2525

2626
<ItemGroup>

src/TensorFlowNET.Core/Keras/ArgsDefinition/LSTMArgs.cs

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Tensorflow.Keras.ArgsDefinition.Rnn;
2+
3+
namespace Tensorflow.Keras.ArgsDefinition.Lstm
4+
{
5+
public class LSTMArgs : RNNArgs
6+
{
7+
public bool UnitForgetBias { get; set; }
8+
public float Dropout { get; set; }
9+
public float RecurrentDropout { get; set; }
10+
public int Implementation { get; set; }
11+
}
12+
}

src/TensorFlowNET.Core/Keras/ArgsDefinition/LSTMCellArgs.cs renamed to src/TensorFlowNET.Core/Keras/ArgsDefinition/Lstm/LSTMCellArgs.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Tensorflow.Keras.ArgsDefinition
1+
namespace Tensorflow.Keras.ArgsDefinition.Lstm
22
{
33
public class LSTMCellArgs : LayerArgs
44
{

src/TensorFlowNET.Core/Keras/ArgsDefinition/RNNArgs.cs

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Collections.Generic;
2+
3+
namespace Tensorflow.Keras.ArgsDefinition.Rnn
4+
{
5+
public class RNNArgs : LayerArgs
6+
{
7+
public interface IRnnArgCell : ILayer
8+
{
9+
object state_size { get; }
10+
}
11+
12+
public IRnnArgCell Cell { get; set; } = null;
13+
public bool ReturnSequences { get; set; } = false;
14+
public bool ReturnState { get; set; } = false;
15+
public bool GoBackwards { get; set; } = false;
16+
public bool Stateful { get; set; } = false;
17+
public bool Unroll { get; set; } = false;
18+
public bool TimeMajor { get; set; } = false;
19+
public Dictionary<string, object> Kwargs { get; set; } = null;
20+
21+
public int Units { get; set; }
22+
public Activation Activation { get; set; }
23+
public Activation RecurrentActivation { get; set; }
24+
public bool UseBias { get; set; } = true;
25+
public IInitializer KernelInitializer { get; set; }
26+
public IInitializer RecurrentInitializer { get; set; }
27+
public IInitializer BiasInitializer { get; set; }
28+
29+
// kernel_regularizer=None,
30+
// recurrent_regularizer=None,
31+
// bias_regularizer=None,
32+
// activity_regularizer=None,
33+
// kernel_constraint=None,
34+
// recurrent_constraint=None,
35+
// bias_constraint=None,
36+
// dropout=0.,
37+
// recurrent_dropout=0.,
38+
// return_sequences=False,
39+
// return_state=False,
40+
// go_backwards=False,
41+
// stateful=False,
42+
// unroll=False,
43+
// **kwargs):
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Tensorflow.Keras.ArgsDefinition.Rnn
2+
{
3+
public class SimpleRNNArgs : RNNArgs
4+
{
5+
6+
}
7+
}

src/TensorFlowNET.Core/Keras/ArgsDefinition/StackedRNNCellsArgs.cs renamed to src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/StackedRNNCellsArgs.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Collections.Generic;
22

3-
namespace Tensorflow.Keras.ArgsDefinition
3+
namespace Tensorflow.Keras.ArgsDefinition.Rnn
44
{
55
public class StackedRNNCellsArgs : LayerArgs
66
{

src/TensorFlowNET.Core/Keras/ArgsDefinition/SimpleRNNArgs.cs

-30
This file was deleted.
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Tensorflow.Keras.Layers;
5+
6+
namespace Tensorflow.Keras
7+
{
8+
public interface IKerasApi
9+
{
10+
public ILayersApi layers { get; }
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Tensorflow.Keras
6+
{
7+
public interface IPreprocessing
8+
{
9+
public ILayer Resizing(int height, int width, string interpolation = "bilinear");
10+
public ILayer TextVectorization(Func<Tensor, Tensor> standardize = null,
11+
string split = "whitespace",
12+
int max_tokens = -1,
13+
string output_mode = "int",
14+
int output_sequence_length = -1);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using Tensorflow.Keras.ArgsDefinition;
3+
using Tensorflow.NumPy;
4+
using Tensorflow.Operations.Activation;
5+
6+
namespace Tensorflow.Keras.Layers
7+
{
8+
public partial interface ILayersApi
9+
{
10+
public ILayer ELU(float alpha = 0.1f);
11+
public ILayer SELU();
12+
public ILayer Softmax(Axis axis);
13+
public ILayer Softplus();
14+
public ILayer HardSigmoid();
15+
public ILayer Softsign();
16+
public ILayer Swish();
17+
public ILayer Tanh();
18+
public ILayer Exponential();
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using Tensorflow.Keras.ArgsDefinition;
3+
using Tensorflow.NumPy;
4+
5+
namespace Tensorflow.Keras.Layers
6+
{
7+
public partial interface ILayersApi
8+
{
9+
public ILayer Attention(bool use_scale = false,
10+
string score_mode = "dot",
11+
bool causal = false,
12+
float dropout = 0f);
13+
public ILayer MultiHeadAttention(int num_heads,
14+
int key_dim,
15+
int? value_dim = null,
16+
float dropout = 0f,
17+
bool use_bias = true,
18+
Shape output_shape = null,
19+
Shape attention_axes = null,
20+
IInitializer kernel_initializer = null,
21+
IInitializer bias_initializer = null,
22+
IRegularizer kernel_regularizer = null,
23+
IRegularizer bias_regularizer = null,
24+
IRegularizer activity_regularizer = null,
25+
Action kernel_constraint = null,
26+
Action bias_constraint = null);
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using Tensorflow.Keras.ArgsDefinition;
3+
using Tensorflow.NumPy;
4+
5+
namespace Tensorflow.Keras.Layers
6+
{
7+
public partial interface ILayersApi
8+
{
9+
public ILayer Cropping1D(NDArray cropping);
10+
public ILayer Cropping2D(NDArray cropping, Cropping2DArgs.DataFormat data_format = Cropping2DArgs.DataFormat.channels_last);
11+
public ILayer Cropping3D(NDArray cropping, Cropping3DArgs.DataFormat data_format = Cropping3DArgs.DataFormat.channels_last);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using Tensorflow.NumPy;
3+
4+
namespace Tensorflow.Keras.Layers
5+
{
6+
public partial interface ILayersApi
7+
{
8+
public ILayer Concatenate(int axis = -1);
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using Tensorflow.Keras.ArgsDefinition;
3+
using Tensorflow.NumPy;
4+
5+
namespace Tensorflow.Keras.Layers
6+
{
7+
public partial interface ILayersApi
8+
{
9+
public ILayer Reshape(Shape target_shape);
10+
public ILayer Reshape(object[] target_shape);
11+
12+
public ILayer UpSampling2D(Shape size = null,
13+
string data_format = null,
14+
string interpolation = "nearest");
15+
16+
public ILayer ZeroPadding2D(NDArray padding);
17+
}
18+
}

0 commit comments

Comments
 (0)