dcscn-super-resolution icon indicating copy to clipboard operation
dcscn-super-resolution copied to clipboard

Possible to export to Android

Open gitman88 opened this issue 6 years ago • 21 comments

Is it somehow possible to export this model for Android use? I guess it might be doable with Tensorflow Mobile or Tensorflow Lite. Then it would be needed to get hold of checkpoints files (.cpkt) as well as a frozen graph?

gitman88 avatar Feb 05 '19 09:02 gitman88

Hi, I'm also curious about porting to mobile. A year ago I have tried TensorFlow RT with freezer graph. But I believe Tensorflow Lite is the we should use? In this case do we just need to convert the checkpoint file??

jiny2001 avatar Feb 05 '19 13:02 jiny2001

Yes, Tensorflow Lite is the new framework for this. Both checkpoint files (.cpkt) and a graph def (.pb) is needed to get a freezed graph. This freezed graph can be used (and also optimized) to a Tensorflow Lite file.

gitman88 avatar Feb 06 '19 11:02 gitman88

So, do you mean you want to add freezed graph output feature on this project? Or you just want to confirm if it just runs directory under tensorflow lite?

jiny2001 avatar Feb 07 '19 15:02 jiny2001

Well, I was wondering how you would manage to get a frozen graph from the existing model. The checkpoint files should not be a problem but the graph def (.pb) is not as straight forward.

You can see how the structure for converting looks here (visualized): https://www.tensorflow.org/lite/convert

gitman88 avatar Feb 08 '19 06:02 gitman88

Well,,, when I tried freeze_graph function on the other project, I just used this freeze_graph.py. And it worked for TF RT. I succeed to make it run on Mac witch C++ in realtime. Sorry for not sure about TF Lite.

But I believe you can also check freeze_graph_test.py so that you can export it as freezed graph.

jiny2001 avatar Feb 10 '19 19:02 jiny2001

Okey, thanks! But for example when trying to use the function you provided you need to know output_node_names and in other similar functions also input_nodes. How do you get hold of those? In Tensorboard the graph got a node called output for instance which contains 5 different outputs. Do you know what do provide as output_node_name?

Y_/output/Mean ?×?×?×1 Y_/output/sub ?×?×?×1 diff ?×?×?×1 gradients/diff_grad/Shape ?×?×?×1 Y_/output/dcscn_L8_F96to48_NIN_A64_PS_R1F32

gitman88 avatar Feb 11 '19 13:02 gitman88

Hi, sorry for late reply. I'm so busy these days... Yes you need the name of the last output node. I think what you want to use is this node. https://github.com/jiny2001/dcscn-super-resolution/blob/master/DCSCN.py#L265

In this case, the name is just "output". Please try it.

jiny2001 avatar Feb 12 '19 20:02 jiny2001

I ported to pure keras https://github.com/iperov/DeepFaceLab/blob/master/imagelib/DCSCN.py real model size is 6mb without optimizer weights works on plaidML backend

iperov avatar Mar 28 '19 18:03 iperov

I applied DCSCN in DeepFaceLab,

before/after gif 2019-03-28_17-36-57

iperov avatar Mar 28 '19 18:03 iperov

Wow!! hi iperov, this is AWSOME!!

I guess you can see the super resolution result better when you use an image which has more clear edges (the sample face image has blurred so it's hard to see the difference). However, the project is also awesome. I pushed a star on your project and will add to my readme that you can use my model via your project. Thank you so much!!

jiny2001 avatar Mar 29 '19 23:03 jiny2001

@jiny2001 is DCSCN better than for example SRGAN ? did you compare? do you know any superresolution network that will work better for blurred images? do you know any superresolution network that can add details/texture to blurred images?

iperov avatar Mar 30 '19 11:03 iperov

Hi, if you compare DCSCN and SRResNet, SRResNet will have a better result. However, it might be difficult to see the difference from human eyes. And also normal SR network won't work better on blurred image.

SRGAN will normally have less PSNR than other SR networks, however, they generate details/texture and makes it more "natural" so it might work on blurred image. But I haven't tested. For the face super resolution, I believe those papers are the best for now. But it only works in certain angle and resolution I guess. http://openaccess.thecvf.com/content_cvpr_2018/CameraReady/1035.pdf https://arxiv.org/pdf/1711.10703.pdf

Anyway, I guess you can try SRGAN since there are some implementations in github. Thx.

jiny2001 avatar Mar 30 '19 20:03 jiny2001

my opinion is that all SRs are actually trained to restorate downscaled images, so these images have high density of "details per pixel". But real world images are not downscaled images :D

especially bicubic downsampled image has more information about upscaled image than bilinear or nearest-neighbor. So why to train SR to restorate images that already have more information than real world image? My suggestion to train x2 DCSCN upscale network on x4 nearest neighbor downscaled (random offset 1-4px), then x2 bilinear upscaled images

iperov avatar Mar 31 '19 04:03 iperov

You are right. I agree I should train from bilinear. I'm just using bicubic because every other people use it and I can compare the performance with it. let me know if you can point me a nice training data set. I can try it with bilinear downsampling. ;)

jiny2001 avatar Apr 02 '19 05:04 jiny2001

Okey, thanks! But for example when trying to use the function you provided you need to know output_node_names and in other similar functions also input_nodes. How do you get hold of those? In Tensorboard the graph got a node called output for instance which contains 5 different outputs. Do you know what do provide as output_node_name?

Y_/output/Mean ?×?×?×1 Y_/output/sub ?×?×?×1 diff ?×?×?×1 gradients/diff_grad/Shape ?×?×?×1 Y_/output/dcscn_L8_F96to48_NIN_A64_PS_R1F32

have you found the input node name?

ricardobnjunior avatar Apr 08 '19 20:04 ricardobnjunior

2019-04-14_21-18-47

iperov avatar Apr 14 '19 17:04 iperov

Hi @ricardobnjunior, sorry for late reply. The input node is the one which is defined as placeholder, the name is "x". I guess you have found this already though...

Hi @iperov, the result is really awesome!! Great!! I guess much much smaller model will also work if it focused on face super resolution. Which will greatly improve processing speed. Will try it when i have a time. Thx!!

jiny2001 avatar Apr 29 '19 01:04 jiny2001

Hi @ricardobnjunior, sorry for late reply. The input node is the one which is defined as placeholder, the name is "x". I guess you have found this already though...

Hi @iperov, the result is really awesome!! Great!! I guess much much smaller model will also work if it focused on face super resolution. Which will greatly improve processing speed. Will try it when i have a time. Thx!!

Yes, I found! Thank you for reply ;)

ricardobnjunior avatar Apr 29 '19 13:04 ricardobnjunior

@ricardobnjunior, have you succeeded in converting the model to TFLite?

djalusic avatar Dec 12 '19 13:12 djalusic

my opinion is that all SRs are actually trained to restorate downscaled images, so these images have high density of "details per pixel". But real world images are not downscaled images :D

especially bicubic downsampled image has more information about upscaled image than bilinear or nearest-neighbor. So why to train SR to restorate images that already have more information than real world image? My suggestion to train x2 DCSCN upscale network on x4 nearest neighbor downscaled (random offset 1-4px), then x2 bilinear upscaled images

@iperov Could you please explain further about the rationale behind suggesting this - "x4 nearest neighbor downscaled (random offset 1-4px), then x2 bilinear upscaled images"

Nik-Khandelwal avatar Mar 04 '20 09:03 Nik-Khandelwal

@Nik-Khandelwal

main idea is remove more information from downscaled image about it upscaled version, therefore neural network will not learn to fetch that info

iperov avatar Mar 04 '20 16:03 iperov