| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 400cde2 commit fd64ad1
21 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,12 +26,12 @@ In comparison to other projects, like for instance [TensorFlowSharp](https://www | |||
| 26 | 26 | ||
| 27 | 27 | ### How to use | |
| 28 | 28 | ||
| 29 | - | TensorFlow | tf native1.14 | tf native 1.15 | tf native 2.3 | | ||
| 30 | - | -------------------------- | ------------- | -------------- | ------------- | | ||
| 31 | - | tf.net 0.3x, tf.keras 0.2 | | | x | | ||
| 32 | - | tf.net 0.2x | | x | x | | ||
| 33 | - | tf.net 0.15 | x | x | | | ||
| 34 | - | tf.net 0.14 | x | | | | ||
| 29 | + | TensorFlow | tf native1.14, cuda 10.0 | tf native 1.15, cuda 10.0 | tf native 2.3, cuda 10.1 | tf native 2.4, cuda 11 | | ||
| 30 | + | -------------------------- | ------------- | -------------- | ------------- | ------------- | | ||
| 31 | + | tf.net 0.3x, tf.keras 0.2 | | | x | not compatible | | ||
| 32 | + | tf.net 0.2x | | x | x | | | ||
| 33 | + | tf.net 0.15 | x | x | | | | ||
| 34 | + | tf.net 0.14 | x | | | | | ||
| 35 | 35 | ||
| 36 | 36 | Troubleshooting of running example or installation, please refer [here](tensorflowlib/README.md). | |
| 37 | 37 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,11 +22,19 @@ https://www.nuget.org/packages/SciSharp.TensorFlow.Redist | |||
| 22 | 22 | ||
| 23 | 23 | Related merged [commits](https://github.com/SciSharp/TensorFlow.NET/commit/854a5ba61ad0e400623821236bd117cc24c6cb77). | |
| 24 | 24 | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + #### Download pre-build package | ||
| 28 | + | ||
| 29 | + [Mac OSX CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-2.4.0.tar.gz), [Linux CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.4.0.tar.gz), [Linux GPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.4.0.tar.gz), [Windows CPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-2.4.0.tar.gz), [Windows GPU](https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-2.4.0.zip) | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + | ||
| 25 | 33 | #### Pack and Deploy #### | |
| 26 | 34 | ||
| 27 | 35 | On Windows, the tar command does not support extracting archives with symlinks. So when `dotnet pack` runs on Windows it will only package the Windows binaries. | |
| 28 | 36 | ||
| 29 | 37 | 1. Run `dotnet pack SciSharp.TensorFlow.Redist.nupkgproj` under `src/SciSharp.TensorFlow.Redist` directory in Linux. | |
| 30 | - 2. Run `dotnet nuget push SciSharp.TensorFlow.Redist.2.3.1.nupkg -k APIKEY -s https://api.nuget.org/v3/index.json -t 600` | ||
| 38 | + 2. Run `dotnet nuget push SciSharp.TensorFlow.Redist.2.4.0.nupkg -k APIKEY -s https://api.nuget.org/v3/index.json -t 600` | ||
| 31 | 39 | ||
| 32 | 40 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ | |||
| 8 | 8 | </PropertyGroup> | |
| 9 | 9 | ||
| 10 | 10 | <ItemGroup> | |
| 11 | - <PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.3.0" /> | ||
| 11 | + <PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.3.1" /> | ||
| 12 | 12 | </ItemGroup> | |
| 13 | 13 | ||
| 14 | 14 | <ItemGroup> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -574,7 +574,7 @@ public static string to_numpy_string(Tensor tensor) | |||
| 574 | 574 | return string.Join(string.Empty, nd.ToArray<byte>() | |
| 575 | 575 | .Select(x => x < 32 || x > 127 ? "\\x" + x.ToString("x") : Convert.ToChar(x).ToString())); | |
| 576 | 576 | case TF_DataType.TF_BOOL: | |
| 577 | - return (nd.GetByte(0) > 0).ToString(); | ||
| 577 | + return nd.GetBoolean(0).ToString(); | ||
| 578 | 578 | case TF_DataType.TF_VARIANT: | |
| 579 | 579 | case TF_DataType.TF_RESOURCE: | |
| 580 | 580 | return "<unprintable>"; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,19 +37,38 @@ public DataHandler(DataHandlerArgs args) | |||
| 37 | 37 | _steps_per_execution_value = args.StepsPerExecution.numpy(); | |
| 38 | 38 | } | |
| 39 | 39 | ||
| 40 | - _adapter = new TensorLikeDataAdapter(new TensorLikeDataAdapterArgs | ||
| 40 | + if(args.Dataset == null) | ||
| 41 | 41 | { | |
| 42 | - X = args.X, | ||
| 43 | - Y = args.Y, | ||
| 44 | - BatchSize = args.BatchSize, | ||
| 45 | - Steps = args.StepsPerEpoch, | ||
| 46 | - Epochs = args.Epochs - args.InitialEpoch, | ||
| 47 | - Shuffle = args.Shuffle, | ||
| 48 | - MaxQueueSize = args.MaxQueueSize, | ||
| 49 | - Worker = args.Workers, | ||
| 50 | - UseMultiprocessing = args.UseMultiprocessing, | ||
| 51 | - Model = args.Model | ||
| 52 | - }); | ||
| 42 | + _adapter = new TensorLikeDataAdapter(new DataAdapterArgs | ||
| 43 | + { | ||
| 44 | + X = args.X, | ||
| 45 | + Y = args.Y, | ||
| 46 | + BatchSize = args.BatchSize, | ||
| 47 | + Steps = args.StepsPerEpoch, | ||
| 48 | + Epochs = args.Epochs - args.InitialEpoch, | ||
| 49 | + Shuffle = args.Shuffle, | ||
| 50 | + MaxQueueSize = args.MaxQueueSize, | ||
| 51 | + Worker = args.Workers, | ||
| 52 | + UseMultiprocessing = args.UseMultiprocessing, | ||
| 53 | + Model = args.Model | ||
| 54 | + }); | ||
| 55 | + } | ||
| 56 | + else | ||
| 57 | + { | ||
| 58 | + _adapter = new DatasetAdapter(new DataAdapterArgs | ||
| 59 | + { | ||
| 60 | + Dataset = args.Dataset, | ||
| 61 | + BatchSize = args.BatchSize, | ||
| 62 | + Steps = args.StepsPerEpoch, | ||
| 63 | + Epochs = args.Epochs - args.InitialEpoch, | ||
| 64 | + Shuffle = args.Shuffle, | ||
| 65 | + MaxQueueSize = args.MaxQueueSize, | ||
| 66 | + Worker = args.Workers, | ||
| 67 | + UseMultiprocessing = args.UseMultiprocessing, | ||
| 68 | + Model = args.Model | ||
| 69 | + }); | ||
| 70 | + } | ||
| 71 | + | ||
| 53 | 72 | _dataset = _adapter.GetDataset(); | |
| 54 | 73 | _inferred_steps = _infer_steps(args.StepsPerEpoch, _dataset); | |
| 55 | 74 | _current_step = 0; | |
@@ -66,7 +85,8 @@ int _infer_steps(int steps_per_epoch, IDatasetV2 dataset) | |||
| 66 | 85 | if (adapter_steps > -1) | |
| 67 | 86 | return adapter_steps; | |
| 68 | 87 | ||
| 69 | - throw new NotImplementedException(""); | ||
| 88 | + var size = dataset.dataset_cardinality(); | ||
| 89 | + return size.numpy(); | ||
| 70 | 90 | } | |
| 71 | 91 | ||
| 72 | 92 | public IEnumerable<(int, OwnedIterator)> enumerate_epochs() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,35 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Text; | ||
| 4 | + using Tensorflow.Keras.ArgsDefinition; | ||
| 5 | + | ||
| 6 | + namespace Tensorflow.Keras.Engine.DataAdapters | ||
| 7 | + { | ||
| 8 | + public class DatasetAdapter : IDataAdapter | ||
| 9 | + { | ||
| 10 | + DataAdapterArgs args; | ||
| 11 | + IDatasetV2 _dataset => args.Dataset; | ||
| 12 | + public DatasetAdapter(DataAdapterArgs args) | ||
| 13 | + { | ||
| 14 | + this.args = args; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public bool CanHandle(Tensor x, Tensor y = null) | ||
| 18 | + { | ||
| 19 | + throw new NotImplementedException(); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public IDatasetV2 GetDataset() | ||
| 23 | + => _dataset; | ||
| 24 | + | ||
| 25 | + public int GetSize() | ||
| 26 | + => -1; | ||
| 27 | + | ||
| 28 | + public (Tensor, Tensor) Expand1d(Tensor x, Tensor y) | ||
| 29 | + { | ||
| 30 | + if (y.TensorShape.ndim == 1) | ||
| 31 | + y = array_ops.expand_dims(y, axis: -1); | ||
| 32 | + return (x, y); | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,14 +9,14 @@ namespace Tensorflow.Keras.Engine.DataAdapters | |||
| 9 | 9 | /// </summary> | |
| 10 | 10 | public class TensorLikeDataAdapter : IDataAdapter | |
| 11 | 11 | { | |
| 12 | - TensorLikeDataAdapterArgs args; | ||
| 12 | + DataAdapterArgs args; | ||
| 13 | 13 | int _size; | |
| 14 | 14 | int _batch_size; | |
| 15 | 15 | int num_samples; | |
| 16 | 16 | int num_full_batches; | |
| 17 | 17 | IDatasetV2 _dataset; | |
| 18 | 18 | ||
| 19 | - public TensorLikeDataAdapter(TensorLikeDataAdapterArgs args) | ||
| 19 | + public TensorLikeDataAdapter(DataAdapterArgs args) | ||
| 20 | 20 | { | |
| 21 | 21 | this.args = args; | |
| 22 | 22 | _process_tensorlike(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,10 +39,12 @@ public Functional(Tensors inputs, Tensors outputs, string name = null) | |||
| 39 | 39 | _input_coordinates = new List<KerasHistory>(); | |
| 40 | 40 | _output_coordinates = new List<KerasHistory>(); | |
| 41 | 41 | tensor_usage_count = new Dictionary<int, int>(); | |
| 42 | + if (this is Sequential) | ||
| 43 | + return; | ||
| 42 | 44 | _init_graph_network(inputs, outputs); | |
| 43 | 45 | } | |
| 44 | 46 | ||
| 45 | - void _init_graph_network(Tensors inputs, Tensors outputs) | ||
| 47 | + protected void _init_graph_network(Tensors inputs, Tensors outputs) | ||
| 46 | 48 | { | |
| 47 | 49 | _is_graph_network = true; | |
| 48 | 50 | this.inputs = inputs; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,10 +9,6 @@ public partial class Model | |||
| 9 | 9 | { | |
| 10 | 10 | LossesContainer compiled_loss; | |
| 11 | 11 | MetricsContainer compiled_metrics; | |
| 12 | - public void compile(string optimizerName, ILossFunc lossName) | ||
| 13 | - { | ||
| 14 | - throw new NotImplementedException(""); | ||
| 15 | - } | ||
| 16 | 12 | ||
| 17 | 13 | public void compile(ILossFunc loss, OptimizerV2 optimizer, string[] metrics) | |
| 18 | 14 | { | |
@@ -29,12 +25,12 @@ public void compile(ILossFunc loss, OptimizerV2 optimizer, string[] metrics) | |||
| 29 | 25 | this.loss = loss; | |
| 30 | 26 | } | |
| 31 | 27 | ||
| 32 | - public void compile(string optimizerName, string lossName) | ||
| 28 | + public void compile(string optimizer, string loss, string[] metrics) | ||
| 33 | 29 | { | |
| 34 | - switch (optimizerName) | ||
| 30 | + switch (optimizer) | ||
| 35 | 31 | { | |
| 36 | 32 | case "rmsprop": | |
| 37 | - optimizer = new RMSprop(new RMSpropArgs | ||
| 33 | + this.optimizer = new RMSprop(new RMSpropArgs | ||
| 38 | 34 | { | |
| 39 | 35 | ||
| 40 | 36 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,5 +68,49 @@ public void fit(NDArray x, NDArray y, | |||
| 68 | 68 | Console.WriteLine($"epoch: {epoch + 1}, " + string.Join(", ", results.Select(x => $"{x.Item1}: {(float)x.Item2}"))); | |
| 69 | 69 | } | |
| 70 | 70 | } | |
| 71 | + | ||
| 72 | + public void fit(IDatasetV2 dataset, | ||
| 73 | + IDatasetV2 validation_data = null, | ||
| 74 | + int batch_size = -1, | ||
| 75 | + int epochs = 1, | ||
| 76 | + int verbose = 1, | ||
| 77 | + float validation_split = 0f, | ||
| 78 | + bool shuffle = true, | ||
| 79 | + int initial_epoch = 0, | ||
| 80 | + int max_queue_size = 10, | ||
| 81 | + int workers = 1, | ||
| 82 | + bool use_multiprocessing = false) | ||
| 83 | + { | ||
| 84 | + data_handler = new DataHandler(new DataHandlerArgs | ||
| 85 | + { | ||
| 86 | + Dataset = dataset, | ||
| 87 | + BatchSize = batch_size, | ||
| 88 | + InitialEpoch = initial_epoch, | ||
| 89 | + Epochs = epochs, | ||
| 90 | + Shuffle = shuffle, | ||
| 91 | + MaxQueueSize = max_queue_size, | ||
| 92 | + Workers = workers, | ||
| 93 | + UseMultiprocessing = use_multiprocessing, | ||
| 94 | + Model = this, | ||
| 95 | + StepsPerExecution = _steps_per_execution | ||
| 96 | + }); | ||
| 97 | + | ||
| 98 | + stop_training = false; | ||
| 99 | + _train_counter.assign(0); | ||
| 100 | + Console.WriteLine($"Training..."); | ||
| 101 | + foreach (var (epoch, iterator) in data_handler.enumerate_epochs()) | ||
| 102 | + { | ||
| 103 | + // reset_metrics(); | ||
| 104 | + // callbacks.on_epoch_begin(epoch) | ||
| 105 | + // data_handler.catch_stop_iteration(); | ||
| 106 | + IEnumerable<(string, Tensor)> results = null; | ||
| 107 | + foreach (var step in data_handler.steps()) | ||
| 108 | + { | ||
| 109 | + // callbacks.on_train_batch_begin(step) | ||
| 110 | + results = step_function(iterator); | ||
| 111 | + } | ||
| 112 | + Console.WriteLine($"epoch: {epoch + 1}, " + string.Join(", ", results.Select(x => $"{x.Item1}: {(float)x.Item2}"))); | ||
| 113 | + } | ||
| 114 | + } | ||
| 71 | 115 | } | |
| 72 | 116 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments