Skip to content

Commit a6b4b5d

Browse files
committed
solve conflict
2 parents 4b6b9f8 + 031670b commit a6b4b5d

12 files changed

Lines changed: 211 additions & 24 deletions

File tree

TensorFlow.NET.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Utility", "sr
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Visualization", "TensorFlowNET.Visualization\TensorFlowNET.Visualization.csproj", "{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}"
1515
EndProject
16-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KerasNET.Core", "..\Keras.NET\src\KerasNET.Core\KerasNET.Core.csproj", "{E2F0C39C-D706-4CF5-AE00-81FB447F949D}"
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{0AB4662E-7E3C-455F-BF0C-23D56CBE74F3}"
1717
EndProject
1818
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{62360571-D1F7-473C-B81F-F03CA59E37DD}"
1919
EndProject
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Tensorflow.Keras;
5+
using Tensorflow.Keras.Engine;
6+
7+
namespace Tensorflow
8+
{
9+
public static partial class keras
10+
{
11+
public static Preprocessing preprocessing => new Preprocessing();
12+
public static Sequence sequence = new Sequence();
13+
public static Sequential Sequential() => new Sequential();
14+
}
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Tensorflow.Keras.Engine
6+
{
7+
/// <summary>
8+
/// Base layer class.
9+
/// A layer is a class implementing common neural networks operations, such
10+
/// as convolution, batch norm, etc. These operations require managing weights,
11+
/// losses, updates, and inter-layer connectivity.
12+
/// </summary>
13+
public class Layer : CheckpointableBase
14+
{
15+
16+
}
17+
}
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.Keras.Engine
6+
{
7+
internal class Model : Network
8+
{
9+
}
10+
}
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.Keras.Engine
6+
{
7+
public class Network : Layer
8+
{
9+
}
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Tensorflow.Keras.Engine
6+
{
7+
public class Sequential : Network, IPython
8+
{
9+
public void Dispose()
10+
{
11+
throw new NotImplementedException();
12+
}
13+
14+
public void __enter__()
15+
{
16+
throw new NotImplementedException();
17+
}
18+
19+
public void __exit__()
20+
{
21+
throw new NotImplementedException();
22+
}
23+
}
24+
}
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.Keras
6+
{
7+
public class Preprocessing
8+
{
9+
public Sequence sequence => new Sequence();
10+
}
11+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using NumSharp.Core;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Text.RegularExpressions;
7+
using System.Threading.Tasks;
8+
9+
namespace Tensorflow.Keras
10+
{
11+
public class Sequence
12+
{
13+
/// <summary>
14+
/// Pads sequences to the same length.
15+
/// https://keras.io/preprocessing/sequence/
16+
/// https://faroit.github.io/keras-docs/1.2.0/preprocessing/sequence/
17+
/// </summary>
18+
/// <param name="sequences">List of lists, where each element is a sequence.</param>
19+
/// <param name="maxlen">Int, maximum length of all sequences.</param>
20+
/// <param name="dtype">Type of the output sequences.</param>
21+
/// <param name="padding">String, 'pre' or 'post':</param>
22+
/// <param name="truncating">String, 'pre' or 'post'</param>
23+
/// <param name="value">Float or String, padding value.</param>
24+
/// <returns></returns>
25+
public NDArray pad_sequences(NDArray sequences,
26+
int? maxlen = null,
27+
string dtype = "int32",
28+
string padding = "pre",
29+
string truncating = "pre",
30+
object value = null)
31+
{
32+
int[] length = new int[sequences.size];
33+
switch (sequences.dtype.Name)
34+
{
35+
case "Object":
36+
for (int i = 0; i < sequences.size; i++)
37+
{
38+
switch (sequences.Data<object>(i))
39+
{
40+
case string data:
41+
length[i] = Regex.Matches(data, ",").Count;
42+
break;
43+
}
44+
}
45+
break;
46+
case "Int32":
47+
for (int i = 0; i < sequences.size; i++)
48+
length[i] = Regex.Matches(sequences.Data<object>(i).ToString(), ",").Count;
49+
break;
50+
default:
51+
throw new NotImplementedException($"pad_sequences: {sequences.dtype.Name}");
52+
}
53+
54+
if (maxlen == null)
55+
maxlen = length.Max();
56+
57+
if (value == null)
58+
value = 0f;
59+
60+
var nd = new NDArray(np.int32, new Shape(sequences.size, maxlen.Value));
61+
for (int i = 0; i < nd.shape[0]; i++)
62+
{
63+
switch(sequences[i])
64+
{
65+
case int[] data:
66+
for (int j = 0; j < nd.shape[1]; j++)
67+
nd[i, j] = j < data.Length ? data[j] : value;
68+
break;
69+
default:
70+
throw new NotImplementedException("pad_sequences");
71+
}
72+
}
73+
74+
return nd;
75+
}
76+
}
77+
}

src/TensorFlowNET.Core/TensorFlowNET.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Docs: https://tensorflownet.readthedocs.io</Description>
5252
</ItemGroup>
5353

5454
<ItemGroup>
55-
<Folder Include="APIs\Keras\" />
55+
<ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" />
5656
</ItemGroup>
5757

5858
<ItemGroup>
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 CheckpointableBase
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)