Properly Load Microsoft.ML model in Xamarin App? - machine-learning

I was learning a bit about how Machine Learning works and eventually built a small C# application because of a tutorial I was watching where a model determines what species of Bee a particular bee IS. It works well in the C# application, but I was also developing an app project that had picture taking capabilities in mind so I thought "No reason the model I saved in the first project can't work in the second, right?". Apparently there is a reason why it can't work because here is the necessary code to view in the app project:
MLContext m_mlObj;
DataViewSchema m_modelSchema;
ITransformer m_loadedTrainedModel;
var folderPath = DependencyService.Get<IFileSystem>().GetExternalStorage();
var fileDir = Path.Combine(folderPath, "trainedModel.zip");
bool testValue = File.Exists(fileDir);
if(testValue)
{
Console.WriteLine("File in fact exists.");
try
{
m_loadedTrainedModel = m_mlObj.Model.Load(fileDir, out m_modelSchema);
}
catch (Exception e)
{
Console.WriteLine("\n\n\nInner exception: " + e.InnerException);
}
}
else
{
Console.WriteLine("File does not exist");
}
I have a breakpoint on the "m_loadedTrainedModel = m_mlObj.Model.Load(fileDir, out m_modelSchema);" line of course and it always triggers an exception.
The exception states:
---> System.TypeLoadException: Could not load type of field 'Microsoft.ML.Transforms.DnnRetrainTransformer:_tfInputShapes' (9) due to: Could not resolve type with token 01000060 from typeref (expected class 'Tensorflow.TensorShape' in assembly 'TensorFlow.NET, Version=0.20.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51') assembly:TensorFlow.NET, Version=0.20.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd5 1 type:Tensorflow.TensorShape member:(null)
What I THINK this means is it's checking for Tensorflow.TensorShape inside of the package TensorFlow.NET and isn't finding it. If that's the case, I believe I don't have the correct package installed so my Xamarin project will be able to load the model correctly, maybe? Or if not, then what may be the real underlying issue? The code seems straight forward so I'm a bit perplexed as to how this is failing.
If the solution is blatantly going over my head, my apologies and thank you to anyone who is willing to help.

When working with ML.NET on ARM, TensorFlow is one of the limitations at the time of this writing.
https://devblogs.microsoft.com/dotnet/ml-net-june-updates-model-builder/#ml-net-on-arm
What you might want to consider in the meantime is deploying your model as a Web API and making requests to that API from your mobile app.
https://learn.microsoft.com/dotnet/machine-learning/how-to-guides/serve-model-web-api-ml-net

Related

Syntax error in library code when including matrial design using Rails + Webpacker + Typescript + Angular

In my rails app, I get a syntax error somewhere in a huge js file that is presumably generated by webpacker. But it seems to be some sort of angular/material code. If I don't include material design, the error goes away, so it seems to be related to material design. This is the part that causes the syntax error:
function instantiateSupportedAnimationDriver() {
return !(function webpackMissingModule() { var e = new Error("Cannot find module '#angular/animations/browser'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())() ? new !(function webpackMissingModule() { var e = new Error("Cannot find module '#angular/animations/browser'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())() : new !(function webpackMissingModule() { var e = new Error("Cannot find module '#angular/animations/browser'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();
}
Note that telling me how to fix the syntax error doesn't help me. This code is not in my control and I wouldn't know how to effectively patch it. Besides, it's a frequently used piece of code, I doubt that it has a syntax error, probably something in plumbing is incorrect.
Some context: I probably don't get all the mechanics right. I am trying to make the combination Rails + Webpacker + Typescript + Angular + Material work. It's quite tricky, I find nothing useful on it on the web and I seem to be pretty much the first one to do it. I saw some suggestions to make an api-only rails app, but I don't like that...
I never really figured out why this caused a syntax error in a seemingly unrelated file, but I had some "unmet peer dependency" warnings and when I fixed them, this went away.

Instantiating Appium IOS/Android driver

I'm using appium-dotnet-driver v4.0.0.4 beta of the appium nuget package (but I have downgraded to the previous versions too and I'm getting the same issue)
So I've never used it before, therefore not entirely sure how it should work. Currently I'm doing this:
private static AppiumDriver<AppiumWebElement> mobileDriver;
AppiumOptions opt = new AppiumOptions();
opt.AddAdditionalCapability("autoWebview", true);
switch (platform.ToLower())
{
case "ios":
{
foreach (var cap in MobileSettingsFileConstants.iosCapabilities)
{
opt.AddAdditionalCapability(cap.Key, cap.Value);
}
mobileDriver = new IOSDriver<AppiumWebElement>(GridUri, opt);
break;
}
When ever it tries to add an additional capability to Appium Options I get an exception : Exception thrown: 'System.MissingMethodException' in appium-dotnet-driver.dll, Additional information: Method not found: 'Void OpenQA.Selenium.Remote.DesiredCapabilities.set_Item
I've had a look on the appium forum and they said this was an issue. Can someone share their experience with this please?
I found out I had to be at the latest version on Selenium on both test framework and test solution.
Simple answer to a mind boggling question.

AngularJS with .NET MVC Bundling Minification Error

I have been developing a large AngularJS application inside of a .NET MVC Website. I've gone way to long without testing if it will sucesfully minifiy using the Bundle Optimiazation Features?
BundleTable.EnableOptimizations = True
And of Course, it fails. I've been playing with the Order I bundle my scripts, and ensuring I am using String Literals for my Controller Names (I wasn't, and that is a lot of re-factoring that I will have to do).
But I can not get my Core Scripts to Minifiy without the angular "Unknown Provider" error.
Here is the exact Error:
Uncaught Error: [$injector:modulerr] [http://errors.angularjs.org/1.3.14/$injector/modulerr?p0=ppAccount&p1=Error…redScripts%3Fv%3DknV3wkCOg32ajaw4GwiRSrTXdo8Ue7MRIn65CPYa1b81%3A1%3A379851)]1
Here is my bundle config that is failing:
bundles.Add(new ScriptBundle("~/bundles/PilotPartnerRequiredScripts")
.Include(
"~/UI/js/jquery/jquery-2.1.3.js",
"~/UI/js/plugins/jquery-ui/jquery-ui.js",
"~/UI/js/bootstrap/bootstrap.js",
"~/UI/js/plugins/pace/pace.min.js",
"~/UI/js/plugins/slimscroll/jquery.slimscroll.js",
"~/UI/js/inspinia.js",
"~/UI/js/angular/angular.js",
"~/UI/js/ui-router/angular-ui-router.js",
"~/UI/js/bootstrap/ui-bootstrap-tpls-0.12.1.js",
"~/UI/js/angular/angular-resource.js",
"~/UI/js/angular/angular-sanitize.js",
"~/UI/js/angular/angular-route.js",
"~/UI/js/plugins/switchery/switchery.js",
"~/UI/js/plugins/angular-ui-switch/angular-ui-switch.js",
"~/UI/js/plugins/angularLocalStorage/angular-local-storage.js",
"~/UI/js/plugins/ngDialog/ngDialog.js",
"~/Scripts/ngTags/ng-tags-input.js",
"~/Scripts/uiSortable/sortable.js",
"~/Scripts/kendo/2014.3.1119/kendo.all.min.js",
"~/Scripts/xeditable/xeditable.js"
For the life of me, I can't figure out which dependency isn't being resolved. I feel that if I can narrow it down to a specific dependency I know I can solve the issue.
Is there any way to track down the specific Module that is causing the issue?
Any suggestions on how to make this work?
Thank you for your help.
You should always follow strict di while injecting dependency (Array notation)
Angualar Doc has mentioned that, Do follow strict DI while doing minification, otherwise it could break you app
Eg.(Code)
angular.module('myModule', [])
.factory('serviceId', ['depService', function(depService) {
// ...
}])
.directive('directiveName', ['depService', function(depService) {
// ...
}])
.filter('filterName', ['depService', function(depService) {
// ...
}]);
In above snippet I followed inline array notation of DI, it has been applied on various angular component just to demonstrate it. You should make sure that you follow it wherever you're injecting dependency.

Rotativa - QT untested version

Up until now, my Rorativa (latest stable version - 1.6.1) has been working beautifully in my MVC project.
My code was originally
return new Rotativa.ActionAsPdf(string.Format("PrintPage/{0}", id));
and I get a nice happy pdf version of my page
But now I want to do some more advances stuff, so I do this
return new Rotativa.ActionAsPdf(string.Format("PrintPage/{0}", id))
{
CustomSwitches = "--print-media-type --footer-html " + Url.Action("Footer",id)
};
and then when I do I get this error
Qt: Untested Windows version 6.2 detected!
QMetaObject::invokeMethod: No such method WebCore::SocketStreamHandlePrivate::socketSentData()
Error: Failed loading page http:///Invoice/Footer?page=1&section=Account Queries VAT No.
0&title=Ben Dover-Invoice No:
A0120852&subsection=MATERIALS&frompage=1&subsubsection=&topage=2&doctitle=Ben Dover-Invoice No:
A0120852&webpage=http://localhost:2066/Invoice/PrintPage/386&time=01:01:59 PM&date=2015/01/06
(sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http:///Invoice/Footer?page=2&section=Account Queries VAT No.
0&title=Ben Dover-Invoice No: A0120852&subsection=TOTAL R
1á850.70&frompage=1&subsubsection=&topage=2&doctitle=Ben Dover-Invoice No:
A0120852&webpage=http://localhost:2066/Invoice/PrintPage/386&time=01:01:59 PM&date=2015/01/06
(sometimes it will work just to ignore this error with --load-error-handling ignore)
QPaintDevice: Cannot destroy paint device that is being painted
pure virtual method called
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
terminate called without an active exception
I tried following the suggestion and add --load-error-handling ignore this removes the error, but my footer doesn't load
We have the same problem on the project. Additionally report work on localhost but not in production server. Solution for the problem is to add route, so the static IP address will be represented as local on the server.
http://technet.microsoft.com/en-us/library/cc757323%28v=ws.10%29.aspx
On some servers that can not be added for some reasons so we add Microsoft loopback adapter to do the same thing.
https://4sysops.com/archives/how-to-install-loopback-adapter-in-windows-8/
After that everything works perfectly.

Compiling jabber-net in Xamarin Studio

I am trying to compile jabber-net in Xamarin Studio so I can use it in a Xamarin.iOS app.
From other searches I have done I am told I need to recompile the source.
From command line I can build the dll, but I have no idea what version of .NET/Mono this is targeting.
This makes a jabber-net.dll and a jabber-net.dll.mdb.
If I add jabber-net.dll to my project, add the reqiured
using jabber.client;
...
...
...
JabberClient client = new JabberClient ();
and try to compile I am told.
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,47): error CS0584: Internal compiler error: Could not import type jabber.client.JabberClient' fromjabber-net, Version=2.1.0.702, Culture=neutral, PublicKeyToken=924c5b18328d6f09'
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,38): error CS0584: Internal compiler error: Could not import type jabber.client.JabberClient' fromjabber-net, Version=2.1.0.702, Culture=neutral, PublicKeyToken=924c5b18328d6f09'
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,38): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
I got no idea what is going on here...
When I try to open any of the .sln's (or include any of the existing projects, even the mono specific project) that came with jabber-net into my solution it will either hang trying to convert the project, or will tell me
The file '/Users/brad/Projects/XMPPChat/JabberNet-2.1.0.710/mono-jabber-net.csproj' could not be loaded.
and will spit out this error.
Any idea where to go from here? :|
Start a new solution from scratch, and add all of the .cs files except those in the test and examples directories. Also make sure you don't have an old version of the .dll around somewhere.

Resources