How to load a onnx model on tensorflow.js? - tensorflow.js

I'm creating a program using Tensorflow.js.
It should receive an onnx file and be able to load it with tf, being able to make inferences.
My problem is how to convert it from onnx to tfjs?
I would rather solve it using just js. (so i can't use https://github.com/onnx/onnx-tensorflow cause python)
If it helps the file contains an image classfication cnn, being either resNet18, resnet34 or mobilenet.

An alternative solution may be to use ONNX Runtime Web's Javascript API - https://github.com/microsoft/onnxruntime/blob/master/js/web
ORT Web takes ONNX models directly.
Side note - tfjs models conversion via the Tensorflow-ONNX converter (https://github.com/onnx/tensorflow-onnx) is also in the works and will be released soon

Related

Sagemaker Inference Endpoint with fitted Encoder

So as I don't get any help by reading documentations and blogposts I ll ask over here:
I want to deploy a Sagemaker Endpoint with fitting a Sagemaker Pipeline. I want to have an endpoint which is backed by a PipelineModel. This PipelineModel should consist of two models: A fitted model which encodes my data and a model which predicts with an XGBoost estimator. I follow along this docu: enter link description here
But this example doesn't show how to integrate the fitted preprocessor model in a PipelineStep. What Step do I have to use? A TrainingStep? Thanks in advance. I am desperate
Check out this official example: Train register and deploy a pipeline model.
The two variations to keep in mind:
For models that need training (usually for those based on tensorflow/pytorch), a TrainingStep must be used so that the output (the model artifact) is correctly (and automatically) generated with the ability to use it later for inference.
For models generated by a simple fitting on the data (e.g., a scaler with sklearn), you can think about creating a TrainingStep in disguised (it is an extra component in pipeline, it is not very correct to do it but it is a working round) but the more correct method is to configure the preprocessing script so that it internally saves a model.tar.gz file with the necessary files (e.g., pickle or joblib objects) inside it can then be properly used in later steps as model_data. In fact, if you have a model.tar.gz, you can define a Model of various types (e.g., an SKLearnModel) that is already fitted.
At this point, you define your PipelineModel with the trained/fitted models and can either proceed to direct endpoint deployment or decide to go through the model registry and keep a more robust approach.

Using X3D and Javascript

I'm supposed to develop a project using X3D. I have an idea to create a conversor of DXf file to X3D. however, to do that, I have to use Javascript to manage this properly, but I haven't found a way to integrate Javascript with X3D. Does someone know some way to do that?
Previously, I though in loading the dxf file, get the data I need, and save this as a X3D file, like writing the XML.
thanks in advance
X3D supports JavaScript natively in the Script node (and it is sometimes referred to via the standardization name EcmaScript). Script events are connected to a scene via ROUTE statements. This provides a bridge between declarative 3D models and programmatic events/computation. Lots more online:
http://x3dgraphics.com/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting
http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts
http://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html#Scripts
http://www.web3d.org/x3d/content/X3dTooltips.html#Script
http://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/scripting.html#Script
In VRML you can integrate javascript using the Script node.
Here's an example:
DEF SCRIPT Script {
url ["javascript:
here goes your javascript code
"]
}
Considering that X3D started as the XML representation of VRML then I suppose there is support in X3D for the Script node.
Edit: Yes I can confirm the above.

Register Embedded DirectShow filter

I am working on an application at the moment that plays back video with a DirectShow filter. The application is written in WPF and is using MediaElements to play the video. As long as the DirectShow filter is registered the video will play. At the moment I just use regsvr32 to register the filter before playback.
What I was wondering is if it is possible to load the filter from an embedded resource when the application is run? I am trying to avoid needing administrator privileges to register the filter.
Edit:
Ok I'm trying to use this information and come up with a solution. You will have to excuse my lack of knowledge in the DirectShow area. I did not write the filter, I am just trying to come up with a solution using it. I am trying to do a little more research so I understand DirectShow and its components a little better.
I found a handy ComHelper class that I'm using to load the filter.
https://gist.github.com/jjeffery/1568627
I am using the code below to create an instance of the filter.
LibraryModule module = LibraryModule.LoadModule(#"filter.ax");
var comObject = ComHelper.CreateInstance(module, new Guid("c91aa7be-f627-46e3-b79f-2de55da46a8b"));
Is this correct? I'm trying to figure out where to go next. How would I use this to build the filter graph?
Building a filter graph using unregistered filters is possible, but you have to be aware of obstacles and then decide whether it is acceptable or not.
DirectShow filters are COM objects with relaxed requirements for threading. That is, adding filters to graphs does not require full COM registration. Graph's IGraphBuilder::AddFilter will accept an interface pointer of your filter without asking you how you obtained it. This means in particular that if you take care of filter instantiation and then you build the graph manually adding filter and connecting pins - this will definitely work out well.
Filters, that you don't want to be registered, can be otherwise instantiated by creating C++ object directly, or by loading DLL and using its DllGetClassObject exported function the way COM would do it with instantiation through registration.
Another note is that COM class can be registered "per-user" without need to have administrator privileges, and such registration enables standard CoCreateInstance instantiation (but not Intelligent Connect - see below).
The typical problem on the way is scenario when you expect a filter of your interest, such as video/audio decoder, to be added automatically via DirectShow Intelligent Connect. This only works with full COM registration, or the alternate option is API hooking which I omit here. To cut long story short: if you are not registering the filters, you have to instantiate and add them to the filter graph yourself, via code.
A final note on embedding. The filter will still be hosted by DLL, so you will have to load executable code into memory. This means that you cannot load it "from resource" directly. Although there are certain methods to build executable DLL image right in memory, the easiest would be to keep filter DLL with you and load it as regular DLL from external file using LoadLibrary. If you prefer to have single binary, you can embed the DLL as binary resource, then extract into temporary file on runtime and then continue with LoadLibrary from there.
See also:
How can I directly embed a DirectShow Push Source filter in an EXE?
C# Register Embedded Directshow Filter
Can I make my private DirectShow filter discoverable by Moniker by external programs?

How do I put and replace a file using in a client machine in a Silverlight app?

I'm trying to make a Silverlight app which has a local sqlite file to search some data when the app gets offline. I found the following library, http://code.google.com/p/csharp-sqlite/ and it seems pretty nice.
So, what I want to know is, what is a good approach to have and place a file which might be replaced by automatically when the data in a server gets updated at some points?
I've tried to put a file into a folder under the app, but I couldn't access to the file by using csSQLite.sqlite3_open (This method is from the library above). Sorry, I'm pretty new to Silverlight, so my question might be very odd.
Thanks in advance,
yokyo
It doesn't look like this library has been specifially coded for Silverlight. Despite being a pure C# implementation its still likely to assume the full .NET API is available. This is not true in Silverlight.
Specifically Silverlight cannot ordinarily access the local file system. The SQLLite code would need to be modified to understand Silverlight's IsolatedStorage. It would also have to limit its file operations to those that are supported by the streams available Isolated Storage.
The creation of a DB-esq. data source in Silverlight is typically done by create Classes the represent records and collections of records, using LINQ to query them and Xml serialisation into Isolated storage to persist them.
Here is a hacked version of the SQLite code to work with Silverlight, you can use it for some ideas on what to do: http://www.itwriting.com/blog/1695-proof-of-concept-c-sqlite-running-in-silverlight.html

How do I load a module catalog from a database in Prism?

I'm using Prism in my WPF application and up to now, I've been loading the modules via var moduleCatalog = new ConfigurationModuleCatalog();. I'd like to get the module catalog from a database. The Prism documentation indicates that this is possible, but it doesn't go into any details.
Has anyone done this and can provide some guidance?
This is a theoretical possibility, but it's not in any samples I've seen.
Basically what you'd do is either base64 encode the DLLs / Files into the database or zip them up and store them in one blob. You'd download them in your bootstrapper and copy them locally (in a temp directory) and then allows them to load normally from the filesystem using the DirectoryModuleCatalog. If you wanted it to be a bit more elegant, you could write your own ModuleCatalog that encapsulates this logic.
This is very similar to what I do... I actually download a zip file of all of the modules from a website at launch time and unzip them and load them with the DirectoryModuleCatalog.
You can write your own ModuleCatalog implementation by implementing IModuleCatalog. Your implementation can then populate the catalog by any means you define.
You could also use the CreateFromXAML overload that accepts a Stream and implement a webservice that delivers the ModuleCatalog in XAML over HTTP.

Resources