Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import the models into Chainer #420

Open
CuteZombie7 opened this issue Mar 29, 2022 · 9 comments
Open

import the models into Chainer #420

CuteZombie7 opened this issue Mar 29, 2022 · 9 comments

Comments

@CuteZombie7
Copy link

https://github.com/tsurumeso/waifu2x-chainer
This is the Chainer implementation of waifu2x, but cunet models haven't been added to this project.
Is there any way to convert original luatorch models to Chainer models? It would be very helpful to me.

@nagadomi
Copy link
Owner

nagadomi commented Mar 29, 2022

The following repository has PyTorch implementations of vgg_7, upconv_7, and cunet (training does not work due to inplace_clip gradient issue).
It is not difficult to convert to Chainer model, I think.
https://github.com/nagadomi/nunif/tree/master/nunif/models/waifu2x

Also, waifu2x-caffe supports both cunet and upresnet10. It does not support training, though.

@CuteZombie7
Copy link
Author

I want to deploy the cunet model to that project, and just use it for inference. And now, the problem is how to convert t7 format to npz format. The models in that project are all in npz format.

@nagadomi
Copy link
Owner

  1. port from pytorch model to chainer model
  2. load model parameters from the json file into the chainer model (json file can be loaded in Python and contains the same data as t7).
  3. serialize the chainer model parameters in npz format.

ref. code that loads the json file into the pytorch model.
https://github.com/nagadomi/nunif/blob/eab6952d93e85951ed4e4cff30cd26c09e1dbb63/nunif/models/load_save.py#L10-L28

@CuteZombie7
Copy link
Author

thank you, I will have a try.

@CuteZombie7
Copy link
Author

Is there any .caffemodel file of cunet? So that I can directly use CaffeFunction to convert it. I'm a novice in deep learning, it's too difficult for me to port it at the code level, because I'm familiar with neither of the frameworks.

@nagadomi
Copy link
Owner

waifu2x-caffe has it. The following threads may be helpful.
lltcggie/waifu2x-caffe#115

@CuteZombie7
Copy link
Author

/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/chainer/links/caffe/caffe_function.py:165: UserWarning: Skip the layer "input", since CaffeFunction does not support Input layer
'support %s layer' % (layer.name, layer.type))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/chainer/links/caffe/caffe_function.py:165: UserWarning: Skip the layer "Flatten1", since CaffeFunction does not support Flatten layer
'support %s layer' % (layer.name, layer.type))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/chainer/links/caffe/caffe_function.py:165: UserWarning: Skip the layer "Crop1", since CaffeFunction does not support Crop layer
'support %s layer' % (layer.name, layer.type))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/chainer/links/caffe/caffe_function.py:165: UserWarning: Skip the layer "Flatten2", since CaffeFunction does not support Flatten layer
'support %s layer' % (layer.name, layer.type))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/chainer/links/caffe/caffe_function.py:165: UserWarning: Skip the layer "Flatten3", since CaffeFunction does not support Flatten layer
'support %s layer' % (layer.name, layer.type))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/chainer/links/caffe/caffe_function.py:165: UserWarning: Skip the layer "Crop2", since CaffeFunction does not support Crop layer
'support %s layer' % (layer.name, layer.type))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/chainer/links/caffe/caffe_function.py:165: UserWarning: Skip the layer "Flatten4", since CaffeFunction does not support Flatten layer
'support %s layer' % (layer.name, layer.type))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/chainer/links/caffe/caffe_function.py:165: UserWarning: Skip the layer "Crop3", since CaffeFunction does not support Crop layer
'support %s layer' % (layer.name, layer.type))
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/chainer/links/caffe/caffe_function.py:165: UserWarning: Skip the layer "Crop4", since CaffeFunction does not support Crop layer
'support %s layer' % (layer.name, layer.type))
------------------------------OK-----------------------------
2.0x scaling... Traceback (most recent call last):
File "waifu2x.py", line 270, in
main()
File "waifu2x.py", line 245, in main
args, dst, models['noise_scale'], models['alpha'])
File "waifu2x.py", line 47, in upscale_image
dst = reconstruct.image(dst, model, cfg.block_size, cfg.batch_size)
File "/home/aistudio/work/waifu2x-chainer/lib/reconstruct.py", line 135, in image
dst = blockwise(src, model, block_size, batch_size)
File "/home/aistudio/work/waifu2x-chainer/lib/reconstruct.py", line 52, in blockwise
batch_y = model(batch_x)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/chainer/link.py", line 287, in call
out = forward(*args, **kwargs)
TypeError: forward() missing 1 required positional argument: 'outputs'

It seems that caffeFunction doesn't surpport some layers. Is there any way to solve this problem? Or should i port the model at code level ? :(

@nagadomi
Copy link
Owner

nagadomi commented Apr 1, 2022

I am not familiar with the chainer code, but the documentation says the following:

It does not support full compatibility against Caffe. Some layers and configurations are not implemented in Chainer yet, though the reference models provided by the BVLC team are supported except data layers.
https://docs.chainer.org/en/v7.8.0/reference/generated/chainer.links.caffe.CaffeFunction.html

Also, chainer has already decided to discontinue development.

@CuteZombie7
Copy link
Author

All right. I will go on to port the model at code level. Since i want to install waifu2x on a platform where torch, caffe and some other frameworks are banned, chainer is the only choice, maybe. And thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants