kritiksoman / GIMP-ML

AI for GNU Image Manipulation Program
https://kritiksoman.github.io/GIMP-ML-Docs/index.html
MIT License
1.39k stars 127 forks source link

Use Torch Hub format, GIMP handling refactor, clarify license and reference details #12

Closed valgur closed 3 years ago

valgur commented 4 years ago

Hi! This PR introduces three significant overall changes.

Using Torch Hub for model management

The current approach to providing models and sharing their weights kind of works but has some serious limitations:

With that in mind, PyTorch offers a convenient and consistent way to publish and use existing models + weights via their torch.hub format (with corresponding central PyTorch Hub). Loading a model is as easy as doing

model = torch.hub.load('pytorch/vision:v0.6.0', 'deeplabv3_resnet101', pretrained=True)

Unfortunately, publishing models in this format is not too popular yet and is quite underutilized. This can be worked around quite simply, though, by forking any interesting repo to refactor the code as needed, add hubconf.py and re-publish the model weights in a more suitable format as a release under the forked repo.

So, I did just that for all of the models used by GIMP-ML:

With this, the bundled model source code dirs, downloading weights.zip and using moveWeights.sh is no longer needed. Instead, the models are downloaded on the fly as necessary and with no work required by the user. I also added a hook to tqdm to get a nice indication of weight download progress directly in GIMP:

model_dl_progress

So, this solves all of the mentioned issues and more:

Along with these changes I also improved and cleaned up the input/output handling code in the plugin scripts somewhat. Notably:

Refactoring of GIMP wrapper code

I consolidated the GIMP<->NumPy wrapper code to shared functions under _util.py and added correct handling of layers with alpha channels. Also got rid of from gimpfu import * as it was fragile and caused frequent clashes between PIL.Image and gimpfu.Image.

Alpha channels are now removed from input images for processing and re-applied to the result automatically. The plugin input format types are now also correctly specified as RGB* or GRAY* accordingly to avoid confusing silent errors for the users. Fixes #8.

License, authors info and improved model references

The repo is in sore need of a license (as also mentioned in #11). The lack of it prevents any serious re-use, extension and collaboration on the project. And I personally like the idea behind this project a lot and would like to see it flourish and the number and variety of included models grow.

With the individual models now residing in separate repos with this PR, applying a license to the repo becomes straightforward. I propose adding a permissive MIT license and I already included one in this PR. Any changes in this PR are also licensed accordingly.

With the considerable input from this PR in mind, which is closer to a re-write than a patch, really, I also added myself as one of the contributors to the project in the readme. I hope you find it fair. I would also like to continue the collaboration in the future as well anyway, particularly by adding support for even more DL models now that it is much simpler. Besides that, the contributor credits are needed by nearly all open-source licenses as well.

I also extended and re-organized the model references somewhat. The most notable difference is again the addition of license details, which is a quite important detail for end-users since many of the models only allow non-commercial or research-only use.

If you have any comments or would like to approach something differently, let me know. I am open to any discussion.

kritiksoman commented 3 years ago

Sorry we were not accepting PR as GIMP was transitioning to python3 and python2 was already deprecated. If you are interested, please contribute to this branch which is meant for python 3.