Skip to content
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

Update ML.NET to work with .NET8 #6641

Merged
merged 4 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<NoWarn>$(NoWarn);MSB3270</NoWarn>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<SignAssembly>false</SignAssembly>
<!--This ensures that we can never make the mistake of adding this as a friend assembly. Please don't remove.-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Tar;
using Microsoft.ML;
Expand All @@ -23,7 +25,9 @@ public static void Example()
string modelLocation = "resnet_v2_101_299_frozen.pb";
if (!File.Exists(modelLocation))
{
modelLocation = Download(@"https://storage.googleapis.com/download.tensorflow.org/models/tflite_11_05_08/resnet_v2_101.tgz", @"resnet_v2_101_299_frozen.tgz");
var downloadTask = Download(@"https://storage.googleapis.com/download.tensorflow.org/models/tflite_11_05_08/resnet_v2_101.tgz", @"resnet_v2_101_299_frozen.tgz");
downloadTask.Wait();
modelLocation = downloadTask.Result;
Unzip(Path.Join(Directory.GetCurrentDirectory(), modelLocation),
Directory.GetCurrentDirectory());

Expand Down Expand Up @@ -111,11 +115,18 @@ class OutputScores
public float[] output { get; set; }
}

private static string Download(string baseGitPath, string dataFile)
private static async Task<string> Download(string baseGitPath, string dataFile)
michaelgsharp marked this conversation as resolved.
Show resolved Hide resolved
{
using (WebClient client = new WebClient())
if (File.Exists(dataFile))
return dataFile;

using (HttpClient client = new HttpClient())
{
client.DownloadFile(new Uri($"{baseGitPath}"), dataFile);
var response = await client.GetStreamAsync(new Uri($"{baseGitPath}")).ConfigureAwait(false);
using (var fs = new FileStream(dataFile, FileMode.CreateNew))
{
await response.CopyToAsync(fs).ConfigureAwait(false);
michaelgsharp marked this conversation as resolved.
Show resolved Hide resolved
}
}

return dataFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ML;
Expand Down Expand Up @@ -244,14 +245,14 @@ public static string DownloadImageSet(string imagesDownloadFolder)
string fileName = "flower_photos_small_set.zip";
string url = $"https://aka.ms/mlnet-resources/datasets/flower_photos_small_set.zip";

Download(url, imagesDownloadFolder, fileName);
Download(url, imagesDownloadFolder, fileName).Wait();
UnZip(Path.Combine(imagesDownloadFolder, fileName), imagesDownloadFolder);

return Path.GetFileNameWithoutExtension(fileName);
}

// Download file to destination directory from input URL.
public static bool Download(string url, string destDir, string destFileName)
public static async Task<bool> Download(string url, string destDir, string destFileName)
{
if (destFileName == null)
destFileName = url.Split(Path.DirectorySeparatorChar).Last();
Expand All @@ -266,14 +267,18 @@ public static bool Download(string url, string destDir, string destFileName)
return false;
}

var wc = new WebClient();
Console.WriteLine($"Downloading {relativeFilePath}");
var download = Task.Run(() => wc.DownloadFile(url, relativeFilePath));
while (!download.IsCompleted)

using (HttpClient client = new HttpClient())
{
Thread.Sleep(1000);
Console.Write(".");
var response = await client.GetStreamAsync(new Uri($"{url}")).ConfigureAwait(false);

using (var fs = new FileStream(relativeFilePath, FileMode.CreateNew))
{
await response.CopyToAsync(fs);
}
}

Console.WriteLine("");
Console.WriteLine($"Downloaded {relativeFilePath}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ML;
Expand Down Expand Up @@ -275,15 +276,15 @@ public static string DownloadImageSet(string imagesDownloadFolder)
// https://github.com/YoongiKim/CIFAR-10-images
string url = $"https://github.com/YoongiKim/CIFAR-10-images/archive/refs/heads/master.zip";

Download(url, imagesDownloadFolder, fileName);
Download(url, imagesDownloadFolder, fileName).Wait();
UnZip(Path.Combine(imagesDownloadFolder, fileName),
imagesDownloadFolder);

return Path.GetFileNameWithoutExtension(fileName);
}

// Download file to destination directory from input URL.
public static bool Download(string url, string destDir, string destFileName)
public static async Task<bool> Download(string url, string destDir, string destFileName)
{
if (destFileName == null)
destFileName = url.Split(Path.DirectorySeparatorChar).Last();
Expand All @@ -298,14 +299,18 @@ public static bool Download(string url, string destDir, string destFileName)
return false;
}

var wc = new WebClient();
Console.WriteLine($"Downloading {relativeFilePath}");
var download = Task.Run(() => wc.DownloadFile(url, relativeFilePath));
while (!download.IsCompleted)

using (HttpClient client = new HttpClient())
{
Thread.Sleep(1000);
Console.Write(".");
var response = await client.GetStreamAsync(new Uri($"{url}")).ConfigureAwait(false);

using (var fs = new FileStream(relativeFilePath, FileMode.CreateNew))
{
await response.CopyToAsync(fs);
}
}

Console.WriteLine("");
Console.WriteLine($"Downloaded {relativeFilePath}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ML;
Expand Down Expand Up @@ -232,14 +233,14 @@ public static string DownloadImageSet(string imagesDownloadFolder)
string fileName = "flower_photos_small_set.zip";
string url = $"https://aka.ms/mlnet-resources/datasets/flower_photos_small_set.zip";

Download(url, imagesDownloadFolder, fileName);
Download(url, imagesDownloadFolder, fileName).Wait();
UnZip(Path.Combine(imagesDownloadFolder, fileName), imagesDownloadFolder);

return Path.GetFileNameWithoutExtension(fileName);
}

// Download file to destination directory from input URL.
public static bool Download(string url, string destDir, string destFileName)
public static async Task<bool> Download(string url, string destDir, string destFileName)
{
if (destFileName == null)
destFileName = url.Split(Path.DirectorySeparatorChar).Last();
Expand All @@ -254,14 +255,18 @@ public static bool Download(string url, string destDir, string destFileName)
return false;
}

var wc = new WebClient();
Console.WriteLine($"Downloading {relativeFilePath}");
var download = Task.Run(() => wc.DownloadFile(url, relativeFilePath));
while (!download.IsCompleted)

using (HttpClient client = new HttpClient())
{
Thread.Sleep(1000);
Console.Write(".");
var response = await client.GetStreamAsync(new Uri($"{url}")).ConfigureAwait(false);

using (var fs = new FileStream(relativeFilePath, FileMode.CreateNew))
{
await response.CopyToAsync(fs);
}
}

Console.WriteLine("");
Console.WriteLine($"Downloaded {relativeFilePath}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ML;
Expand Down Expand Up @@ -253,14 +254,14 @@ public static string DownloadImageSet(string imagesDownloadFolder)
string fileName = "flower_photos_small_set.zip";
string url = $"https://aka.ms/mlnet-resources/datasets/flower_photos_small_set.zip";

Download(url, imagesDownloadFolder, fileName);
Download(url, imagesDownloadFolder, fileName).Wait();
UnZip(Path.Combine(imagesDownloadFolder, fileName), imagesDownloadFolder);

return Path.GetFileNameWithoutExtension(fileName);
}

// Download file to destination directory from input URL.
public static bool Download(string url, string destDir, string destFileName)
public static async Task<bool> Download(string url, string destDir, string destFileName)
{
if (destFileName == null)
destFileName = url.Split(Path.DirectorySeparatorChar).Last();
Expand All @@ -275,14 +276,18 @@ public static bool Download(string url, string destDir, string destFileName)
return false;
}

var wc = new WebClient();
Console.WriteLine($"Downloading {relativeFilePath}");
var download = Task.Run(() => wc.DownloadFile(url, relativeFilePath));
while (!download.IsCompleted)

using (HttpClient client = new HttpClient())
{
Thread.Sleep(1000);
Console.Write(".");
var response = await client.GetStreamAsync(new Uri($"{url}")).ConfigureAwait(false);

using (var fs = new FileStream(relativeFilePath, FileMode.CreateNew))
{
await response.CopyToAsync(fs);
}
}

Console.WriteLine("");
Console.WriteLine($"Downloaded {relativeFilePath}");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<SignAssembly>false</SignAssembly>
<!--This ensures that we can never make the mistake of adding this as a friend assembly. Please don't remove.-->
Expand Down
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<ApprovalTestsVersion>5.4.7</ApprovalTestsVersion>
<BenchmarkDotNetVersion>0.12.0</BenchmarkDotNetVersion>
<DotNetRuntime60Version>6.0.9</DotNetRuntime60Version>
<DotNetRuntime80Version>8.0.0-preview.3.23174.8</DotNetRuntime80Version>
<FluentAssertionVersion>5.10.2</FluentAssertionVersion>
<MicrosoftCodeAnalysisTestingVersion>1.1.2-beta1.22512.1</MicrosoftCodeAnalysisTestingVersion>
<MicrosoftDotNetXUnitExtensionsVersion>7.0.0-beta.23073.6</MicrosoftDotNetXUnitExtensionsVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Data.Analysis/Microsoft.Data.Analysis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- The following properties are set to package M.D.A.Interactive with the M.D.A nuget package. If M.D.A.I undergoes TFM or dependency changes, we need to update the TargetFramework passed in below-->
<Target Name="AddMDAIToInteractiveExtensionsFolder">
<MSBuild Projects="./../Microsoft.Data.Analysis.Interactive/Microsoft.Data.Analysis.Interactive.csproj" Targets="_GetBuildOutputFilesWithTfm" Properties="TargetFramework=netcoreapp3.1">
<MSBuild Projects="./../Microsoft.Data.Analysis.Interactive/Microsoft.Data.Analysis.Interactive.csproj" Targets="_GetBuildOutputFilesWithTfm" Properties="TargetFramework=net6.0">
<!-- Manually hardcoding the TargetFramework to netcoreapp3.1 as that is the one that MDAI targets -->
<Output TaskParameter="TargetOutputs" ItemName="_ItemsToIncludeForInteractive" />
</MSBuild>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal partial class PredictProject : PredictProjectBase
public virtual string TransformText()
{
this.Write("<Project Sdk=\"Microsoft.NET.Sdk\">\r\n\r\n <PropertyGroup>\r\n <OutputType>Exe</Outp" +
"utType>\r\n <TargetFramework>netcoreapp3.1</TargetFramework>\r\n </PropertyGroup" +
"utType>\r\n <TargetFramework>net6.0</TargetFramework>\r\n </PropertyGroup" +
">\r\n <ItemGroup>\r\n <PackageReference Include=\"Microsoft.ML\" Version=\"");
this.Write(this.ToStringHelper.ToStringWithCulture(StablePackageVersion));
this.Write("\" />\r\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ML" Version="<#= StablePackageVersion #>" />
Expand Down
Loading