Any way to process batches of images? #104
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I like being able to use this on single images, however, if I have 10 images I want to map one face to, I have to go through individually, one by one. After one is completed, I have to rename it to save it being overwritten during the next process.
Is there a command I can use to process one face to a folder of images?
If not, could we get this in a future update?
Thankyou.
I didn't test this but it should work. Instead of swapping to an image directly, you just use the path where the images are.
On line 1 in test_one_image.py, add
import os186a57aa96/test_one_image.py (L1)From lines 40-86 in test_one_image.py, replace this:
186a57aa96/test_one_image.py (L40-L86)With this:
Excuse me, how would you do a command to execute this? Could you provide an example? Thanks in advance!
THANKS!!!And
How to modify test_wholeimage_swapsingle.py?
I created a handy script to do this:
Put it in your simswap directoy, and run it like so:
python batch_process.py bob
This will face swap all images in the ./input_faces directory on to the videos in the ./input_videos directory. It should be easy to modify the commands if you want to do the different functions.
Thanks, this worked flawless, however there's an issue when modifying it to utilize the image scripts. They're designed to write to a specific file name, so when you process a whole batch of images, it's just overwriting the same file over and over. Not sure how I can change this behavior to write to a unique file for every process like with the scripts for video.
@watertau I have actually modified this script a bunch of times since then and that was one of the problems. I've also added the ability to just generate the command, so that you can copy them and batch process long videos overnight.
I dont have it on this machine but I will update this thread with the new script asap.
@chud37 Thanks for all your efforts! I have absolutely no affinity for coding, so it's pretty daunting to me just to even troubleshoot this, you know? I've been running a program to monitor and capture newly created jpg files and auto rename them. Works well enough, but that feels like a janky solution and not really ideal.
This is my latest code:
You'll need to put it into the same directory as /simswap. Set save the file above (i.e. batch_simswap.py) and run it from the simswap directory like
python batch_simswap bob.Note: Make sure you edit the file first to set up the directories. You'll need to put your faces inside the ./input_faces path (again, inside the simswap directory) and change the video input path and the video output path. I added a feature today that creates a new folder with the face name and date i.e. c:/simswap/output/bob/09-26-2021. So all new videos go in their own folder, under the face name. I also created a script to speed up the multispecific faces if anyone wants that too.
Thanks so much! I tried it on batch processing videos, which worked great. I tried fiddling with your script so that it would work with batch processing images (pic a to pic b) but kept running into errors. Any chance you could adjust your script for images?
@drzodozo I've tried writing the script that batch process images but for some reason the actual image isn't being processed due to errors. It queues it up and everything just doesnt actually do it. Here is the code:
If you get it running, let me know. It is just a modified version of the video one. There are different
simswap_commandvars that could try swapping in and out to see if they work okay.Thanks, @chud37. I had the same issues with the errors regarding patches and write permissions when I tried tweaking your original code. When I swap images manually, they get outputted correctly, but get the same patch error messages (they don't seem to affect the output).
But when I try the batch process script (that I tweaked), I get the same permission errors and nothing seems to happen. The folders are being written with the correct dates so I'm dumbfounded by the write permission error. I'll try your new script and see what happens.
Tried your script, and unfortunately ran into the same problems. The folders write fine, but the output image file just isn't there.
Hi! First of all, I want to say big thank @chud37 for sharing my batch processing script with everyone, it really helps me out very often! I modified the script to fit my needs and I also want to share what I got. My version of the script is adopted for the latest version of SimSwap with the ability to choose between models -
224and512.First, in order not to edit existed files, you need to create a scripts in the SimSwap root folder with the name
test_batch_wholeimage_swapsingle.pyand
batch_wholeimage_swapsingle.pyThen go to the SimSwap folder and run
python batch_wholeimage_swapsingle.py. After first run in the SimSwap folder will be created new folders: simswap_batch_img_result, simswap_batch_input_faces and simswap_batch_input_files. Put in simswap_batch_input_faces image with face and destination image in simswap_batch_input_files. Then runpython batch_wholeimage_swapsingle.pyagain. Swaped images will be saved in simswap_batch_img_result folder with names like Iron_man_(15.49.13)_multi_people.jpg, where (15.49.13) - is the time of file creaton. You can also run a script with options:--crop_size 224or 512 and--face(name of the specific face). If you run script without this options, will be used default 224. Example:python batch_wholeimage_swapsingle.pywill run with default options,python batch_wholeimage_swapsingle.py --crop_size 512 --face Iron_manwill swap images with crop size 512 and specific name of the face. Also you can combine options, likepython batch_wholeimage_swapsingle.py --face Iron_manorpython batch_wholeimage_swapsingle.py --crop_size 512. Tested on GTX 1060 6GB, Windows 10 and Debian WSL2Wonderful--works perfectly!
@netrunner-exe I tried your script but it failed with this error:
How could it be solved?
I'm running under WSL 2 on Windows 10, and I have not any CUDA/NVIDIA card in my PC.
EDIT: I found the issue.
The content of your script,
test_batch_wholeimage_swapsingle.py, is taken fromtest_wholeimage_swapsingle.py.The fact is that
test_wholeimage_swapsingle.pyhas recently been updated by the original author to also consider those cases where CUDA is not available. For example, it went from:to:
and similar changes elsewhere in the script.
Here how
test_batch_wholeimage_swapsingleshould be to be aligned with the last version:At the end, the base and modified scripts are identical except for the following which goes from:
to:
Sorry - Just to clarify - I wrote that script I posted? If it helps you then great. I use it on videos all the time. Some day soon I'm going to give the 512 version a try.
Hey all, so sorry for the late reply after starting this thread. I tried out the code and it works perfectly. SUCH a timesaver. Thankyou so much :)
Thanks for sharing this you guys, so I modified the code so that the model just initializes once then goes through the folders and saves the result instead of calling command for every new inputs.
Average time of a python command on 1 image Tesla P100 16GB is about 12s while keeping the model idle reduces processing time for each image to ~2s. Another thing I notice that on a P100 16GB, GPU utilization is mostly < 25% while occupied is always < 3GB. This suggest that we can initialize at least 4 models on a GPU and distribute input images via threading. I will try to combine our ideas to work in a more universal way for other tests too!
Hi everyone - I've actually forked Simswap to create a new Repo: BatchSimSwap which is does many things like automated batch video swapping, swapping from a website that contains images, swapping a folder of images etc. I've changed the above script I wrote to be OOP so there are global options and variables and good debug error messages to. I'm still working on it but its growing each day. You can find it here:
https://github.com/chud37/BatchSimSwap
[chud37] Thank you. I think you have better describe how to use your fork. I see this number of bat files but a bit lost. Can you put such examples for every each one into your descriprion? Also you can put some exapmle files to see the progress and results
@SerZhyAle Yes I have only just started the probject a few days a go. Give me a week to get it together and I'll have good documentation too. Im also working on supressing a lot of the useless warning messages too, which makes using SimSwap a lot nicer. So far the only available functions are
bs-url {name} {url}andbs-video 1 bob(This command will make batch processing look for the following folder:batch_processing/input/input_1and will then convert all videos inside there to the face bob.jpg (stored in batch_processing/input_faces/bob.jpg`))This should give you something to get started with.