When I install Microsoft.ML stable version in my Web Application and doing same as this tutorial https://dotnet.microsoft.com/learn/machinelearning-ai/ml-dotnet-get-started-tutorial#install
But var model = pipeline.Fit(trainingDataView); this code does not throw any error or does not continue to the next step. Moreover, I tried this same step in a console app and gave the same result.
My Code is:
var mlContext = new MLContext();
var reader = mlContext.Data.CreateTextReader<IrisData>(separatorChar: ',', hasHeader: true);
IDataView trainingDataView = reader.Read("C:/Users/HACKBAL/Documents/visual studio 2017/Projects/WebApplication1/WebApplication1/Data/Test.txt");
var pipeline = mlContext.Transforms.Conversion.MapValueToKey("Label")
.Append(mlContext.Transforms.Concatenate("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"))
.Append(mlContext.MulticlassClassification.Trainers.StochasticDualCoordinateAscent(labelColumn: "Label", featureColumn: "Features"))
.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));
var model = pipeline.Fit(trainingDataView);
var prediction = model.CreatePredictionEngine<IrisData, IrisPrediction>(mlContext).Predict(
new IrisData()
{
SepalLength = 3.3f,
SepalWidth = 1.6f,
PetalLength = 0.2f,
PetalWidth = 5.1f,
});
Console.WriteLine($"Predicted flower type is: {prediction.PredictedLabels}");
I might be a bit late, but found the cause and the solution.
After waiting for the .Fit() method to 'run' for about 30 minutes, it finally gave me the following error:
Apparently it's trying to download the ResNet model from a remote server. Why this is not documented, and why this is being done is the Fit() method is beyond me...
Anyways, the suggested solution is to download the meta file from here:
https://aka.ms/mlnet-resources/meta/resnet_v2_101_299.meta
Then copy the file to the following folder:
C:\Users\YourName\AppData\Local\Temp\MLNET\
Once the file is copied, run your app again, it should be working now.
Try to use .NET Core SDK, not .NET FrameWork.
Download .NET SDKs for Visual Studio
Try to use my work sample on github. Console.Example.ML.NET
Related
I'm trying to use the dll version of ghost script in an azure web app. It has worked before, but now I start getting these errors when using Ghostscript.
An error occured when call to 'gsapi_new_instance' is made: -100
I'm using Ghostscript.NET for working with Ghostscript.
From reading other posts here, it could be because of missing permissions. But I'm not sure which permissions I'm missing.
According to your description, I have created a test demo using Ghostscript.NET with "gsdll32.dll" and published the application to azure. It works well(I don't change any setting).
As you said, it worked well before. I think this error is not related with your permissions. I suggest you could follow below step to troubleshoot the application.
1.Use remote debug to check the gsdll32.dll path is right in your application code
2.Create a new app web app and published the application to it and test again.
More details about my test codes, you could refer to below:
GhostscriptVersionInfo gvi = new GhostscriptVersionInfo(Server.MapPath("~/dll/gsdll32.dll"));
GhostscriptProcessor proc = new GhostscriptProcessor(gvi);
string inputFile = Server.MapPath("~/File/Test Document.pdf");
string outputFile = Server.MapPath("~/File/page-%03d.png");
int pageFrom = 1;
int pageTo = 2;
List<string> switches = new List<string>();
switches.Add("-empty");
switches.Add("-dSAFER");
switches.Add("-dBATCH");
switches.Add("-dNOPAUSE");
switches.Add("-dNOPROMPT");
switches.Add("-dFirstPage=" + pageFrom.ToString());
switches.Add("-dLastPage=" + pageTo.ToString());
switches.Add("-sDEVICE=png16m");
switches.Add("-r96");
switches.Add("-dTextAlphaBits=4");
switches.Add("-dGraphicsAlphaBits=4");
switches.Add(#"-sOutputFile=" + outputFile);
switches.Add(#"-f");
switches.Add(inputFile);
proc.Process(switches.ToArray());
Result:
I have been fiddling with the Veridis sdk 5.0. I need to get the ANSI 378 template from a fingerprint image file. Here is a sample code for that.
var r = VeridisLicense.InstallLicense(myKey, string.Empty);
var bitmap = Bitmap.FromFile(imagePath) as Bitmap;
var sample = new BiometricSample(bitmap, 500);
var bioTemplate = new BiometricTemplate(sample, BiometricTemplateFormat.Ansi);
var data = bioTemplate.GetData();
However, the app crashes with ntdll heap corruption error after executing the InstallLicense line. If I omit that, I get Veridis.Biometric.BiometricException "Not started (Error #-4)" from BiometricTemplate constructor.
Can someone tell me what is going on here? I have the same problem while installing license with the dot net sample that comes with it. However, the demo application inside veridis sdk package does not give any error while installing the license.
I believe you forgot to call the static function BiometricCapture.StartSDK(eventListener)
You also will need a class that inherit from ICaptureListener. That new class will be your Event listener.
I'm having a very hard time with what I feel should be a simple task. Every week, our team queries VMware vCenter for three pieces of output: VM counts in three different locations. Here is what it looks like:
Name Value
---- -----
locationA 1433
locationB 278
locationC 23
The information is emailed to our team, as well as some of the higher-ups who like to see the data. This is all automated with a Powershell script and Windows Task Scheduler running on a server, no problems.
That data is also placed in a Google sheet. We just append a new row with the date, and copy and paste the data into the three existing columns. It takes 30 seconds, once a week. Seems silly given how little time it takes to copy it over to the Google sheet but I really want to automate that last process using Google Sheets API.
I seem to keep finding and persuing what feel are online wild goose chases, in the Google scripting to accessing and editing Google sheets. I've downloaded and installed the Sheets API libraries, Drive API libraries, the Google .net library, set up the Google developer site, and run through the Google sheets API documentation and OAuth authenticating. I'm using Visual Studio 2013 because I figured that would play the best with Powershell and calling the .net commands.
I have pretty much no coding experience outside of Powershell (if you can call that coding). I can't even figure out how to pull the Google sheet, much less do anything to it. Nothing I've tried is working so far, and for what little time it takes to copy this info manually every week I've already spent so much more time than is probably worth it. I feel like if I can get a handle on this, that would open the door for further Google automation in the future since we operate with a Google domain. At any rate, help is very much appreciated.
Here is my latest scripting attempt in Visual Studio:
using System;
using Google.GData.Client;
using Google.GData.Spreadsheets;
namespace MySpreadsheetIntegration
{
class Program {
static void Main(string[] args)
{
string CLIENT_ID = "abunchofcharacters.apps.googleusercontent.com";
string CLIENT_SECRET = "secretnumber";
string REDIRECT_URI = "https://code.google.com/apis/console";
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.ClientId = CLIENT_ID;
parameters.ClientSecret = CLIENT_SECRET;
parameters.RedirectUri = REDIRECT_URI;
parameters.Scope = SCOPE;
string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
Console.WriteLine(https://code.google.com/apis/console);
Console.WriteLine("Please visit the URL above to authorize your OAuth "
+ "request token. Once that is complete, type in your access code to "
+ "continue..."));
parameters.AccessCode = Console.ReadLine();
OAuthUtil.GetAccessToken(parameters);
string accessToken = parameters.AccessToken;
Console.WriteLine("OAuth Access Token: " + accessToken);
GOAuth2RequestFactory requestFactory =
new GOAuth2RequestFactory(null, "MySpreadsheetIntegration-v1", parameters);
SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");
service.RequestFactory = requestFactory;
var driveService = new DriveService(auth);
var file = new File();
file.Title = "VSI - VM Totals by Service TEST";
file.Description = string.Format("Created via {0} at {1}", ApplicationName, DateTime.Now.ToString());
file.MimeType = "application/vnd.google-apps.spreadsheet";
var request = driveService.Files.Insert(file);
var result = request.Fetch();
var spreadsheetLink = "https://docs.google.com/spreadsheets/d/GoogleDoc_ID";
Console.WriteLine("Created at " + spreadsheetLink);
End Class;
End Namespace;
}
}
}
For anyone still following this, I found a solution. I was going about this entirely the wrong way (or at least a way that I could comprehend). One solution to my issue was to create a new Google Script that only accessed my email once a week (after we got the report) and teased out everything but the data I was looking for and sent it to the Google spreadsheet.
Here's the script:
function SendtoSheet(){
var threads = GmailApp.search("from:THESENDER in:anywhere subject:THESUBJECTOFTHEEMAILWHICHNEVERCHANGES")[0];
var message = threads.getMessages().pop()
var bodytext = message.getBody();
counts = []
bodytext = bodytext.split('<br>');
for (var i=0 ; i < bodytext.length; i++){
line = bodytext[i].split(':');
if (line.length > 0){
if (!isNaN(line[1])){counts.push(line[1]);}}}
var now = new Date()
counts.unshift(Utilities.formatDate(now, 'EST', 'MM/dd/yyyy'))
var sheet = SpreadsheetApp.openById("GoogleDocID")
sheet = sheet.setActiveSheet(sheet.getSheetByName("Data by Week"))
sheet.appendRow(counts)
}
That Counts array contains the magic to extract the numeric data by breaking up by line breaks and :'s. Works perfectly. It didn't involve figuring out how to use Visual Studio, or the .net Google libraries, or editing the running PowerShell script. Clean and easy.
Hope this helps someone.
Using Rotativa 1.6.4 from NuGet and have noticed the following issue using the code below.
ActionAsPdf hangs randomly for indeterminate amount of time.
Code below that is hanging:
var pdfResult = new ActionAsPdf("Report", new {id = Request.Params["id"]})
{
Cookies = cookieCollection,
FormsAuthenticationCookieName = FormsAuthentication.FormsCookieName,
CustomSwitches = "--load-error-handling ignore"
};
Background info that may help:
The customSwitches is in use to ignore a documented issue calling wkhtmltopdf.exe using the ActionAsPdf, but it does not suppress errors in the code only in the wkhtmltopdf call.
Observations, usage and testing:
It works but when running the application (whether or not stepping through code), it can be anywhere from 10 seconds up to about 4 minutes between hitting the pdfResult = new ActionAsPdf and finally entering into the "Report" action being called. Can't discern anything actually happening in the output window of Visual Studio, no errors are being thrown that I have found. Just random slow transition into the Reports() action.
I can run the Reports() action directly via URL and it never slows like this and is quite fast for PDF generation. I am running it using the ActionAsPdf to obtain the binary to save to file system and send via email, which is the prescribed method of doing so for this library.
The behavior exists on both a local Windows 10 dev box and a remote Server 2008R2 Test box. .Net 4.5.1 on both boxes, default IIS on each.
Questions I have:
Any idea on what might cause this slow down and how to remedy it?
I ended up using UrlAsPdf() instead of ActionAsPdf() and it works. Seems there may be some issues with the ActionAsPdf() and I have filed a bug with Rotative project on GitHub. The ActionAsPdf() is still marked as beta, so hopefully it get's fixed in future versions or by the community.
In my case, I had to do few more tweaks along with using UrlAsPdf(). I have narrowed down the issue to the cookie collection that I was adding. So I tried just adding the cookie that I needed, and the issue was resolved. Following is the sample code that I have used.
var report = new UrlAsPdf(url);
Dictionary<string, string> cookieCollection = new Dictionary<string, string>();
foreach (var key in Request.Cookies.AllKeys)
{
if (Crypto.Hash("_user").Equals(key))
{
cookieCollection.Add(key, Request.Cookies.Get(key).Value);
break;
}
}
report.Cookies = cookieCollection;
report.FormsAuthenticationCookieName = FormsAuthentication.FormsCookieName;
My basic problem was converting a .docx file to .pdf. The problem would be solved incase I was allowed to use Microsoft.Office.Interop.Word.dll, which i am not since the server will not have MS Office installed. So I needed a free/open-source library that would allow me to do so. And i came across docx4j.NET.
http://www.docx4java.org/blog/2014/09/docx-to-pdf-in-c-net/
This worked fine as long as I ran it as a Console App. The following is the concerned code snippet:
string fileIN = #"C:\Users\...\Visual Studio 2013\Projects\HRDapp\HRDapp\Letter_Templates\AP.docx";
string fileOUT = #"C:\Users\...\Visual Studio 2013\Projects\HRDapp\HRDapp\Letter_Templates\AP.pdf";
log.Info("Hello from Common Logging");
// Necessary, if slf4j-api and slf4j-NetCommonLogging are separate DLLs
ikvm.runtime.Startup.addBootClassPathAssembly(
System.Reflection.Assembly.GetAssembly(
typeof(org.slf4j.impl.StaticLoggerBinder)));
// Configure to find docx4j.properties
// .. add as URL the dir containing docx4j.properties (not the file itself!)
Plutext.PropertiesConfigurator.setDocx4jPropertiesDir(projectDir + #"src\samples\resources\");
java.io.File file = new java.io.File(fileIN);
// OK, do it..
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(file);
java.io.FileOutputStream fos = new java.io.FileOutputStream(new java.io.File(fileOUT));
org.docx4j.Docx4J.toPDF(wordMLPackage, fos);
fos.close();
In case of using this in a Web App, the code runs fine till
java.io.File file = new java.io.File(fileIN);
and gets stuck at
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(file);
Although the file path is correct and works fine in the console app, but there seems something else that I am missing here. The log also prints upto the following statement-
iisexpress.exe Information: 0 : [INFO] org.docx4j.jaxb.Context - Using Java 6/7 JAXB implementation
.. and stops. Any kind of reply directing me to the source of the error will be very helpful. Thanks.
As Jeroen (of IKVM fame) has explained, when there is no main assembly (eg in an ASP.NET application), the IKVM class loader can't find your assembly when the code is trying to dynamically load a class.
So you'll want to add not just:
ikvm.runtime.Startup.addBootClassPathAssembly(
System.Reflection.Assembly.GetAssembly(
typeof(org.slf4j.impl.StaticLoggerBinder)));
but also:
ikvm.runtime.Startup.addBootClassPathAssembly(
System.Reflection.Assembly.GetAssembly(
typeof(org.slf4j.LoggerFactory)));
ikvm.runtime.Startup.addBootClassPathAssembly(
System.Reflection.Assembly.GetAssembly(
typeof(org.docx4j.jaxb.Context)));