diff --git a/src/TensorFlowNET.Keras/Engine/BaseLayer.cs b/src/TensorFlowNET.Keras/Engine/BaseLayer.cs index 35f65357..36c69843 100644 --- a/src/TensorFlowNET.Keras/Engine/BaseLayer.cs +++ b/src/TensorFlowNET.Keras/Engine/BaseLayer.cs @@ -1,10 +1,73 @@ -using System; +using Keras.Layers; +using NumSharp; +using System; using System.Collections.Generic; using System.Text; namespace Tensorflow.Keras.Engine { - public class Layer + public class TensorFlowOpLayer : Layer { + public TensorFlowOpLayer(string node_def, string name, NDArray[] constants = null, bool trainable = true, string dtype = null) + { + + } + + public override void call(Tensor[] inputs) + { + throw new NotImplementedException(); + } + + public override Dictionary get_config() + { + throw new NotImplementedException(); + } + + private NodeDef _make_node_def(Graph graph) => throw new NotImplementedException(); + + private Tensor[] _make_op(Tensor[] inputs) => throw new NotImplementedException(); + + private Tensor[] _defun_call(Tensor[] inputs) => throw new NotImplementedException(); + } + + public class AddLoss : Layer + { + public AddLoss(bool unconditional) + { + throw new NotImplementedException(); + } + + public override void call(Tensor[] inputs) + { + throw new NotImplementedException(); + } + + public override Dictionary get_config() + { + throw new NotImplementedException(); + } + } + + public class AddMetric : Layer + { + public AddMetric(string aggregation = null, string metric_name = null) + { + throw new NotImplementedException(); + } + + public override void call(Tensor[] inputs) + { + throw new NotImplementedException(); + } + + public override Dictionary get_config() + { + throw new NotImplementedException(); + } + } + + public class KerasHistory + { + } } diff --git a/src/TensorFlowNET.Keras/Engine/BaseLayerUtils.cs b/src/TensorFlowNET.Keras/Engine/BaseLayerUtils.cs index 914aee71..323e9819 100644 --- a/src/TensorFlowNET.Keras/Engine/BaseLayerUtils.cs +++ b/src/TensorFlowNET.Keras/Engine/BaseLayerUtils.cs @@ -1,4 +1,5 @@ -using System; +using Keras.Layers; +using System; using System.Collections.Generic; using System.Text; using Tensorflow.Keras.Initializers; @@ -20,5 +21,25 @@ namespace Tensorflow.Keras.Engine public bool have_all_keras_metadata(Tensor[] tensors) => throw new NotImplementedException(); public static dynamic generate_placeholders_from_shape(TensorShape shape) => throw new NotImplementedException(); + + public Layer[] create_keras_history(Tensor[] tensors) => throw new NotImplementedException(); + + private void _create_keras_history_helper(Tensor[] tensors, TensorFlowOpLayer[] processed_ops, Layer[] created_layers) => throw new NotImplementedException(); + + public Tensor[] unnest_if_single_tensor(Tensor[] input_tensors) => throw new NotImplementedException(); + + public bool needs_keras_history(Tensor[] tensors, bool ignore_call_context= false) => throw new NotImplementedException(); + + public bool is_in_keras_graph() => throw new NotImplementedException(); + + public string is_in_eager_or_tf_function() => throw new NotImplementedException(); + + public bool is_in_tf_function() => throw new NotImplementedException(); + + public bool uses_keras_history(Tensor[] tensors) => throw new NotImplementedException(); + + public Tensor[] mark_checked(Tensor[] tensors) => throw new NotImplementedException(); + + public CallContext call_context() => throw new NotImplementedException(); } } diff --git a/src/TensorFlowNET.Keras/Engine/BasePreprocessingLayer.cs b/src/TensorFlowNET.Keras/Engine/BasePreprocessingLayer.cs index 6beda9fe..61c57d39 100644 --- a/src/TensorFlowNET.Keras/Engine/BasePreprocessingLayer.cs +++ b/src/TensorFlowNET.Keras/Engine/BasePreprocessingLayer.cs @@ -1,10 +1,58 @@ -using System; +using Keras.Layers; +using NumSharp; +using System; using System.Collections.Generic; using System.Text; +using Tensorflow.Data; +using Tensorflow.Keras.Initializers; namespace Tensorflow.Keras.Engine { - class BasePreprocessingLayer + public abstract class PreprocessingLayer : Layer { + public abstract void adapt(Data.DatasetV1 data, bool reset_state = true); + } + + public abstract class Combiner + { + public abstract dynamic compute(NDArray[] batch_values, dynamic accumulator = null); + + public abstract dynamic merge(dynamic[] accumulators); + + public abstract NDArray[] extract(dynamic accumulator); + + public abstract dynamic restore(Tensor output); + + public abstract string serialize(dynamic accumulator); + + public abstract dynamic deserialize(string encoded_accumulator); + + public override string ToString() + { + throw new NotImplementedException(); + } + } + + public class CombinerPreprocessingLayer : PreprocessingLayer + { + public CombinerPreprocessingLayer(Combiner combiner) + { + throw new NotImplementedException(); + } + + private void _add_state_variable(string name, TensorShape shape, string dtype, Initializer initializer= null, string partitioner= null, bool? use_resource= null) => throw new NotImplementedException(); + + private Dictionary _restore_updates() => throw new NotImplementedException(); + + private bool _dataset_is_infinite(DatasetV1 dataset) => throw new NotImplementedException(); + + private dynamic _get_dataset_iterator(DatasetV1 dataset) => throw new NotImplementedException(); + + private void _set_state_variables(Dictionary updates) => throw new NotImplementedException(); + + public override void adapt(DatasetV1 data, bool reset_state = true) + { + throw new NotImplementedException(); + } } } diff --git a/src/TensorFlowNET.Keras/Engine/CallContext.cs b/src/TensorFlowNET.Keras/Engine/CallContext.cs new file mode 100644 index 00000000..5547c6de --- /dev/null +++ b/src/TensorFlowNET.Keras/Engine/CallContext.cs @@ -0,0 +1,45 @@ +using Keras.Layers; +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; + +namespace Tensorflow.Keras.Engine +{ + public class CallContext + { + public bool in_keras_graph + { + get + { + throw new NotImplementedException(); + } + } + public CallContext() + { + + } + + public void enter(Layer layer, Tensor[] inputs, Graph build_graph, bool training, Saving saving = null) => throw new NotImplementedException(); + + public bool training_arg_passed_to_call(string[] argspec, Dictionary args, Dictionary kwargs) => throw new NotImplementedException(); + + public dynamic autocast_context_manager(string dtype) => throw new NotImplementedException(); + + public bool is_subclassed(Layer layer) => throw new NotImplementedException(); + + public bool from_saved_model(Layer layer) => throw new NotImplementedException(); + + public bool check_graph_consistency(Tensor tensor = null, string method = "add_loss", bool force_raise = false) => throw new NotImplementedException(); + + public dynamic mark_as_return(Tensor[] outputs, dynamic acd) => throw new NotImplementedException(); + + public MethodInfo Default(MemberInfo method) => throw new NotImplementedException(); + + public void enable_v2_dtype_behavior() => throw new NotImplementedException(); + + public void disable_v2_dtype_behavior() => throw new NotImplementedException(); + + public void v2_dtype_behavior_enabled() => throw new NotImplementedException(); + } +} diff --git a/src/TensorFlowNET.Keras/Engine/Saving.cs b/src/TensorFlowNET.Keras/Engine/Saving.cs index 43ba2cf6..8ba804c3 100644 --- a/src/TensorFlowNET.Keras/Engine/Saving.cs +++ b/src/TensorFlowNET.Keras/Engine/Saving.cs @@ -4,7 +4,7 @@ using System.Text; namespace Tensorflow.Keras.Engine { - class Saving + public class Saving { } } diff --git a/src/TensorFlowNET.Keras/Engine/TrackableWeightHandler.cs b/src/TensorFlowNET.Keras/Engine/TrackableWeightHandler.cs new file mode 100644 index 00000000..c6305809 --- /dev/null +++ b/src/TensorFlowNET.Keras/Engine/TrackableWeightHandler.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow.Keras.Engine +{ + public class TrackableWeightHandler + { + public int num_tensors + { + get + { + throw new NotImplementedException(); + } + } + + public TrackableWeightHandler(bool trackable) + { + throw new NotImplementedException(); + } + + public void set_weights(Tensor[] weights) => throw new NotImplementedException(); + + public void _set_weights_v1(Tensor[] weights) => throw new NotImplementedException(); + } +} diff --git a/src/TensorFlowNET.Keras/IInitializer.cs b/src/TensorFlowNET.Keras/IInitializer.cs deleted file mode 100644 index d69e0d1b..00000000 --- a/src/TensorFlowNET.Keras/IInitializer.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Keras -{ - interface IInitializer - { - } -} diff --git a/src/TensorFlowNET.Keras/Layers/Layer.cs b/src/TensorFlowNET.Keras/Layers/Layer.cs index 7e23fd71..eb231fad 100644 --- a/src/TensorFlowNET.Keras/Layers/Layer.cs +++ b/src/TensorFlowNET.Keras/Layers/Layer.cs @@ -1,14 +1,205 @@ -using System; +using NumSharp; +using System; using System.Collections.Generic; using Tensorflow; using Tensorflow.Keras.Constraints; using Tensorflow.Keras.Initializers; +using Tensorflow.Keras.Losses; +using Tensorflow.Keras.Metrics; using Tensorflow.Keras.Regularizers; namespace Keras.Layers { public abstract class Layer { + public TF_DataType dtype + { + get + { + throw new NotImplementedException(); + } + } + + public string name + { + get + { + throw new NotImplementedException(); + } + } + + public bool stateful + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public bool trainable + { + get + { + throw new NotImplementedException(); + } + } + + public Regularizer activity_regularizer + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public dynamic input_spec + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public Tensor[] trainable_weights + { + get + { + throw new NotImplementedException(); + } + } + + public Tensor[] non_trainable_weights + { + get + { + throw new NotImplementedException(); + } + } + + private Tensor[] _weights + { + get + { + throw new NotImplementedException(); + } + } + + public Func[] updates + { + get + { + throw new NotImplementedException(); + } + } + + public Tensor[] losses + { + get + { + throw new NotImplementedException(); + } + } + + public Tensor[] metrics + { + get + { + throw new NotImplementedException(); + } + } + + public Tensor[] input_mask + { + get + { + throw new NotImplementedException(); + } + } + + public Tensor[] output_mask + { + get + { + throw new NotImplementedException(); + } + } + + public Tensor[] input + { + get + { + throw new NotImplementedException(); + } + } + + public Tensor[] output + { + get + { + throw new NotImplementedException(); + } + } + + public TensorShape[] input_shape + { + get + { + throw new NotImplementedException(); + } + } + + public TensorShape[] output_shape + { + get + { + throw new NotImplementedException(); + } + } + + public Tensor[] variables + { + get + { + return _weights; + } + } + + public Tensor[] trainable_variables + { + get + { + return trainable_weights; + } + } + + public Tensor[] non_trainable_variables + { + get + { + return non_trainable_weights; + } + } + + private string _compute_dtype + { + get + { + throw new NotImplementedException(); + } + } + public Layer(bool trainable = true, string name = null, string dtype = null, bool @dynamic = false, Dictionary kwargs = null) { @@ -16,7 +207,7 @@ namespace Keras.Layers public void build(TensorShape shape) => throw new NotImplementedException(); - public void call(Tensor[] inputs) => throw new NotImplementedException(); + public virtual void call(Tensor[] inputs) => throw new NotImplementedException(); public void _add_trackable(dynamic trackable_object, bool trainable) => throw new NotImplementedException(); @@ -25,12 +216,207 @@ namespace Keras.Layers dynamic partitioner= null, bool? use_resource= null, VariableSynchronization synchronization= VariableSynchronization.Auto, VariableAggregation aggregation= VariableAggregation.None, Dictionary kwargs = null) => throw new NotImplementedException(); - public Dictionary get_config() => throw new NotImplementedException(); + public virtual Dictionary get_config() => throw new NotImplementedException(); public Layer from_config(Dictionary config) => throw new NotImplementedException(); public TensorShape compute_output_shape(TensorShape input_shape) => throw new NotImplementedException(); public dynamic compute_output_signature(dynamic input_signature) => throw new NotImplementedException(); - } + + public Tensor[] compute_mask(Tensor[] inputs, Tensor[] mask = null) => throw new NotImplementedException(); + + public void __call__(Tensor[] inputs) => throw new NotImplementedException(); + + public void add_loss(Loss[] losses, Tensor[] inputs = null) => throw new NotImplementedException(); + + public void _clear_losses() => throw new NotImplementedException(); + + public void add_metric(Tensor value, string aggregation= null, string name= null) => throw new NotImplementedException(); + + public void add_update(Func[] updates) => throw new NotImplementedException(); + + public void set_weights(NDArray[] weights) => throw new NotImplementedException(); + + public NDArray[] get_weights() => throw new NotImplementedException(); + + public Func[] get_updates_for(Tensor[] inputs) => throw new NotImplementedException(); + + public Tensor[] get_losses_for(Tensor[] inputs) => throw new NotImplementedException(); + + public Tensor[] get_input_mask_at(int node_index) => throw new NotImplementedException(); + + public Tensor[] get_output_mask_at(int node_index) => throw new NotImplementedException(); + + public TensorShape[] get_input_shape_at(int node_index) => throw new NotImplementedException(); + + public TensorShape[] get_output_shape_at(int node_index) => throw new NotImplementedException(); + + public Tensor[] get_input_at(int node_index) => throw new NotImplementedException(); + + public Tensor[] get_output_at(int node_index) => throw new NotImplementedException(); + + public int count_params() => throw new NotImplementedException(); + + private void _set_dtype_policy(string dtype) => throw new NotImplementedException(); + + private Tensor _maybe_cast_inputs(Tensor inputs) => throw new NotImplementedException(); + + private void _warn_about_input_casting(string input_dtype) => throw new NotImplementedException(); + + private string _name_scope() + { + return name; + } + + private string _obj_reference_counts + { + get + { + throw new NotImplementedException(); + } + } + + private dynamic _attribute_sentinel + { + get + { + throw new NotImplementedException(); + } + } + + private dynamic _call_full_argspec + { + get + { + throw new NotImplementedException(); + } + } + + private string[] _call_fn_args + { + get + { + throw new NotImplementedException(); + } + } + + private string[] _call_accepts_kwargs + { + get + { + throw new NotImplementedException(); + } + } + + private bool _should_compute_mask + { + get + { + throw new NotImplementedException(); + } + } + + private Tensor[] _eager_losses + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + private dynamic _trackable_saved_model_saver + { + get + { + throw new NotImplementedException(); + } + } + + private string _object_identifier + { + get + { + throw new NotImplementedException(); + } + } + + private string _tracking_metadata + { + get + { + throw new NotImplementedException(); + } + } + + public Dictionary state + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + private void _init_set_name(string name, bool zero_based= true) => throw new NotImplementedException(); + + private Metric _get_existing_metric(string name = null) => throw new NotImplementedException(); + + private void _eager_add_metric(Metric value, string aggregation= null, string name= null) => throw new NotImplementedException(); + + private void _symbolic_add_metric(Metric value, string aggregation = null, string name = null) => throw new NotImplementedException(); + + private void _handle_weight_regularization(string name, VariableV1 variable, Regularizer regularizer) => throw new NotImplementedException(); + + private void _handle_activity_regularization(Tensor[] inputs, Tensor[] outputs) => throw new NotImplementedException(); + + private void _set_mask_metadata(Tensor[] inputs, Tensor[] outputs, Tensor previous_mask) => throw new NotImplementedException(); + + private Tensor[] _collect_input_masks(Tensor[] inputs, Dictionary args, Dictionary kwargs) => throw new NotImplementedException(); + + private bool _call_arg_was_passed(string arg_name, Dictionary args, Dictionary kwargs, bool inputs_in_args= false) => throw new NotImplementedException(); + + private T _get_call_arg_value(string arg_name, Dictionary args, Dictionary kwargs, bool inputs_in_args = false) => throw new NotImplementedException(); + + private (Tensor[], Tensor[]) _set_connectivity_metadata_(Tensor[] inputs, Tensor[] outputs, Dictionary args, Dictionary kwargs) => throw new NotImplementedException(); + + private void _add_inbound_node(Tensor[] input_tensors, Tensor[] output_tensors, Dictionary args = null) => throw new NotImplementedException(); + + private AttrValue _get_node_attribute_at_index(int node_index, string attr, string attr_name) => throw new NotImplementedException(); + + private void _maybe_build(Tensor[] inputs) => throw new NotImplementedException(); + + private void _symbolic_call(Tensor[] inputs) => throw new NotImplementedException(); + + private Dictionary _get_trainable_state() => throw new NotImplementedException(); + + private void _set_trainable_state(bool trainable_state) => throw new NotImplementedException(); + + private void _maybe_create_attribute(string name, object default_value) => throw new NotImplementedException(); + + private void __delattr__(string name) => throw new NotImplementedException(); + + private void __setattr__(string name, object value) => throw new NotImplementedException(); + + private List _gather_children_attribute(string attribute) => throw new NotImplementedException(); + + private List _gather_unique_layers() => throw new NotImplementedException(); + + private List _gather_layers() => throw new NotImplementedException(); + + private bool _is_layer() => throw new NotImplementedException(); + + private void _init_call_fn_args() => throw new NotImplementedException(); + + public dynamic _list_extra_dependencies_for_serialization(dynamic serialization_cache) => throw new NotImplementedException(); + + public dynamic _list_functions_for_serialization(dynamic serialization_cache) => throw new NotImplementedException(); + } } diff --git a/src/TensorFlowNET.Keras/Losses/Loss.cs b/src/TensorFlowNET.Keras/Losses/Loss.cs index 55d9b100..49246027 100644 --- a/src/TensorFlowNET.Keras/Losses/Loss.cs +++ b/src/TensorFlowNET.Keras/Losses/Loss.cs @@ -4,7 +4,7 @@ using System.Text; namespace Tensorflow.Keras.Losses { - class Loss + public abstract class Loss { } }