update net6
This commit is contained in:
parent
5e08f0b7d5
commit
9c998f7614
@ -8,6 +8,7 @@ using System.Linq;
|
|||||||
namespace Mask.ML.WebApi.Controllers
|
namespace Mask.ML.WebApi.Controllers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
public class DiscernController : ControllerBase
|
public class DiscernController : ControllerBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -16,17 +17,11 @@ namespace Mask.ML.WebApi.Controllers
|
|||||||
/// <param name="stream"></param>
|
/// <param name="stream"></param>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
[HttpPost("upload")]
|
[HttpPost("upload")]
|
||||||
[Route("api/discern/upload")]
|
public IActionResult UploadFile(IFormFile file)
|
||||||
public IActionResult UploadFile([FromForm] IFormCollection collection)
|
|
||||||
{
|
{
|
||||||
//申明返回的结果
|
//申明返回的结果
|
||||||
string result = "";
|
string result = "";
|
||||||
FormFileCollection filelist = (FormFileCollection)collection.Files;
|
|
||||||
//检查是否有文件提交上来
|
|
||||||
if (filelist != null && filelist.Any())
|
|
||||||
{
|
|
||||||
//我们只做第一个文件的检查
|
|
||||||
IFormFile file = filelist[0];
|
|
||||||
//做随机数,用到文件夹名字上,防重名
|
//做随机数,用到文件夹名字上,防重名
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
string r = "";
|
string r = "";
|
||||||
@ -69,8 +64,7 @@ namespace Mask.ML.WebApi.Controllers
|
|||||||
var predictionResult = ConsumeModel.Predict(sampleData);
|
var predictionResult = ConsumeModel.Predict(sampleData);
|
||||||
//System.IO.File.Delete(filefullname);
|
//System.IO.File.Delete(filefullname);
|
||||||
return Ok(predictionResult.Prediction);
|
return Ok(predictionResult.Prediction);
|
||||||
}
|
|
||||||
return NoContent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -25,7 +25,15 @@ namespace Mask.ML.WebApi
|
|||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
services.AddSwaggerGen(c =>
|
||||||
|
{
|
||||||
|
c.SwaggerDoc("v1", new OpenApiInfo
|
||||||
|
{
|
||||||
|
Title = "Mask.ML",
|
||||||
|
Version = "v1",
|
||||||
|
Description = "框架说明文档"
|
||||||
|
});
|
||||||
|
});
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,6 +45,13 @@ namespace Mask.ML.WebApi
|
|||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI(c =>
|
||||||
|
{
|
||||||
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Mask.ML v1");
|
||||||
|
c.RoutePrefix = string.Empty;//如果设置根目录为swagger,将此值置空
|
||||||
|
});
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.ML" Version="1.5.0-preview2" />
|
<PackageReference Include="Microsoft.ML" Version="1.5.0-preview2" />
|
||||||
|
@ -13,17 +13,18 @@ namespace Mask_MLML.ConsoleApp
|
|||||||
{
|
{
|
||||||
public static class ModelBuilder
|
public static class ModelBuilder
|
||||||
{
|
{
|
||||||
private static string TRAIN_DATA_FILEPATH = @"C:\Users\HUAWEI\AppData\Local\Temp\b441e20c-6f79-4437-a21a-be0014456e13.tsv";
|
private static string TRAIN_DATA_FILEPATH = @"\b441e20c-6f79-4437-a21a-be0014456e13.tsv";
|
||||||
private static string MODEL_FILEPATH = @"C:\Users\HUAWEI\AppData\Local\Temp\MLVSTools\Mask.MLML\Mask.MLML.Model\MLModel.zip";
|
private static string MODEL_FILEPATH = @"\MLModel.zip";
|
||||||
// Create MLContext to be shared across the model creation workflow objects
|
// Create MLContext to be shared across the model creation workflow objects
|
||||||
// Set a random seed for repeatable/deterministic results across multiple trainings.
|
// Set a random seed for repeatable/deterministic results across multiple trainings.
|
||||||
private static MLContext mlContext = new MLContext(seed: 1);
|
private static MLContext mlContext = new MLContext(seed: 1);
|
||||||
|
|
||||||
public static void CreateModel()
|
public static void CreateModel()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Load Data
|
// Load Data
|
||||||
IDataView trainingDataView = mlContext.Data.LoadFromTextFile<ModelInput>(
|
IDataView trainingDataView = mlContext.Data.LoadFromTextFile<ModelInput>(
|
||||||
path: TRAIN_DATA_FILEPATH,
|
path: Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TRAIN_DATA_FILEPATH),
|
||||||
hasHeader: true,
|
hasHeader: true,
|
||||||
separatorChar: '\t',
|
separatorChar: '\t',
|
||||||
allowQuoting: true,
|
allowQuoting: true,
|
||||||
@ -39,7 +40,7 @@ namespace Mask_MLML.ConsoleApp
|
|||||||
Evaluate(mlContext, trainingDataView, trainingPipeline);
|
Evaluate(mlContext, trainingDataView, trainingPipeline);
|
||||||
|
|
||||||
// Save model
|
// Save model
|
||||||
SaveModel(mlContext, mlModel, MODEL_FILEPATH, trainingDataView.Schema);
|
SaveModel(mlContext, mlModel, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, MODEL_FILEPATH), trainingDataView.Schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEstimator<ITransformer> BuildTrainingPipeline(MLContext mlContext)
|
public static IEstimator<ITransformer> BuildTrainingPipeline(MLContext mlContext)
|
||||||
|
@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.ML;
|
using Microsoft.ML;
|
||||||
using Mask_MLML.Model;
|
using Mask_MLML.Model;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Mask_MLML.Model
|
namespace Mask_MLML.Model
|
||||||
{
|
{
|
||||||
@ -25,9 +26,8 @@ namespace Mask_MLML.Model
|
|||||||
{
|
{
|
||||||
// Create new MLContext
|
// Create new MLContext
|
||||||
MLContext mlContext = new MLContext();
|
MLContext mlContext = new MLContext();
|
||||||
|
|
||||||
// Load model & create prediction engine
|
// Load model & create prediction engine
|
||||||
string modelPath = @"C:\Users\HUAWEI\AppData\Local\Temp\MLVSTools\Mask.MLML\Mask.MLML.Model\MLModel.zip";
|
string modelPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MLModel.zip");
|
||||||
ITransformer mlModel = mlContext.Model.Load(modelPath, out var modelInputSchema);
|
ITransformer mlModel = mlContext.Model.Load(modelPath, out var modelInputSchema);
|
||||||
var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
|
var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user