Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gimp Python-fu 2.7 to launch Python 3 for editing images
#1
Lightbulb 
On windows 10 you can open up python-fu console in gimp and launch a python 3 terminal.

Code:
from subprocess import call
call(["C:/Users/audov/AppData/Local/Programs/Python/Python36/python.exe"])
If you have python 3.6 that will launch it and when you close that console it gets an exit code back. If you close python 3 by typing exit() the exit code is 0. If you just close the terminal you get -1073741510.

But if I try to pass in additional arguments about what python file to run then I get problems. For example if I run this.
Code:
from subprocess import call
call(["C:/Users/audov/AppData/Local/Programs/Python/Python36/python.exe", "D:/Projects/neural-style-master/neural_style.py"])
I get an exit code of 1 and the terminal opens but immediately closes.

If I were to run the same thing by running python 2.7 and then run this.
Code:
from subprocess import call
call(["C:/Users/audov/AppData/Local/Programs/Python/Python36/python.exe", "D:/Projects/neural-style-master/neural_style.py"])
Then from python 2.7 it launches the specified script using python 3.6. By then typing exit() I end up back in python 2.7.
----------------------------------------------------------------
But Why
----------------------------------------------------------------
The reason I want to do all this is so that I can write a plugin that sends a specified image or set of images to a command line program written for python 3.6. I would then either directly pass back the modified images or save them to a temp file, and then pass back the path.

The reason I need it to be python 3 is because of the use of Tensorflow and similar deep learning image processing libraries. Tensorflow both has useful projects written for it and approaches being easy to install on Windows, Mac, and Linux but it needs python 3.6.

The reason Tensorflow would be useful is there are projects like these Github projects.
https://github.com/anishathalye/neural-style
takes about 5 minutes to process an image with a gpu.

https://github.com/Eyyub/tensorflow-pix2pix
takes about 20 seconds to initialize and then about 2 seconds to process each image.

https://github.com/lengstrom/fast-style-transfer
takes 2 seconds to under a second to process an image.

All of which can make a wide range of innovative changes to images.
Integrating them into a program like gimp would greatly aid their integration into a broader creative process. As it stands now using something like neural-style requires a command line argument like...

D:/Projects/neural-style-master/neural_style.py --network D:/Projects/neural-style-master/imagenet-vgg-verydeep-19.mat  --checkpoint-output "D:/Projects/neural-style-master/temp/temp.png" --iterations 600 --style-scales 1.0 --content-weight-blend 1.0 --content-weight 5.0 --style-weight 500.0 --tv-weight 100.0 --pooling avg --width 512 --content "D:/tile/nature256/nature_00312.png" --styles "D:/tile/nature256/nature_01111.png" --output "D:/tile/temp/nature_00312.png_nature_01111.png.png"

There are efforts to integrate projects like these into a gui but it would be far preferable to make it into a plugin for something like gimp.
---------------------------------------
If what I am trying to do is not possible I am open to trying to do it another way.

The most extreme solution I can think of would be adding a python 3 version of python-fu.
I read somewhere that it was very important to keep python-fu as 2.7 because of plugin comparability. That seems very reasonable.
The same poster however said that there was nothing to stop adding python-fu 3 as a separate plugin. According to them the only reason it was not done already was because there was no great interest from the community to work on adding that feature.
Reply


Messages In This Thread
Gimp Python-fu 2.7 to launch Python 3 for editing images - by audovoice - 11-12-2018, 09:03 AM

Forum Jump: