| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 68df1b7 commit 436afe9
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | - using System; | ||
| 1 | + using NumSharp; | ||
| 2 | + using System; | ||
| 2 | 3 | using System.Collections.Generic; | |
| 3 | 4 | using System.Text; | |
| 4 | 5 | using Tensorflow.Data; | |
@@ -7,6 +8,20 @@ namespace Tensorflow | |||
| 7 | 8 | { | |
| 8 | 9 | public class DatasetManager | |
| 9 | 10 | { | |
| 11 | + public IDatasetV2 from_generator<T>(IEnumerable<T> generator, TF_DataType[] output_types, TensorShape[] output_shapes) | ||
| 12 | + => new GeneratorDataset(); | ||
| 13 | + | ||
| 14 | + /// <summary> | ||
| 15 | + /// Creates a `Dataset` with a single element, comprising the given tensors. | ||
| 16 | + /// </summary> | ||
| 17 | + /// <param name="tensors"></param> | ||
| 18 | + /// <returns></returns> | ||
| 19 | + public IDatasetV2 from_tensor(NDArray tensors) | ||
| 20 | + => new TensorDataset(tensors); | ||
| 21 | + | ||
| 22 | + public IDatasetV2 from_tensor(Tensor tensors) | ||
| 23 | + => new TensorDataset(tensors); | ||
| 24 | + | ||
| 10 | 25 | public IDatasetV2 from_tensor_slices(Tensor features, Tensor labels) | |
| 11 | 26 | => new TensorSliceDataset(features, labels); | |
| 12 | 27 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Text; | ||
| 4 | + | ||
| 5 | + namespace Tensorflow.Data | ||
| 6 | + { | ||
| 7 | + public class GeneratorDataset : DatasetSource | ||
| 8 | + { | ||
| 9 | + | ||
| 10 | + } | ||
| 11 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + using NumSharp; | ||
| 2 | + using System; | ||
| 3 | + using System.Collections.Generic; | ||
| 4 | + using System.Linq; | ||
| 5 | + using System.Text; | ||
| 6 | + using static Tensorflow.Binding; | ||
| 7 | + | ||
| 8 | + namespace Tensorflow | ||
| 9 | + { | ||
| 10 | + /// <summary> | ||
| 11 | + /// A `Dataset` with a single element. | ||
| 12 | + /// </summary> | ||
| 13 | + public class TensorDataset : DatasetSource | ||
| 14 | + { | ||
| 15 | + public TensorDataset(Tensor element) | ||
| 16 | + { | ||
| 17 | + _tensors = new[] { element }; | ||
| 18 | + var batched_spec = _tensors.Select(x => x.ToTensorSpec()).ToArray(); | ||
| 19 | + structure = batched_spec.Select(x => x._unbatch()).ToArray(); | ||
| 20 | + | ||
| 21 | + variant_tensor = ops.tensor_dataset(_tensors, output_shapes); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public TensorDataset(NDArray element) | ||
| 25 | + { | ||
| 26 | + _tensors = new[] { tf.convert_to_tensor(element) }; | ||
| 27 | + var batched_spec = _tensors.Select(x => x.ToTensorSpec()).ToArray(); | ||
| 28 | + structure = batched_spec.ToArray(); | ||
| 29 | + | ||
| 30 | + variant_tensor = ops.tensor_dataset(_tensors, output_shapes); | ||
| 31 | + } | ||
| 32 | + } | ||
| 33 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,24 @@ namespace Tensorflow | |||
| 8 | 8 | { | |
| 9 | 9 | public class dataset_ops | |
| 10 | 10 | { | |
| 11 | + public Tensor tensor_dataset(Tensor[] components, TensorShape[] output_shapes, string name = null) | ||
| 12 | + { | ||
| 13 | + if (tf.Context.executing_eagerly()) | ||
| 14 | + { | ||
| 15 | + var results = tf.Runner.TFE_FastPathExecute(tf.Context, tf.Context.DeviceName, | ||
| 16 | + "TensorDataset", name, | ||
| 17 | + null, | ||
| 18 | + new object[] | ||
| 19 | + { | ||
| 20 | + components, | ||
| 21 | + "output_shapes", output_shapes | ||
| 22 | + }); | ||
| 23 | + return results[0]; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + throw new NotImplementedException(""); | ||
| 27 | + } | ||
| 28 | + | ||
| 11 | 29 | /// <summary> | |
| 12 | 30 | /// Creates a dataset that emits each dim-0 slice of `components` once. | |
| 13 | 31 | /// </summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,9 @@ | |||
| 1 | 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; | |
| 2 | 2 | using System; | |
| 3 | 3 | using System.Collections.Generic; | |
| 4 | + using System.Linq; | ||
| 4 | 5 | using System.Text; | |
| 6 | + using Tensorflow.Keras; | ||
| 5 | 7 | using Tensorflow.UnitTest; | |
| 6 | 8 | using static Tensorflow.Binding; | |
| 7 | 9 | ||
@@ -62,6 +64,21 @@ public void FromTensorSlices() | |||
| 62 | 64 | Assert.AreEqual(5, n); | |
| 63 | 65 | } | |
| 64 | 66 | ||
| 67 | + [TestMethod] | ||
| 68 | + public void FromTensor() | ||
| 69 | + { | ||
| 70 | + var X = new[] { 2013, 2014, 2015, 2016, 2017 }; | ||
| 71 | + | ||
| 72 | + var dataset = tf.data.Dataset.from_tensor(X); | ||
| 73 | + int n = 0; | ||
| 74 | + foreach (var x in dataset) | ||
| 75 | + { | ||
| 76 | + Assert.IsTrue(X.SequenceEqual(x.Item1.ToArray<int>())); | ||
| 77 | + n += 1; | ||
| 78 | + } | ||
| 79 | + Assert.AreEqual(1, n); | ||
| 80 | + } | ||
| 81 | + | ||
| 65 | 82 | [TestMethod] | |
| 66 | 83 | public void Shard() | |
| 67 | 84 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments