axodox / axodox-machinelearning

This repository contains a pure C++ ONNX implementation of multiple offline AI models, such as StableDiffusion (1.5 and XL), ControlNet, Midas, HED and OpenPose.
MIT License
605 stars 35 forks source link

Is it possible to use library without WinRt? #9

Closed alex-aparin closed 1 year ago

alex-aparin commented 1 year ago

Recently I tried to use library in my console application. It is important to note that application is not UWP based. Unfortunately I encountered error - Exception thrown at 0x00007FFD7857CF19 (KernelBase.dll) in Console.exe: WinRT originate error - 0x80073D54 : 'The process has no package identity.'. It seems like that WinRt restricts model of application. Is there any way to exclude usage of Winrt? or another way to combine WinRt library with non uwp application?

axodox commented 1 year ago

Can you send the stack trace?

Most WinRT APIs do not require a package identity or UWP, however I might have made a mistake in the code.

alex-aparin commented 1 year ago

It originates when I am trying to create OnnxEnvironment. image

axodox commented 1 year ago

Oh, well... I messed it up with the WinRT logging. Please commit out the logger in the header and where it is used, I will push a fix for it later.

alex-aparin commented 1 year ago

Thank you very much! It's awesome how you instantly reply on issue

axodox commented 1 year ago

FYI this is the issue: https://github.com/axodox/axodox-common/blob/main/Axodox.Common.Shared/Infrastructure/Logger.cpp We will need to surround this part with an #ifdef UWP or similar: image

alex-aparin commented 1 year ago

@axodox Do you mean usage of some macro UWP? Which will disable subset of UWP related API?

alex-aparin commented 1 year ago

By the way the first thing which confused me was also includes.h file. image It includes many winrt related features (I did not investigate their usage yet)

axodox commented 1 year ago

I will need to read up on this, it seems that the logging API requires package identity. To clarify package identity != UWP, though all UWP apps have package identity. Also WinRT != UWP.

UWP is application model which runs the app in an isolated container. WinRT is a new familily of Windows APIs it is not tied to UWP, it works in any app. Package identity is tied to MSIX packages, it is not tied to UWP or WinRT.

There are some APIs which require a package identity. There are APIs to check if the app has package identity, so probably it won't be an #ifdef, just an if with a check for package identity. I think there is also some API to add package identity to apps which do not have it, but I never tried that in action.

axodox commented 1 year ago

So no the includes are fine, I have used WinRT in a normal unreal engine app (so not UWP, no MSIX), and had no issue. But sometime you run into an API which requires package identity, which is not immediately obvious by looking at it.

alex-aparin commented 1 year ago

Thank you, I grasped the idea. It will help me hugely to diagnose next possible errors

axodox commented 1 year ago

One thing to look out for, that you will need to reference the nuget packages from DirectML and ONNX runtime, as well as have the model files, and also the clip_tok.onnx and ortextensions.dll from my nuget.

I plan to refine the nuget later to require these dependencies and copy the mentioned files automatically. Until that just look at how Unpaint does it.

alex-aparin commented 1 year ago

@axodox yep. I have ran into that dependencies. But I temporary included my project within axodox-machinelearning solution. Later I will refactor it.

p.s. Minor update: Logger was the only issue. I commented it, and application was executed without any problems. So library can be used in projects without complex dependencies like uwp etc.