-
Notifications
You must be signed in to change notification settings - Fork 1.9k
TensorFlowMapper transform for scoring Tensorflow models in ML.NET #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 59 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
f6baa5b
Merge pull request #1 from dotnet/master
abgoswam 7d0ea81
Merge pull request #2 from dotnet/master
abgoswam bad9cd2
Merge pull request #3 from dotnet/master
abgoswam 6b76960
creating dummy file to test permissions. will remove
abgoswam 085cf6c
test
yaeldMS 4175209
TensorFlow scoring, from Zeeshan A.'s branch, with some additional ch…
yaeldMS 3e7d118
Merge pull request #4 from dotnet/master
abgoswam 30dcdc5
creating dummy file to test permissions. will remove
abgoswam b80750b
test
yaeldMS 58c703a
TensorFlow scoring, from Zeeshan A.'s branch, with some additional ch…
yaeldMS 032dc48
Merge branch 'agoswami/tensorflow' of https://github.com/abgoswam/mac…
abgoswam 1f83474
taking care of review comments; build fixes
abgoswam bf7b3a7
simple change intended to trigger fresh builds to repro OSX-Release b…
abgoswam 3c0fc04
Prevent input tensors from being GC'ed before TF_SessionRun is called
ericstj c6ecc72
Remove Tensorflow models from tests data
ericstj 54de166
Add entry point
yaeldMS 2ed4575
Merge remote-tracking branch 'upstream/master'
yaeldMS fb5b607
Merge branch 'master' into agoswami/tensorflow
yaeldMS 55aca30
Fix manifest and generated C# API.
yaeldMS 3f2e3ae
Create a redist package for tensorflow
ericstj 7b53f44
Make TF redist project a normal MSBuild project
ericstj fba6c91
Add TF License file to package
ericstj e22b819
Don't use fullpaths when un-tar'ing
ericstj ada8787
Add some logging to TF redist project
ericstj 2444743
Fix casing of TF redist proj
ericstj de4f6ea
Change tests to use redistributed TensorFlow
ericstj 35500ba
Fix mac / linux tensorflow redist
ericstj b9ddacc
Only include LICENSE if it exists
ericstj a0caf2f
unit test to verify TF transform works with ML.NET image transforms
abgoswam 7a5da64
Merge branch 'agoswami/tensorflow' of https://github.com/abgoswam/mac…
abgoswam cdb5892
Factor TensorflowTransform into its own assembly/package
ericstj 88f54c2
Update Tensorflow to TensorFlow
yaeldMS b69af6c
Fix manifest and C# API. Also, add entry point unit test.
yaeldMS 8938aa4
update test case for image transforms; still skipping test for now ti…
abgoswam 136dca4
fix conflicts
abgoswam c1db655
Use IDataView instead of var in unit test.
yaeldMS 919a408
fix have from Tensorflow to TensorFlow
abgoswam 182e036
Merge branch 'agoswami/tensorflow' of https://github.com/abgoswam/mac…
abgoswam 7f6a495
Merge remote-tracking branch 'upstream/master' into agoswami/tensorflow
yaeldMS 413be27
Fix unit test to use new TextLoader APIs.
yaeldMS 0002083
Add unit test using the pipeline API.
yaeldMS dd3e00a
Validate input dimensions.
yaeldMS b6d8c74
Added XML doc for TensorflowTransform.
zeahmed 1830655
Remove extra dimension for batch size in output.
yaeldMS e3a8e50
Merge branch 'agoswami/tensorflow' of https://github.com/abgoswam/mac…
yaeldMS 7fa60e1
Merge remote-tracking branch 'upstream/master' into agoswami/tensorflow
yaeldMS 8f9a8df
Fix input/output validation.
yaeldMS 4d40f94
Introduced BatchSize as constant to replace 1 everywhere.
zeahmed e23c7be
enabling unit test of TensorFlowTransform working with ML.NET Image* …
abgoswam f61486b
Extended XML docs with detailed information.
zeahmed 7b03215
Merge branch 'agoswami/tensorflow' of https://github.com/abgoswam/mac…
zeahmed 878874b
Ensure we include actual TF license in package
ericstj afdf0cb
Change input validation to validate all dimensions in case of multi d…
yaeldMS acef318
Corrected typos in the documentation.
zeahmed 3fea9da
Merge branch 'agoswami/tensorflow' of https://github.com/abgoswam/mac…
zeahmed 39c3533
Fix LICENSE inclusion in package.
ericstj 145db2d
Add symbols package and fix package reference to redist
ericstj e991fa9
Address pull request comments.
yaeldMS 228fb24
Merge branch 'agoswami/tensorflow' of https://github.com/abgoswam/mac…
yaeldMS 5a849c4
Give more details in input dimension mismatch error message.
yaeldMS 08da76d
Added a test for LearningPipelineAPI and updated the doc.xml
zeahmed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
pkg/Microsoft.ML.TensorFlow.Redist/Microsoft.ML.TensorFlow.Redist.nupkgproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack"> | ||
|
||
<PropertyGroup> | ||
<Authors>The TensorFlow Authors</Authors> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<PackageDescription>$(MSBuildProjectName) contains the TensorFlow C library version $(TensorFlowVersion) redistributed as a NuGet package.</PackageDescription> | ||
<PackageLicenseUrl>https://github.com/tensorflow/tensorflow/blob/master/LICENSE</PackageLicenseUrl> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<Copyright>Copyright 2018 The TensorFlow Authors. All rights reserved.</Copyright> | ||
<PackageProjectUrl>https://www.tensorflow.org</PackageProjectUrl> | ||
<PackageReleaseNotes>https://github.com/tensorflow/tensorflow/releases/tag/v$(TensorFlowVersion)</PackageReleaseNotes> | ||
<PackageTags>$(PackageTags) TensorFlow</PackageTags> | ||
<!-- TODO: consider PackageIconUrl --> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="..\common\CommonPackage.props" Pack="true" PackagePath="build\netstandard2.0\$(MSBuildProjectName).props" /> | ||
<Content Include="$(PackageAssetsPath)$(PackageIdFolderName)\LICENSE.txt" Pack="true" PackagePath=".\" /> | ||
<Content Include="$(PackageAssetsPath)$(PackageIdFolderName)\THIRD_PARTY_NOTICES.txt" Pack="true" PackagePath=".\" /> | ||
</ItemGroup> | ||
</Project> |
12 changes: 12 additions & 0 deletions
12
pkg/Microsoft.ML.TensorFlow/Microsoft.ML.TensorFlow.nupkgproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<PackageDescription>Microsoft.ML.TensorFlow contains ML.NET integration of TensorFlow.</PackageDescription> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Microsoft.ML.TensorFlow.Redist\Microsoft.ML.TensorFlow.Redist.nupkgproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
5 changes: 5 additions & 0 deletions
5
pkg/Microsoft.ML.TensorFlow/Microsoft.ML.TensorFlow.symbols.nupkgproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project DefaultTargets="Pack"> | ||
|
||
<Import Project="Microsoft.ML.TensorFlow.nupkgproj" /> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Microsoft.ML.TensorFlow/Microsoft.ML.TensorFlow.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<IncludeInPackage>Microsoft.ML.TensorFlow</IncludeInPackage> | ||
<DefineConstants>CORECLR</DefineConstants> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Microsoft.ML.Core\Microsoft.ML.Core.csproj" /> | ||
<ProjectReference Include="..\Microsoft.ML.Data\Microsoft.ML.Data.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Update="TensorFlow\TensorGeneric.cs"> | ||
<DesignTime>True</DesignTime> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>TensorGeneric.tt</DependentUpon> | ||
</Compile> | ||
<None Update="TensorFlow\TensorGeneric.tt"> | ||
<Generator>TextTemplatingFileGenerator</Generator> | ||
<LastGenOutput>TensorGeneric.cs</LastGenOutput> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" /> | ||
abgoswam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using size_t = System.UIntPtr; | ||
|
||
#pragma warning disable MSML_GeneralName | ||
#pragma warning disable MSML_ParameterLocalVarName | ||
|
||
namespace Microsoft.ML.Transforms.TensorFlow | ||
{ | ||
/// <summary> | ||
/// This attribute can be applied to callback functions that will be invoked | ||
/// from unmanaged code to managed code. | ||
/// </summary> | ||
/// <remarks> | ||
/// <code> | ||
/// [TensorFlow.MonoPInvokeCallback (typeof (BufferReleaseFunc))] | ||
/// internal static void MyFreeFunc (IntPtr data, IntPtr length){..} | ||
/// </code> | ||
/// </remarks> | ||
internal sealed class MonoPInvokeCallbackAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Use this constructor to annotate the type of the callback function that | ||
/// will be invoked from unmanaged code. | ||
/// </summary> | ||
/// <param name="t">T.</param> | ||
public MonoPInvokeCallbackAttribute(Type t) { } | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct LLBuffer | ||
{ | ||
internal IntPtr data; | ||
internal size_t length; | ||
internal IntPtr data_deallocator; | ||
} | ||
|
||
/// <summary> | ||
/// Holds a block of data, suitable to pass, or retrieve from TensorFlow. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// Use the TFBuffer to blobs of data into TensorFlow, or to retrieve blocks | ||
/// of data out of TensorFlow. | ||
/// </para> | ||
/// <para> | ||
/// There are two constructors to wrap existing data, one to wrap blocks that are | ||
/// pointed to by an IntPtr and one that takes a byte array that we want to wrap. | ||
/// </para> | ||
/// <para> | ||
/// The empty constructor can be used to create a new TFBuffer that can be populated | ||
/// by the TensorFlow library and returned to user code. | ||
/// </para> | ||
/// <para> | ||
/// Typically, the data consists of a serialized protocol buffer, but other data | ||
/// may also be held in a buffer. | ||
/// </para> | ||
/// </remarks> | ||
// TODO: the string ctor | ||
// TODO: perhaps we should have an implicit byte [] conversion that just calls ToArray? | ||
internal class TFBuffer : TFDisposable | ||
{ | ||
// extern TF_Buffer * TF_NewBufferFromString (const void *proto, size_t proto_len); | ||
[DllImport(NativeBinding.TensorFlowLibrary)] | ||
private static extern unsafe LLBuffer* TF_NewBufferFromString(IntPtr proto, IntPtr proto_len); | ||
|
||
// extern TF_Buffer * TF_NewBuffer (); | ||
[DllImport(NativeBinding.TensorFlowLibrary)] | ||
private static extern unsafe LLBuffer* TF_NewBuffer(); | ||
|
||
internal TFBuffer(IntPtr handle) : base(handle) { } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="T:TensorFlow.TFBuffer"/> class. | ||
/// </summary> | ||
public unsafe TFBuffer() : base((IntPtr)TF_NewBuffer()) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Signature of the method that is invoked to release the data. | ||
/// </summary> | ||
/// <remarks> | ||
/// Methods of this signature are invoked with the data pointer and the | ||
/// lenght pointer when then TFBuffer no longer needs to hold on to the | ||
/// data. If you are using this on platforms with static compilation | ||
/// like iOS, you need to annotate your callback with the MonoPInvokeCallbackAttribute, | ||
/// like this: | ||
/// | ||
/// <code> | ||
/// [TensorFlow.MonoPInvokeCallback (typeof (BufferReleaseFunc))] | ||
/// internal static void MyFreeFunc (IntPtr data, IntPtr length){..} | ||
/// </code> | ||
/// </remarks> | ||
public delegate void BufferReleaseFunc(IntPtr data, IntPtr lenght); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="T:TensorFlow.TFBuffer"/> by wrapping the unmanaged resource pointed by the buffer. | ||
/// </summary> | ||
/// <param name="buffer">Pointer to the data that will be wrapped.</param> | ||
/// <param name="size">The size of the buffer to wrap.</param> | ||
/// <param name="release">Optional, if not null, this method will be invoked to release the block.</param> | ||
/// <remarks> | ||
/// This constructor wraps the buffer as a the data to be held by the <see cref="T:TensorFlow.TFBuffer"/>, | ||
/// if the release parameter is null, then you must ensure that the data is not released before the TFBuffer | ||
/// is no longer in use. If the value is not null, the provided method will be invoked to release | ||
/// the data when the TFBuffer is disposed, or the contents of the buffer replaced. | ||
/// </remarks> | ||
public unsafe TFBuffer(IntPtr buffer, long size, BufferReleaseFunc release) : base((IntPtr)TF_NewBuffer()) | ||
{ | ||
LLBuffer* buf = (LLBuffer*)handle; | ||
buf->data = buffer; | ||
buf->length = (size_t)size; | ||
if (release == null) | ||
buf->data_deallocator = IntPtr.Zero; | ||
else | ||
buf->data_deallocator = Marshal.GetFunctionPointerForDelegate(release); | ||
} | ||
|
||
[MonoPInvokeCallback(typeof(BufferReleaseFunc))] | ||
internal static void FreeBlock(IntPtr data, IntPtr length) | ||
{ | ||
Marshal.FreeHGlobal(data); | ||
} | ||
|
||
internal static IntPtr FreeBufferFunc; | ||
internal static BufferReleaseFunc FreeBlockDelegate; | ||
|
||
static TFBuffer() | ||
{ | ||
FreeBlockDelegate = FreeBlock; | ||
FreeBufferFunc = Marshal.GetFunctionPointerForDelegate<BufferReleaseFunc>(FreeBlockDelegate); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="T:TensorFlow.TFBuffer"/> by making a copy of the provided byte array. | ||
/// </summary> | ||
/// <param name="buffer">Buffer of data that will be wrapped.</param> | ||
/// <remarks> | ||
/// This constructor makes a copy of the data into an unmanaged buffer, | ||
/// so the byte array is not pinned. | ||
/// </remarks> | ||
public TFBuffer(byte[] buffer) : this(buffer, 0, buffer.Length) { } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="T:TensorFlow.TFBuffer"/> by making a copy of the provided byte array. | ||
/// </summary> | ||
/// <param name="buffer">Buffer of data that will be wrapped.</param> | ||
/// <param name="start">Starting offset into the buffer to wrap.</param> | ||
/// <param name="count">Number of bytes from the buffer to keep.</param> | ||
/// <remarks> | ||
/// This constructor makes a copy of the data into an unmanaged buffer, | ||
/// so the byte array is not pinned. | ||
/// </remarks> | ||
public TFBuffer(byte[] buffer, int start, int count) : this() | ||
{ | ||
if (start < 0 || start >= buffer.Length) | ||
throw new ArgumentException("start"); | ||
if (count < 0 || count > buffer.Length - start) | ||
throw new ArgumentException("count"); | ||
unsafe | ||
{ | ||
LLBuffer* buf = LLBuffer; | ||
buf->data = Marshal.AllocHGlobal(count); | ||
Marshal.Copy(buffer, start, buf->data, count); | ||
buf->length = (size_t)count; | ||
buf->data_deallocator = FreeBufferFunc; | ||
} | ||
} | ||
|
||
internal unsafe LLBuffer* LLBuffer => (LLBuffer*)handle; | ||
|
||
// extern void TF_DeleteBuffer (TF_Buffer *); | ||
[DllImport(NativeBinding.TensorFlowLibrary)] | ||
private static extern unsafe void TF_DeleteBuffer(LLBuffer* buffer); | ||
|
||
internal override void NativeDispose(IntPtr handle) | ||
{ | ||
unsafe { TF_DeleteBuffer((LLBuffer*)handle); } | ||
} | ||
|
||
// extern TF_Buffer TF_GetBuffer (TF_Buffer *buffer); | ||
[DllImport(NativeBinding.TensorFlowLibrary)] | ||
private static extern unsafe LLBuffer TF_GetBuffer(LLBuffer* buffer); | ||
|
||
/// <summary> | ||
/// Returns a byte array representing the data wrapped by this buffer. | ||
/// </summary> | ||
/// <returns>The array.</returns> | ||
public byte[] ToArray() | ||
{ | ||
if (handle == IntPtr.Zero) | ||
return null; | ||
|
||
unsafe | ||
{ | ||
var lb = (LLBuffer*)handle; | ||
|
||
var result = new byte[(int)lb->length]; | ||
Marshal.Copy(lb->data, result, 0, (int)lb->length); | ||
|
||
return result; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericstj - We should also have a ".symbols" pkgproj file. That way a symbols package gets produced and is uploaded to the symbols server for the managed assemblies in this package. See the other folders for an example. #Resolved