chaiNNer-org / chaiNNer

A node-based image processing GUI aimed at making chaining image processing tasks easy and customizable. Born as an AI upscaling application, chaiNNer has grown into an extremely flexible and powerful programmatic image processing application.
https://chaiNNer.app
GNU General Public License v3.0
4.47k stars 279 forks source link

model converter (to NCNN) #1328

Closed hat3l0v3 closed 1 year ago

hat3l0v3 commented 1 year ago

Hello, i'm not a programmer I just want to rip and upscale some anime so I just want to ask if someone can solve the problem I have. I want to convert models to NCNN format to run them with Real-Esrgan (that I used by command line). I used Cupscale model convertor for some models before and it works fine (its gives me same result but almost twice faster time when I using Real-Esrgan). To see why im doing it - here my tests (with gtx1060) :

##########################################
########## LD-Anime_Skr_v1.0 #############
##########################################
cupscale  ncnn  40frames - 712s
1frame =17,8s
realEsrgun      40frames - 436s
1frame =10,9s
-39% difference

chaiNNer  ncnn  30frames - 600s
1frame =20s

I dont know whats the reason behind it (dont really care) but it works faster.

So I just want to run some test with interpolated models and convert it to NCNN format that Real-Esrgan can read. ( I apologise in advance, maybe its impossible for some reason or anything like that )

Issue: when I convert model to NCNN by chaiNNer ( LD-Anime_Skr_v1.0 for example ) and run through Real-Esrgan it gives me error :

find_blob_index_by_name data failed
Try
    ex.input("input", in0);

Mr. mafiosnik777 tried to help by changing some input name or something in .param file but it doesn't help. So I made post here.

I can add Cupscale and ChaiNNer .param files to compare, but I see that .bin files are different too. Maybe someone can find solution to make ChaiNNer converter work fine in my case? Even If it takes to modify .param file manually by hand.

hat3l0v3 commented 1 year ago

Oh I forgot to add, when I try to interpolate models and save them as .pth and then convert them in Cupscale it gives me error like that:

Failed to convert Pytorch model to NCNN format! It might be incompatible.

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

Stack Trace:
   в Cupscale.OS.NcnnUtils.<ConvertNcnnModel>d__6.MoveNext()

The error message was copied to the clipboard.

So this option doesn't work for me.

joeyballentine commented 1 year ago

Hi. We use the input and outputs names of "input" and "output" respectively when we convert to onnx and then to ncnn. The real esrgan command line is hardcoded to look for an input named "data", which is how their models are converted. Realistically, they should just be parsing the param to detect the input name automatically (which is what we do in chaiNNer, which is why their ncnn models will work in chaiNNer but ours don't work there).

So, this is really an issue for them to solve by not hardcoding that. I don't want to change our code just because theirs is bad.

joeyballentine commented 1 year ago

Thinking about it some more, I'm fairly confident that the real-esrgan team will never actually change this and will probably just ignore you if you ask about this, so I'll consider changing it here.

hat3l0v3 commented 1 year ago

So could I change models manually or its not just renaming A to B ( as I see it is ) Because if it's just renaming A to B that must be not a problem to make some program that will do it automatically.

joeyballentine commented 1 year ago

I'm not sure what it takes for you to change it yourself, all i know is what in the code i would need to change for future models to work.

joeyballentine commented 1 year ago

If you want to try though, replace every instance of the word "input" in the .param file with the word "data". But idk if that's all that it would need

hat3l0v3 commented 1 year ago

Thank You very much, its work very fine. All I need is renaming 3 out of 4 inputs (Ignoring the 1st one) 222

will be great if someone can do something like .bat file that can do it automatically.

I can go and test interpolated models now 😊

hat3l0v3 commented 1 year ago

I allready made 1 test. I took two models, interpolate them 20%-80% and run through chainner and real-esrgan. chainner took 786s per 40frames, when real-esrgan only 482s. same 39% difference. thank you very much.🤗