Browse Source

Add dataset cardinality test #695

tags/keras_v0.3.0
Oceania2018 4 years ago
parent
commit
8cdb4a7828
4 changed files with 21 additions and 7 deletions
  1. +6
    -4
      README.md
  2. +1
    -3
      src/TensorFlowNET.Core/Data/DatasetV2.cs
  3. +5
    -0
      src/TensorFlowNET.Core/Data/IDatasetV2.cs
  4. +9
    -0
      test/TensorFlowNET.UnitTest/Dataset/DatasetTest.cs

+ 6
- 4
README.md View File

@@ -16,13 +16,15 @@

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

`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.
`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.

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

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.
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.

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#.
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#.

Go through the online docs [TensorFlow for .NET](https://scisharp.github.io/tensorflow-net-docs) before you get started with Machine Learning in .NET.

### How to use

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

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.
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.

### Contribute:



+ 1
- 3
src/TensorFlowNET.Core/Data/DatasetV2.cs View File

@@ -132,9 +132,7 @@ namespace Tensorflow
break;
}

yield return results.Length == 2
? (results[0], results[1])
: (null, results[0]);
yield return (results[0], results.Length == 1 ? null : results[1]);
}
}



+ 5
- 0
src/TensorFlowNET.Core/Data/IDatasetV2.cs View File

@@ -75,6 +75,11 @@ namespace Tensorflow
/// <returns></returns>
IDatasetV2 apply_options();

/// <summary>
/// Returns the cardinality of `dataset`, if known.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
Tensor dataset_cardinality(string name = null);
}
}

+ 9
- 0
test/TensorFlowNET.UnitTest/Dataset/DatasetTest.cs View File

@@ -142,5 +142,14 @@ namespace TensorFlowNET.UnitTest.Dataset
value++;
}
}

[TestMethod, Ignore]
public void Cardinality()
{
var dataset = tf.data.Dataset.range(10);
dataset = dataset.map(x => x + 1);
var cardinality = dataset.dataset_cardinality();
Assert.AreEqual(new long[] { 10 }, cardinality.numpy());
}
}
}

Loading…
Cancel
Save