Skip to content

Commit 8f8b0fd

Browse files
committed
Merge remote-tracking branch 'SciSharp/master' into safe-status-handle
2 parents f7b8421 + b83c77e commit 8f8b0fd

72 files changed

Lines changed: 2058 additions & 2534 deletions

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![Badge](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu/#/en_US)
1010
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/javiercp/BinderTF.NET/master?urlpath=lab)
1111

12-
*master branch is based on tensorflow 2.2 now, v0.15-tensorflow1.15 is from tensorflow1.15.*
12+
*master branch is based on tensorflow 2.3 now, v0.15-tensorflow1.15 is from tensorflow1.15.*
1313

1414

1515
![tensors_flowing](docs/assets/tensors_flowing.gif)

src/TensorFlowNET.Console/Program.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using static Tensorflow.Binding;
23

34
namespace Tensorflow
45
{
@@ -14,18 +15,19 @@ static void Main(string[] args)
1415

1516
int batchSize = 1000;
1617

17-
// 1 million float tensor 58.5M.
18+
// 1 million float tensor 68M.
1819
mm.Execute(10, 100 * batchSize, cases.Constant);
1920

20-
// 100K float variable 80.5M.
21+
// 100K float variable 84M.
2122
mm.Execute(10, 10 * batchSize, cases.Variable);
2223

23-
// 1 million math add 36.5M.
24+
// 1 million math add 39M.
2425
mm.Execute(10, 100 * batchSize, cases.MathAdd);
2526

26-
// 100K gradient 210M.
27+
// 100K gradient 44M.
2728
mm.Execute(10, 10 * batchSize, cases.Gradient);
2829

30+
// 120M
2931
Console.WriteLine("Finished.");
3032
Console.ReadLine();
3133
}

src/TensorFlowNET.Core/APIs/c_api.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*****************************************************************************
2-
Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
2+
Copyright 2020 Haiping Chen. All Rights Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public partial class tensorflow
2424

2525
public class DataOps
2626
{
27-
public TensorSliceDataset Dataset { get; } = new TensorSliceDataset();
27+
public DatasetManager Dataset { get; } = new DatasetManager();
2828
}
2929
}
3030
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ namespace Tensorflow
2020
{
2121
public partial class tensorflow
2222
{
23-
public GradientTape GradientTape()
24-
=> new GradientTape();
23+
public GradientTape GradientTape(bool persistent = false,
24+
bool watch_accessed_variables = true)
25+
=> new GradientTape(persistent: persistent,
26+
watch_accessed_variables: watch_accessed_variables);
2527

2628
public Tensor[] gradients(Tensor[] ys,
2729
Tensor[] xs,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using NumSharp;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Tensorflow
7+
{
8+
public class DatasetManager
9+
{
10+
public IDatasetV2 from_tensor_slices(NDArray features, NDArray labels)
11+
=> new TensorSliceDataset(features, labels);
12+
}
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Tensorflow
6+
{
7+
public interface IDatasetV2
8+
{
9+
10+
}
11+
}

src/TensorFlowNET.Core/Data/TensorSliceDataset.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55

66
namespace Tensorflow
77
{
8-
public class TensorSliceDataset
8+
public class TensorSliceDataset : IDatasetV2
99
{
10-
public TensorSliceDataset(params NDArray[] elements)
11-
{
12-
13-
}
10+
NDArray features;
11+
NDArray labels;
1412

15-
public TensorSliceDataset from_tensor_slices(params NDArray[] elements)
13+
public TensorSliceDataset(NDArray features, NDArray labels)
1614
{
17-
throw new NotImplementedException("");
15+
this.features = features;
16+
this.labels = labels;
1817
}
1918
}
2019
}

src/TensorFlowNET.Core/Eager/Context.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,30 @@ public Context(ContextOptions opts, Status status)
1818
status.Check(true);
1919
}
2020

21+
/// <summary>
22+
/// Initialize handle and devices if not already done so.
23+
/// </summary>
2124
public void ensure_initialized()
2225
{
2326
if (_initialized)
2427
return;
2528
_initialized = true;
2629
}
2730

31+
public void start_step()
32+
=> c_api.TFE_ContextStartStep(_handle);
33+
34+
public void end_step()
35+
=> c_api.TFE_ContextEndStep(_handle);
36+
2837
/// <summary>
2938
/// Dispose any unmanaged resources related to given <paramref name="handle"/>.
3039
/// </summary>
3140
protected sealed override void DisposeUnmanagedResources(IntPtr handle)
3241
=> c_api.TFE_DeleteContext(_handle);
3342

34-
35-
public bool executing_eagerly() => true;
43+
public bool executing_eagerly()
44+
=> default_execution_mode == EAGER_MODE;
3645

3746
public string shared_name(string name = null)
3847
=> !string.IsNullOrEmpty(name) || !executing_eagerly() ?

src/TensorFlowNET.Core/Eager/EagerOperation.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,19 @@ namespace Tensorflow.Eager
88
{
99
public class EagerOperation : Operation
1010
{
11-
static Dictionary<string, OpDef> op_dict;
1211
public string Name { get; set; }
1312
public new int NumInputs;
1413
public IntPtr[] InputHandles { get; set; }
1514
public Tensor[] Inputs { get; set; }
1615
public new int NumOutputs;
1716
public IntPtr[] OutputHandles { get; set; }
1817
public Tensor[] Outputs { get; set; }
19-
public BindingArray SkipInputIndicesArray { get; set; }
20-
public unsafe int[] SkipInputIndices => SkipInputIndicesArray.Data.Select(x => *(int*) x).ToArray();
21-
public string[] AttrsArray { get; set; }
18+
public long[] SkipInputIndices { get; set; }
19+
public object[] Attrs { get; set; }
2220

2321
public EagerOperation() : base(IntPtr.Zero)
2422
{
25-
if (op_dict == null)
26-
op_dict = op_def_registry.get_registered_ops();
23+
2724
}
2825

2926
public override InputList inputs
@@ -72,9 +69,9 @@ public override object get_attr(string attr_name)
7269

7370
public bool get_attr_bool(string attr_name)
7471
{
75-
for (int i = 0; i < AttrsArray.Length; i = i + 2)
76-
if (AttrsArray[i] == attr_name)
77-
return AttrsArray[i + 1] == "1";
72+
for (int i = 0; i < Attrs.Length; i = i + 2)
73+
if (Attrs[i].Equals(attr_name))
74+
return Attrs[i + 1].Equals("1");
7875

7976
throw new ValueError($"Can't find attr: {attr_name}");
8077
}

0 commit comments

Comments
 (0)