Skip to content

Commit

Permalink
- Starting to add operator overloads to the Tensor class;
Browse files Browse the repository at this point in the history
- Updating Accord libraries to latest pre-release (3.6.4-alpha);
- Updating sessions / backend instances to be thread-local so unit tests can be run in parallel;
- Updating TensorFlowBackend to follow the Keras' Python counterpart more closely;
- Miscellaneous fixes to make GH-3 pass:

Fixes GH-3: Make the first example for a Dense layer pass.
  • Loading branch information
cesarsouza committed Aug 13, 2017
1 parent e344b34 commit 996b0af
Show file tree
Hide file tree
Showing 16 changed files with 305 additions and 149 deletions.
41 changes: 22 additions & 19 deletions Sources/Backends/Base/IBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public interface IBackend : IDisposable
TFDataType floatx();

Tensor greater_equal(Tensor w, double v);

void clear_session();
Tensor cast(object v1, object v2);

Tensor dropout(object p, double retain_prob, object noise_shape, object seed);
Expand All @@ -75,7 +75,23 @@ public interface IBackend : IDisposable

Tensor hard_sigmoid(Tensor x);

Tensor mul(double scale, Tensor tensor);


Tensor mul<T>(T a, Tensor b);

Tensor mul<T>(Tensor a, T b);

Tensor mul(List<Tensor> batch_outs, int length);



Tensor add(Tensor a, Tensor b);

Tensor add<T>(Tensor a, T b);

Tensor add<T>(T a, Tensor b);



Tensor elu(Tensor x, double alpha);

Expand All @@ -95,13 +111,13 @@ public interface IBackend : IDisposable

object eval(Tensor tensor);

Tensor add(Tensor desired, Tensor v);


Tensor mul(Tensor w, Tensor tensor);

Tensor clip(Tensor norms, double min_value, double max_value);

Tensor add(double v, Tensor tensor);


Tensor random_uniform(int?[] shape, double minvalue = 0.0, double maxvalue = 1.0, TFDataType dtype = Utils.DEFAULT_DTYPE, int? seed = null, string name = null);

Expand All @@ -113,8 +129,6 @@ public interface IBackend : IDisposable

Tensor mean(Tensor tensor, int axis);

Tensor const_(int v);

Tensor abs(Tensor input);

Tensor categorical_crossentropy(Tensor expected, Tensor actual);
Expand All @@ -131,7 +145,7 @@ public interface IBackend : IDisposable

double subtract(double v, Tensor expected);

Tensor add(object v1, double v2);


Tensor variable(Array array, string name = null);

Expand All @@ -143,7 +157,7 @@ public interface IBackend : IDisposable

TFDataType? dtype(Tensor input_tensor);

Tensor constant<T>(T value, int?[] shape, TFDataType dtype = Utils.DEFAULT_DTYPE, string name = null);
Tensor constant<T>(T value, int?[] shape = null, TFDataType? dtype = null, string name = null);

int get_uid(string prefix);

Expand Down Expand Up @@ -180,12 +194,8 @@ public interface IBackend : IDisposable

Tensor placeholder(int ndim, string name);

Tensor mul(double rate, Tensor tensor1, Tensor tensor2);

Tensor add(Tensor tensor);

Tensor mul(double rate, double v, Tensor tensor);

object get_variable_shape(Tensor p);

Tensor get_variable_shape(object s);
Expand All @@ -198,26 +208,19 @@ public interface IBackend : IDisposable

Tensor add(object total_loss, object v);

Tensor const_(double v);

object learning_phase();

Function function(object inputs, List<Tensor> list, Func<List<List<Tensor>>> updates, string name);

Function function(object inputs, List<Tensor> list, List<List<Tensor>> updates, string name);

Tensor mul(Tensor momentum, object v);

Function function<TSource>(List<Tensor> inputs, List<object> list, List<TSource> updates, string name);

Function function(List<Tensor> inputs, List<object> list, Func<List<object>> updates, string name);

Tensor update(object m, object v);

double mul(Tensor batch_out, int length);

Tensor mul(List<Tensor> batch_outs, int length);

Tensor div(Tensor tensor, int samples);

Tensor truncated_normal(int[] shape, double v, double stddev, TFDataType dtype, int? seed);
Expand Down
8 changes: 7 additions & 1 deletion Sources/Backends/Current.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ namespace KerasSharp.Backends
using System.Text;
using System.Threading.Tasks;
using KerasSharp.Engine.Topology;
using System.Threading;

public static class Current
{

public static IBackend K { get; set; } = new TensorFlowBackend();
private static ThreadLocal<IBackend> backend = new ThreadLocal<IBackend>(() => new TensorFlowBackend());

public static IBackend K
{
get { return backend.Value; }
set { backend.Value = value; }
}
}
}
Loading

0 comments on commit 996b0af

Please sign in to comment.