RedAuburn / batch-colourise-and-transfer-colour

A Python script to batch colourise photos using DeOldify through the DeepAI API and transfer colour to the high res original.
MIT License
0 stars 0 forks source link

local ai file #5

Open sohmee opened 3 years ago

sohmee commented 3 years ago

Hello, I have many thousands of images to colour but using deepai.org is quite slow. Could your code be easily made to work from a local ai file like PySimpleGUI-Photo-Colorizer which uses colorization_release_v2.caffemodel? Thanks

RedAuburn commented 3 years ago

In it’s current state, unfortunately not

It could probably be modified to do it though, you’d have to replace the HTTP request with a function that can interact with the AI, and optionally downscale the image to speed up processing (deepai does this server-side)

I’ll look into it tomorrow :)

sohmee commented 3 years ago

That would be awesome. Thanks :)

RedAuburn commented 3 years ago

A few issues I've found:

PySimpleGUI-Photo-Colorizer uses a different, older model that isn't as good, but it would be easier to implement.

Unfortunately, i think making it work is out-of-scope for this repo as it was only meant to be a simple batching script to interact with the DeepAI API.

I've added a timer between the different sections of the code (ccaf602ccbcc655dffeb1bade27e4dea7a67c29e) so at least you can diagnose what is taking a long time to process. if you post the results i'll see if i can optimise that section :)

the result should look like this:

time to recieve API response: 3.51s
time to generate new path: 1.35s
time to blend colour with highres: 0.53s
sohmee commented 3 years ago

Thanks for helping out. Overall your code is fantastic and has done the job really well, Originally I was looking for a method to convert some old black and white videos to colour so I'm breaking the videos down to frames but I end up with 1000s of images for short video. There is probably easier ways of doing the video processing to colour but in this case I used ffmpeg to break the video into frames then after the colourization ffmpeg again to make the video again. This is what I ended up with, it took around 10 hours to do as there were over 3000 frames https://www.youtube.com/watch?v=aYkkrJ-hffY I have pasted the output of the new script below.. using: 1 0002.jpg {'id': '558126ff-463b-4ce2-8b42-0cf01c8fb257', 'output_url': 'https://api.deepai.org/job-view-file/558126ff-463b-4ce2-8b42-0cf01c8fb257/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 3.91s time to generate new path: 2.46s time to blend colour with highres: 0.18s using: 1 0003.jpg {'id': '51847b5d-ce9a-4b67-84c5-937c6647c3fc', 'output_url': 'https://api.deepai.org/job-view-file/51847b5d-ce9a-4b67-84c5-937c6647c3fc/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 3.58s time to generate new path: 3.18s time to blend colour with highres: 0.08s using: 1 0004.jpg {'id': 'a0612ac4-3dfd-4963-bca2-1cc36238571f', 'output_url': 'https://api.deepai.org/job-view-file/a0612ac4-3dfd-4963-bca2-1cc36238571f/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 4.71s time to generate new path: 5.32s time to blend colour with highres: 0.08s using: 1 0005.jpg {'id': 'fa771860-71b2-4934-9602-94872ba55284', 'output_url': 'https://api.deepai.org/job-view-file/fa771860-71b2-4934-9602-94872ba55284/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 5.05s time to generate new path: 4.82s time to blend colour with highres: 0.08s using: 1 0006.jpg {'id': 'ddee470f-c93d-4977-bd26-2965a6498473', 'output_url': 'https://api.deepai.org/job-view-file/ddee470f-c93d-4977-bd26-2965a6498473/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 3.71s time to generate new path: 3.85s time to blend colour with highres: 0.09s using: 1 0007.jpg {'id': '09c026b6-1838-4036-b9e6-2e796c77d2f2', 'output_url': 'https://api.deepai.org/job-view-file/09c026b6-1838-4036-b9e6-2e796c77d2f2/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 3.77s time to generate new path: 3.86s time to blend colour with highres: 0.09s press enter to exit

using: 1 0002.jpg {'id': '558126ff-463b-4ce2-8b42-0cf01c8fb257', 'output_url': 'https://api.deepai.org/job-view-file/558126ff-463b-4ce2-8b42-0cf01c8fb257/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 3.91s time to generate new path: 2.46s time to blend colour with highres: 0.18s using: 1 0003.jpg {'id': '51847b5d-ce9a-4b67-84c5-937c6647c3fc', 'output_url': 'https://api.deepai.org/job-view-file/51847b5d-ce9a-4b67-84c5-937c6647c3fc/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 3.58s time to generate new path: 3.18s time to blend colour with highres: 0.08s using: 1 0004.jpg {'id': 'a0612ac4-3dfd-4963-bca2-1cc36238571f', 'output_url': 'https://api.deepai.org/job-view-file/a0612ac4-3dfd-4963-bca2-1cc36238571f/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 4.71s time to generate new path: 5.32s time to blend colour with highres: 0.08s using: 1 0005.jpg {'id': 'fa771860-71b2-4934-9602-94872ba55284', 'output_url': 'https://api.deepai.org/job-view-file/fa771860-71b2-4934-9602-94872ba55284/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 5.05s time to generate new path: 4.82s time to blend colour with highres: 0.08s using: 1 0006.jpg {'id': 'ddee470f-c93d-4977-bd26-2965a6498473', 'output_url': 'https://api.deepai.org/job-view-file/ddee470f-c93d-4977-bd26-2965a6498473/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 3.71s time to generate new path: 3.85s time to blend colour with highres: 0.09s using: 1 0007.jpg {'id': '09c026b6-1838-4036-b9e6-2e796c77d2f2', 'output_url': 'https://api.deepai.org/job-view-file/09c026b6-1838-4036-b9e6-2e796c77d2f2/outputs/output.jpg'} starting colour image scaling... finished colour image scaling

starting image blending... finished image blending

time to recieve API response: 3.77s time to generate new path: 3.86s time to blend colour with highres: 0.09s press enter to exit