Skip to content

Commit 8cdb4a7

Browse files
committed
Add dataset cardinality test #695
1 parent 06b6055 commit 8cdb4a7

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616

1717
### Why TensorFlow in C# and F# ?
1818

19-
`SciSharp STACK`'s mission is to bring popular data science technology into the .NET world and to provide .NET developers with a powerful Machine Learning tool set without reinventing the wheel. Since the APIs are kept as similar as possible you can immediately adapt any existing Tensorflow code in C# or F# with a zero learning curve. Take a look at a comparison picture and see how comfortably a Tensorflow/Python script translates into a C# program with TensorFlow.NET.
19+
`SciSharp STACK`'s mission is to bring popular data science technology into the .NET world and to provide .NET developers with a powerful Machine Learning tool set without reinventing the wheel. Since the APIs are kept as similar as possible you can immediately adapt any existing TensorFlow code in C# or F# with a zero learning curve. Take a look at a comparison picture and see how comfortably a TensorFlow/Python script translates into a C# program with TensorFlow.NET.
2020

2121
![pythn vs csharp](docs/assets/syntax-comparision.png)
2222

23-
SciSharp's philosophy allows a large number of machine learning code written in Python to be quickly migrated to .NET, enabling .NET developers to use cutting edge machine learning models and access a vast number of Tensorflow resources which would not be possible without this project.
23+
SciSharp's philosophy allows a large number of machine learning code written in Python to be quickly migrated to .NET, enabling .NET developers to use cutting edge machine learning models and access a vast number of TensorFlow resources which would not be possible without this project.
2424

25-
In comparison to other projects, like for instance [TensorFlowSharp](https://www.nuget.org/packages/TensorFlowSharp/) which only provide Tensorflow's low-level C++ API and can only run models that were built using Python, Tensorflow.NET also implements Tensorflow's high level API where all the magic happens. This computation graph building layer is still under active development. Once it is completely implemented you can build new Machine Learning models in C# or F#.
25+
In comparison to other projects, like for instance [TensorFlowSharp](https://www.nuget.org/packages/TensorFlowSharp/) which only provide TensorFlow's low-level C++ API and can only run models that were built using Python, Tensorflow.NET also implements TensorFlow's high level API where all the magic happens. This computation graph building layer is still under active development. Once it is completely implemented you can build new Machine Learning models in C# or F#.
26+
27+
Go through the online docs [TensorFlow for .NET](https://scisharp.github.io/tensorflow-net-docs) before you get started with Machine Learning in .NET.
2628

2729
### How to use
2830

@@ -210,7 +212,7 @@ for step = 1 to (training_steps + 1) do
210212
printfn $"step: {step}, loss: {loss.numpy()}, W: {W.numpy()}, b: {b.numpy()}"
211213
```
212214

213-
Read the docs & book [The Definitive Guide to Tensorflow.NET](https://tensorflownet.readthedocs.io/en/latest/FrontCover.html) if you want to know more about TensorFlow for .NET under the hood.
215+
Read the book [The Definitive Guide to Tensorflow.NET](https://tensorflownet.readthedocs.io/en/latest/FrontCover.html) if you want to know more about TensorFlow for .NET under the hood.
214216

215217
### Contribute:
216218

src/TensorFlowNET.Core/Data/DatasetV2.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ public override string ToString()
132132
break;
133133
}
134134

135-
yield return results.Length == 2
136-
? (results[0], results[1])
137-
: (null, results[0]);
135+
yield return (results[0], results.Length == 1 ? null : results[1]);
138136
}
139137
}
140138

src/TensorFlowNET.Core/Data/IDatasetV2.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ IDatasetV2 map(Func<Tensor, (Tensor, Tensor), (Tensor, Tensor)> map_func,
7575
/// <returns></returns>
7676
IDatasetV2 apply_options();
7777

78+
/// <summary>
79+
/// Returns the cardinality of `dataset`, if known.
80+
/// </summary>
81+
/// <param name="name"></param>
82+
/// <returns></returns>
7883
Tensor dataset_cardinality(string name = null);
7984
}
8085
}

test/TensorFlowNET.UnitTest/Dataset/DatasetTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,14 @@ public void Cache()
142142
value++;
143143
}
144144
}
145+
146+
[TestMethod, Ignore]
147+
public void Cardinality()
148+
{
149+
var dataset = tf.data.Dataset.range(10);
150+
dataset = dataset.map(x => x + 1);
151+
var cardinality = dataset.dataset_cardinality();
152+
Assert.AreEqual(new long[] { 10 }, cardinality.numpy());
153+
}
145154
}
146155
}

0 commit comments

Comments
 (0)