Skip to content

Commit e2f7be6

Browse files
committed
InputLayer for Keras.
1 parent 6726cbd commit e2f7be6

100 files changed

Lines changed: 2110 additions & 1941 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ In comparison to other projects, like for instance TensorFlowSharp which only pr
2626

2727
### How to use
2828

29-
| TensorFlow | tf 1.13 | tf 1.14 | tf 1.15 | tf 2.2 |
30-
| ----------- | ------- | ------- | ------- | ------ |
31-
| tf.net 0.20 | | | x | x |
32-
| tf.net 0.15 | | x | x | |
33-
| tf.net 0.14 | x | x | | |
29+
| TensorFlow | tf native1.14 | tf native 1.15 | tf native 2.3 |
30+
| ----------- | ------------- | -------------- | ------------- |
31+
| tf.net 0.20 | | x | x |
32+
| tf.net 0.15 | x | x | |
33+
| tf.net 0.14 | x | | |
3434

3535
Install TF.NET and TensorFlow binary through NuGet.
3636
```sh
@@ -138,6 +138,10 @@ Scan QR code to join Tencent TIM group:
138138

139139
![SciSharp STACK](docs/TIM.jpg)
140140

141+
WeChat Sponsor 微信打赏:
142+
143+
![SciSharp STACK](docs/assets/WeChatCollection.jpg)
144+
141145
TensorFlow.NET is a part of [SciSharp STACK](https://scisharp.github.io/SciSharp/)
142146
<br>
143-
<a href="http://scisharpstack.org"><img src="https://github.com/SciSharp/SciSharp/blob/master/art/scisharp-stack.png" width="391" height="100" /></a>
147+
<a href="http://scisharpstack.org"><img src="https://github.com/SciSharp/SciSharp/blob/master/art/scisharp-stack.png" width="391" height="100" /></a>

docs/assets/WeChatCollection.jpg

59.9 KB
Loading

src/TensorFlowNET.Console/MemoryMonitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class MemoryMonitor
1010
{
1111
public void WarmUp()
1212
{
13-
print(tf.VERSION);
13+
print($"tensorflow native version: v{tf.VERSION}");
1414
}
1515

1616
public void Execute(int epoch, int iterate, Action<int> process)

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.2" />
11+
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.3.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

src/TensorFlowNET.Core/APIs/keras.layers.cs

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/TensorFlowNET.Core/APIs/tf.compat.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ public class CompatApi
2626
{
2727
public CompatV1Api v1 { get; } = new CompatV1Api();
2828
}
29+
30+
public bool executing_eagerly()
31+
=> Context.executing_eagerly();
2932
}
3033
}

src/TensorFlowNET.Core/APIs/tf.compat.v1.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ limitations under the License.
1616

1717
using System;
1818
using System.Collections.Generic;
19-
using Tensorflow.Eager;
19+
using Tensorflow.Contexts;
2020
using static Tensorflow.Binding;
2121

2222
namespace Tensorflow
2323
{
2424
public class CompatV1Api
2525
{
2626
public void disable_eager_execution()
27-
{
28-
tf.context.default_execution_mode = Context.GRAPH_MODE;
29-
}
27+
=> tf.Context.graph_mode();
3028

3129
public IVariableV1 get_variable(string name,
3230
TensorShape shape = null,

src/TensorFlowNET.Core/APIs/tf.layers.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
using System.Collections.Generic;
1919
using System.Linq;
2020
using NumSharp;
21+
using Tensorflow.Keras;
2122
using Tensorflow.Keras.ArgsDefinition;
2223
using Tensorflow.Keras.Layers;
2324
using Tensorflow.Operations.Activation;
@@ -164,7 +165,7 @@ public Tensor max_pooling2d(Tensor inputs,
164165
/// <returns></returns>
165166
public Tensor dense(Tensor inputs,
166167
int units,
167-
IActivation activation = null,
168+
Activation activation = null,
168169
bool use_bias = true,
169170
IInitializer kernel_initializer = null,
170171
IInitializer bias_initializer = null,
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*****************************************************************************
2+
Copyright 2018 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 System;
18+
using Tensorflow.Eager;
19+
20+
namespace Tensorflow.Contexts
21+
{
22+
/// <summary>
23+
/// Environment in which eager operations execute.
24+
/// </summary>
25+
public sealed class Context : IDisposable
26+
{
27+
public const int GRAPH_MODE = 0;
28+
public const int EAGER_MODE = 1;
29+
30+
int defaultExecutionMode = EAGER_MODE;
31+
public string DeviceName { get; set; } = "";
32+
public string ScopeName { get; set; } = "";
33+
bool initialized = false;
34+
bool isEager;
35+
ContextSwitchStack contextSwitches;
36+
37+
public SafeContextHandle Handle { get; }
38+
39+
public Context(ContextOptions opts, Status status)
40+
{
41+
Handle = c_api.TFE_NewContext(opts.Handle, status.Handle);
42+
status.Check(true);
43+
isEager = defaultExecutionMode == EAGER_MODE;
44+
contextSwitches = new ContextSwitchStack(isEager);
45+
initialized = true;
46+
}
47+
48+
/// <summary>
49+
/// Initialize handle and devices if not already done so.
50+
/// </summary>
51+
public void ensure_initialized()
52+
{
53+
if (initialized)
54+
return;
55+
initialized = true;
56+
}
57+
58+
public void start_step()
59+
=> c_api.TFE_ContextStartStep(Handle);
60+
61+
public void end_step()
62+
=> c_api.TFE_ContextEndStep(Handle);
63+
64+
/// <summary>
65+
/// Checks whether the current thread has eager execution enabled.
66+
/// </summary>
67+
/// <returns></returns>
68+
public bool executing_eagerly()
69+
=> isEager;
70+
71+
public string shared_name(string name = null)
72+
=> !string.IsNullOrEmpty(name) || !executing_eagerly() ?
73+
name :
74+
"cd2c89b7-88b7-44c8-ad83-06c2a9158347";
75+
76+
public void graph_mode()
77+
=> mode(false);
78+
79+
public void eager_mode()
80+
=> mode(true);
81+
82+
void mode(bool mode)
83+
{
84+
isEager = mode;
85+
}
86+
87+
public void Dispose()
88+
=> Handle.Dispose();
89+
}
90+
}

src/TensorFlowNET.Core/Eager/ContextOptions.cs renamed to src/TensorFlowNET.Core/Contexts/ContextOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ limitations under the License.
1515
******************************************************************************/
1616

1717
using System;
18+
using Tensorflow.Eager;
1819

19-
namespace Tensorflow.Eager
20+
namespace Tensorflow.Contexts
2021
{
2122
public sealed class ContextOptions : IDisposable
2223
{

0 commit comments

Comments
 (0)