Skip to content

Commit 786d97c

Browse files
Dorokhovmigueldeicaza
authored andcommitted
TensorFlowSharp Unit Tests & CI (migueldeicaza#55)
* Added F# unit test for tensorflow arithmetic operation * Added Travis CI status * added libtensorflow.dylib
1 parent af0bcdf commit 786d97c

10 files changed

Lines changed: 223 additions & 6 deletions

File tree

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: csharp
2+
solution: TensorFlowSharp.sln
3+
script:
4+
- wget "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-1.0.0-rc0.tar.gz"
5+
- tar xjf libtensorflow-cpu-darwin-x86_64-1.0.0-rc0.tar.gz
6+
- mkdir -p $TRAVIS_BUILD_DIR/release-artifacts/libs/
7+
- cd lib
8+
- cp -R $TRAVIS_BUILD_DIR/lib/libtensorflow.so $TRAVIS_BUILD_DIR/release-artifacts/libs/libtensorflow.dylib
9+
- nuget restore $TRAVIS_BUILD_DIR/TensorFlowSharp.sln
10+
- cd $TRAVIS_BUILD_DIR/
11+
- xbuild /p:Configuration=Release TensorFlowSharp.sln
12+
- cp -R $TRAVIS_BUILD_DIR/lib/libtensorflow.so $TRAVIS_BUILD_DIR/tests/TensorFlowSharp.Tests/bin/Release/libtensorflow.dylib
13+
- sh $TRAVIS_BUILD_DIR/build.sh
14+
mono: "latest"
15+
os: "osx"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Build Status](https://travis-ci.org/migueldeicaza/TensorFlowSharp.svg?branch=master)](https://travis-ci.org/migueldeicaza/TensorFlowSharp)
2+
13
TensorFlowSharp are .NET bindings to the TensorFlow library published here:
24

35
https://github.com/tensorflow/tensorflow

SampleTest/SampleTest.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -20,6 +20,7 @@
2020
<WarningLevel>4</WarningLevel>
2121
<ExternalConsole>true</ExternalConsole>
2222
<PlatformTarget>x64</PlatformTarget>
23+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2324
</PropertyGroup>
2425
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2526
<Optimize>true</Optimize>

TensorFlowSharp.sln

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2012
2+
# Visual Studio 14
3+
VisualStudioVersion = 14.0.25420.1
4+
MinimumVisualStudioVersion = 10.0.40219.1
45
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TensorFlowSharp", "TensorFlowSharp\TensorFlowSharp.csproj", "{0264C321-34F4-46AF-819E-168D1E597232}"
56
EndProject
67
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleTest", "SampleTest\SampleTest.csproj", "{243E2C90-F465-4A6E-9063-8F2C138015C7}"
@@ -11,11 +12,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Learn", "Learn\Learn.csproj
1112
EndProject
1213
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleInceptionInference", "Examples\ExampleInceptionInference\ExampleInceptionInference.csproj", "{069A6736-7711-4805-8660-A267E713BC54}"
1314
EndProject
14-
Project("{f2a71f9b-5d33-465a-a702-920d77279786}") = "FSharpExampleInceptionInference", "Examples\FExampleInceptionInference\FSharpExampleInceptionInference.fsproj", "{03FB7F3A-6D24-4033-9B04-69AD8A198CCF}"
15+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpExampleInceptionInference", "Examples\FExampleInceptionInference\FSharpExampleInceptionInference.fsproj", "{03FB7F3A-6D24-4033-9B04-69AD8A198CCF}"
1516
EndProject
1617
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{674EC1D7-9649-462E-A7A8-93D0DE84FE64}"
1718
EndProject
18-
Project("{f2a71f9b-5d33-465a-a702-920d77279786}") = "ImageCompression", "Examples\ImageCompression\ImageCompression.fsproj", "{5A493E1F-407D-4A3B-AF9B-A0F2930C1C18}"
19+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ImageCompression", "Examples\ImageCompression\ImageCompression.fsproj", "{5A493E1F-407D-4A3B-AF9B-A0F2930C1C18}"
20+
EndProject
21+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{6E72CAD1-7962-4256-AF2A-3B813FFC88EA}"
22+
EndProject
23+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "TensorFlowSharp.Tests", "tests\TensorFlowSharp.Tests\TensorFlowSharp.Tests.fsproj", "{9EE13143-569F-4F7A-975A-DE7DF5C8FF0B}"
1924
EndProject
2025
Global
2126
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -51,11 +56,19 @@ Global
5156
{5A493E1F-407D-4A3B-AF9B-A0F2930C1C18}.Debug|Any CPU.Build.0 = Debug|Any CPU
5257
{5A493E1F-407D-4A3B-AF9B-A0F2930C1C18}.Release|Any CPU.ActiveCfg = Release|Any CPU
5358
{5A493E1F-407D-4A3B-AF9B-A0F2930C1C18}.Release|Any CPU.Build.0 = Release|Any CPU
59+
{9EE13143-569F-4F7A-975A-DE7DF5C8FF0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
60+
{9EE13143-569F-4F7A-975A-DE7DF5C8FF0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
61+
{9EE13143-569F-4F7A-975A-DE7DF5C8FF0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
62+
{9EE13143-569F-4F7A-975A-DE7DF5C8FF0B}.Release|Any CPU.Build.0 = Release|Any CPU
63+
EndGlobalSection
64+
GlobalSection(SolutionProperties) = preSolution
65+
HideSolutionNode = FALSE
5466
EndGlobalSection
5567
GlobalSection(NestedProjects) = preSolution
5668
{069A6736-7711-4805-8660-A267E713BC54} = {674EC1D7-9649-462E-A7A8-93D0DE84FE64}
5769
{03FB7F3A-6D24-4033-9B04-69AD8A198CCF} = {674EC1D7-9649-462E-A7A8-93D0DE84FE64}
5870
{5A493E1F-407D-4A3B-AF9B-A0F2930C1C18} = {674EC1D7-9649-462E-A7A8-93D0DE84FE64}
71+
{9EE13143-569F-4F7A-975A-DE7DF5C8FF0B} = {6E72CAD1-7962-4256-AF2A-3B813FFC88EA}
5972
EndGlobalSection
6073
GlobalSection(MonoDevelopProperties) = preSolution
6174
Policies = $0

TensorFlowSharp/TensorFlowSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
cd $TRAVIS_BUILD_DIR/packages/xunit.runner.console.2.2.0/tools
3+
mono --arch=64 xunit.console.exe $TRAVIS_BUILD_DIR/tests/TensorFlowSharp.Tests/bin/Release/TensorFlowSharp.Tests.dll
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace TensorFlowSharp.Tests
2+
3+
open TensorFlow
4+
open Xunit
5+
6+
module ArithmeticOperationTests =
7+
8+
[<Theory>]
9+
[<InlineData(1.0f, 2.0f, 2.0f)>]
10+
[<InlineData(3.0f, 3.0f, 9.0f)>]
11+
let Should_EvaluateMultiplyExpression_ForFloatDataType(aValue:float32 , bValue:float32, expected:float32) =
12+
use graph = new TFGraph()
13+
use session = new TFSession(graph)
14+
15+
let a = graph.Placeholder(TFDataType.Float) // create symbolic variable a
16+
let b = graph.Placeholder(TFDataType.Float) // create symbolic variable b
17+
18+
let y = graph.Mul(a, b) // multiply symbolic variables
19+
20+
// evaluate expression with parameters for a and b
21+
let mul =
22+
session.Run([| a; b |],
23+
[| new TFTensor(aValue); new TFTensor(bValue) |],
24+
[| y |])
25+
26+
let mulTensor = mul.[0]
27+
let mulValue = mulTensor.GetValue() :?> float32
28+
29+
Assert.Equal(expected, mulValue)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace TensorFlowSharp.Tests.AssemblyInfo
2+
3+
open System.Reflection
4+
open System.Runtime.CompilerServices
5+
open System.Runtime.InteropServices
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[<assembly: AssemblyTitle("TensorFlowSharp.Tests")>]
11+
[<assembly: AssemblyDescription("")>]
12+
[<assembly: AssemblyConfiguration("")>]
13+
[<assembly: AssemblyCompany("")>]
14+
[<assembly: AssemblyProduct("TensorFlowSharp.Tests")>]
15+
[<assembly: AssemblyCopyright("Copyright © 2017")>]
16+
[<assembly: AssemblyTrademark("")>]
17+
[<assembly: AssemblyCulture("")>]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[<assembly: ComVisible(false)>]
23+
24+
// The following GUID is for the ID of the typelib if this project is exposed to COM
25+
[<assembly: Guid("9ee13143-569f-4f7a-975a-de7df5c8ff0b")>]
26+
27+
// Version information for an assembly consists of the following four values:
28+
//
29+
// Major Version
30+
// Minor Version
31+
// Build Number
32+
// Revision
33+
//
34+
// You can specify all the values or you can default the Build and Revision Numbers
35+
// by using the '*' as shown below:
36+
// [<assembly: AssemblyVersion("1.0.*")>]
37+
[<assembly: AssemblyVersion("1.0.0.0")>]
38+
[<assembly: AssemblyFileVersion("1.0.0.0")>]
39+
40+
do
41+
()
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>9ee13143-569f-4f7a-975a-de7df5c8ff0b</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>TensorFlowSharp.Tests</RootNamespace>
11+
<AssemblyName>TensorFlowSharp.Tests</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
<Name>TensorFlowSharp.Tests</Name>
16+
<NuGetPackageImportStamp>
17+
</NuGetPackageImportStamp>
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<Tailcalls>false</Tailcalls>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<WarningLevel>3</WarningLevel>
27+
<DocumentationFile>bin\Debug\TensorFlowSharp.Tests.XML</DocumentationFile>
28+
<PlatformTarget>x64</PlatformTarget>
29+
</PropertyGroup>
30+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
31+
<DebugType>pdbonly</DebugType>
32+
<Optimize>true</Optimize>
33+
<Tailcalls>true</Tailcalls>
34+
<OutputPath>bin\Release\</OutputPath>
35+
<DefineConstants>TRACE</DefineConstants>
36+
<WarningLevel>3</WarningLevel>
37+
<DocumentationFile>bin\Release\TensorFlowSharp.Tests.XML</DocumentationFile>
38+
</PropertyGroup>
39+
<PropertyGroup>
40+
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
41+
</PropertyGroup>
42+
<Choose>
43+
<When Condition="'$(VisualStudioVersion)' == '11.0'">
44+
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
45+
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
46+
</PropertyGroup>
47+
</When>
48+
<Otherwise>
49+
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
50+
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
51+
</PropertyGroup>
52+
</Otherwise>
53+
</Choose>
54+
<Import Project="$(FSharpTargetsPath)" />
55+
<ItemGroup>
56+
<Compile Include="AssemblyInfo.fs" />
57+
<Compile Include="ArithmeticOperationTests.fs" />
58+
<Content Include="packages.config" />
59+
</ItemGroup>
60+
<ItemGroup>
61+
<Reference Include="mscorlib" />
62+
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
63+
<Private>True</Private>
64+
</Reference>
65+
<Reference Include="System" />
66+
<Reference Include="System.Core" />
67+
<Reference Include="System.Numerics" />
68+
<ProjectReference Include="..\..\TensorFlowSharp\TensorFlowSharp.csproj">
69+
<Name>TensorFlowSharp</Name>
70+
<Project>{0264c321-34f4-46af-819e-168d1e597232}</Project>
71+
<Private>True</Private>
72+
</ProjectReference>
73+
<Reference Include="xunit.abstractions">
74+
<HintPath>..\..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
75+
<Private>True</Private>
76+
</Reference>
77+
<Reference Include="xunit.assert">
78+
<HintPath>..\..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
79+
<Private>True</Private>
80+
</Reference>
81+
<Reference Include="xunit.console">
82+
<HintPath>..\..\packages\xunit.runner.console.2.2.0\tools\xunit.console.exe</HintPath>
83+
</Reference>
84+
<Reference Include="xunit.core">
85+
<HintPath>..\..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll</HintPath>
86+
<Private>True</Private>
87+
</Reference>
88+
<Reference Include="xunit.execution.desktop">
89+
<HintPath>..\..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll</HintPath>
90+
<Private>True</Private>
91+
</Reference>
92+
<Reference Include="xunit.runner.reporters.net452">
93+
<HintPath>..\..\packages\xunit.runner.console.2.2.0\tools\xunit.runner.reporters.net452.dll</HintPath>
94+
</Reference>
95+
</ItemGroup>
96+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
97+
Other similar extension points exist, see Microsoft.Common.targets.
98+
<Target Name="BeforeBuild">
99+
</Target>
100+
<Target Name="AfterBuild">
101+
</Target>
102+
-->
103+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="xunit" version="2.2.0" targetFramework="net461" />
4+
<package id="xunit.abstractions" version="2.0.1" targetFramework="net461" />
5+
<package id="xunit.assert" version="2.2.0" targetFramework="net461" />
6+
<package id="xunit.core" version="2.2.0" targetFramework="net461" />
7+
<package id="xunit.extensibility.core" version="2.2.0" targetFramework="net461" />
8+
<package id="xunit.extensibility.execution" version="2.2.0" targetFramework="net461" />
9+
<package id="xunit.runner.console" version="2.2.0" targetFramework="net461" developmentDependency="true" />
10+
</packages>

0 commit comments

Comments
 (0)