Giter VIP home page Giter VIP logo

refacer's People

Contributors

24601 avatar alunit3 avatar bandi13 avatar davidrobles avatar faiseh00d avatar phineas-pta avatar xaviviro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

refacer's Issues

Crashes after the 1st few frames

After the latest tensorrt update it crashes with the following errors:

gradio message: OpenCV(4.7.0) πŸ‘Ž error: (-5:Bad argument) in function 'warpAffine' > Overload resolution failed: > - M is not a numpy array, neither a scalar > - Expected Ptrcv::UMat for argument 'M'

Console message: Total frames: 1204
Extracting frames: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1204/1204 [00:00<00:00, 1585.98it/s]
Processing frames: 2%|β–ˆβ–Ž | 26/1204 [00:01<01:18, 15.05it/s]
Traceback (most recent call last):
File "K:\AI-APPS\refacer\venv\lib\site-packages\gradio\routes.py", line 427, in run_predict
output = await app.get_blocks().process_api(
File "K:\AI-APPS\refacer\venv\lib\site-packages\gradio\blocks.py", line 1323, in process_api
result = await self.call_function(
File "K:\AI-APPS\refacer\venv\lib\site-packages\gradio\blocks.py", line 1051, in call_function
prediction = await anyio.to_thread.run_sync(
File "K:\AI-APPS\refacer\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "K:\AI-APPS\refacer\venv\lib\site-packages\anyio_backends_asyncio.py", line 877, in run_sync_in_worker_thread
return await future
File "K:\AI-APPS\refacer\venv\lib\site-packages\anyio_backends_asyncio.py", line 807, in run
result = context.run(func, *args)
File "K:\AI-APPS\refacer\app.py", line 30, in run
return refacer.reface(video_path,faces)
File "K:\AI-APPS\refacer\refacer.py", line 171, in reface
results = list(tqdm(executor.map(self.__process_faces, frames), total=len(frames),desc="Processing frames"))
File "K:\AI-APPS\refacer\venv\lib\site-packages\tqdm\std.py", line 1178, in iter
for obj in iterable:
File "C:\Users\elias\AppData\Local\Programs\Python\Python310\lib\concurrent\futures_base.py", line 621, in result_iterator
yield _result_or_cancel(fs.pop())
File "C:\Users\elias\AppData\Local\Programs\Python\Python310\lib\concurrent\futures_base.py", line 319, in _result_or_cancel
return fut.result(timeout)
File "C:\Users\elias\AppData\Local\Programs\Python\Python310\lib\concurrent\futures_base.py", line 458, in result
return self.__get_result()
File "C:\Users\elias\AppData\Local\Programs\Python\Python310\lib\concurrent\futures_base.py", line 403, in __get_result
raise self._exception
File "C:\Users\elias\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "K:\AI-APPS\refacer\refacer.py", line 130, in __process_faces
faces = self.__get_faces(frame)
File "K:\AI-APPS\refacer\refacer.py", line 125, in __get_faces
face.embedding = self.rec_app.get(frame, kps)
File "K:\AI-APPS\refacer./recognition\arcface_onnx.py", line 65, in get
aimg = face_align.norm_crop(img, landmark=kps, image_size=self.input_size[0])
File "K:\AI-APPS\refacer./recognition\face_align.py", line 72, in norm_crop
warped = cv2.warpAffine(img, M, (image_size, image_size), borderValue=0.0)
cv2.error: OpenCV(4.7.0) πŸ‘Ž error: (-5:Bad argument) in function 'warpAffine'

Overload resolution failed:

  • M is not a numpy array, neither a scalar
  • Expected Ptrcv::UMat for argument 'M'

Windows 10
nvidia 3060 12GB
Python 3.10.9
Latest Tensorrt

Error and doesn't work

Traceback (most recent call last):
File "/content/refacer/app.py", line 70, in
with gr.Blocks() as demo:
File "/usr/local/lib/python3.10/dist-packages/gradio/blocks.py", line 1478, in exit
self.app = routes.App.create_app(self)
File "/usr/local/lib/python3.10/dist-packages/gradio/routes.py", line 220, in create_app
def login(form_data: OAuth2PasswordRequestForm = Depends()):
File "/usr/local/lib/python3.10/dist-packages/fastapi/routing.py", line 706, in decorator
self.add_api_route(
File "/usr/local/lib/python3.10/dist-packages/fastapi/routing.py", line 645, in add_api_route
route = route_class(
File "/usr/local/lib/python3.10/dist-packages/fastapi/routing.py", line 491, in init
self.dependant = get_dependant(path=self.path_format, call=self.endpoint)
File "/usr/local/lib/python3.10/dist-packages/fastapi/dependencies/utils.py", line 268, in get_dependant
sub_dependant = get_param_sub_dependant(
File "/usr/local/lib/python3.10/dist-packages/fastapi/dependencies/utils.py", line 111, in get_param_sub_dependant
return get_sub_dependant(
File "/usr/local/lib/python3.10/dist-packages/fastapi/dependencies/utils.py", line 147, in get_sub_dependant
sub_dependant = get_dependant(
File "/usr/local/lib/python3.10/dist-packages/fastapi/dependencies/utils.py", line 289, in get_dependant
add_param_to_fields(field=param_field, dependant=dependant)
File "/usr/local/lib/python3.10/dist-packages/fastapi/dependencies/utils.py", line 462, in add_param_to_fields
if field_info.in_ == params.ParamTypes.path:
AttributeError: 'FieldInfo' object has no attribute 'in_'

Feature request: temp file cleanup

Hello,
The new memory management, working on smaller portions of the overall frame count at a time, has been very effective for me - thank you!

I did notice that my Temp directory was getting rather large recently, as it affected swap file size expansion, and it appears that Refacer is writing temporary files to a "gradio" folder in the Windows TEMP folder for videos upon which it works. I manually cleaned up gigabytes of files after discovering this, so wondered if Refacer might clear its temp folder upon startup as a consideration.

Error occured while launching app.py

C:\Python\REFACE\refacer>python app.py
Trying FFMPEG h264_nvenc encoder
FFMPEG h264_nvenc encoder works
Video codec for FFMPEG: h264_nvenc
CPU mode with providers ['CPUExecutionProvider']
Traceback (most recent call last):
File "C:\Python\REFACE\refacer\app.py", line 12, in
refacer = Refacer(force_cpu=args.force_cpu,colab_performance=args.colab_performance)
File "C:\Python\REFACE\refacer\refacer.py", line 35, in init
self.__init_apps()
File "C:\Python\REFACE\refacer\refacer.py", line 95, in init_apps
self.face_swapper = INSwapper(model_path,sess_swap)
File "C:\Users\RMuratuly\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\insightface\model_zoo\inswapper.py", line 16, in init
model = onnx.load(self.model_file)
File "C:\Users\RMuratuly\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\onnx_init
.py", line 170, in load_model
model = load_model_from_string(s, format=format)
File "C:\Users\RMuratuly\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\onnx_init
.py", line 212, in load_model_from_string
return deserialize(s, ModelProto())
File "C:\Users\RMuratuly\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\onnx_init
.py", line 143, in _deserialize
decoded = typing.cast(Optional[int], proto.ParseFromString(s))
google.protobuf.message.DecodeError: Error parsing message

Connection reset error

self._sock.shutdown(socket.SHUT_RDWR)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

Doesn't recognise face from photo so doesnt swap.

Using the collab listed.
I screenshot the video with the destination face, upscaled it (and used raw) , it processed the video but didn't swap the face. Have used thresholds 0.2 and 1 with no effect. The video is only 3 seconds but that's still 75 frames.

What is best practice ? Size of photo used, video resolution etc? Size and number of characters on screen? What does the threshold refer to exactly?

Thanks for this version with gradio and extras, more fun to be had with better spoofs.

Room for further improvement?

Hi.. this is not about any issues.. but a question..

With the latest commits, the app loads and runs smooth and faster than ever.. just asking if more can be done with the leftover vram as I can see 2 gb is still free on my 4 gb card.... Something like multi frame processing with more gpu multithreading.

Error: 'module 'ffmpeg' has no attribute 'probe''

Hello,

I encountered an error with your application. When I select an input image and an output image, and click on the "REFACE" button, I receive the following error: module 'ffmpeg' has no attribute 'probe'

Also, I have installed the necessary dependencies for both CPU and GPU, and my graphics card (GeForce GTX 980) is compatible. However, I'm still experiencing this error:

"Trying FFMPEG h264_nvenc encoder
FFMPEG h264_nvenc encoder doesn't work -> Disabled"

Thanks for your help.

won't start

installed everything that was needed, but when you run python app.py you get an error
the file app.py is in the folder refacer and all rights are granted to it
D:\reface\refacer>python app.py Traceback (most recent call last): File "D:\reface\refacer\app.py", line 11, in <module> refacer = Refacer(force_cpu=args.force_cpu) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\reface\refacer\refacer.py", line 30, in __init__ self.__check_encoders() File "D:\reface\refacer\refacer.py", line 195, in __check_encoders commandout = subprocess.run(command, check=True, capture_output=True).stdout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jecer\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 548, in run with Popen(*popenargs, **kwargs) as process: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jecer\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1024, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\jecer\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1493, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [WinError 2] Cannot find specified file

There was no response after typing the command Python app. py

Downloaded the onnx file from the loop
Successfully installed
There was no response after typing the command Python app. py
Manual alt c stop

$ python app.py
Trying FFMPEG h264_nvenc encoder
FFMPEG h264_nvenc encoder doesn't work -> Disabled.
Trying FFMPEG libx264 encoder
FFMPEG libx264 encoder works
Video codec for FFMPEG: libx264
CPU mode with providers ['CPUExecutionProvider']
inswapper-shape: [1, 3, 128, 128]
Running on local URL: http://127.0.0.1:7860

To create a public link, set share=True in launch().
Keyboard interruption in main thread... closing server.

It seems like there's nothing wrong with the environment

Add information about the rendering speed

It would be great if you could add render speed information in frames per second to the console. It would be visual, and it would also allow you to compare the performance of different devices

ffmpeg error

after I launch the program in the browser and choose a video an a picture, it does some processing and gives me the error below:

Extracting frames:  99%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–| 273/277 [00:00<00:00, 334.97it/s]
Processing frames: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 273/273 [03:09<00:00,  1.44it/s]
Merging audio with the refaced video...
Traceback (most recent call last):
  File "/Users/mac/anaconda3/lib/python3.10/site-packages/gradio/routes.py", line 427, in run_predict
    output = await app.get_blocks().process_api(
  File "/Users/mac/anaconda3/lib/python3.10/site-packages/gradio/blocks.py", line 1323, in process_api
    result = await self.call_function(
  File "/Users/mac/anaconda3/lib/python3.10/site-packages/gradio/blocks.py", line 1051, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "/Users/mac/anaconda3/lib/python3.10/site-packages/anyio/to_thread.py", line 28, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,
  File "/Users/mac/anaconda3/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 818, in run_sync_in_worker_thread
    return await future
  File "/Users/mac/anaconda3/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 754, in run
    result = context.run(func, *args)
  File "/Users/mac/develop/refacer/app.py", line 64, in run
    return refacer.reface(video_path,faces)
  File "/Users/mac/develop/refacer/refacer.py", line 222, in reface
    return self.__convert_video(video_path,output_video_path)
  File "/Users/mac/develop/refacer/refacer.py", line 126, in __convert_video
    out.run(overwrite_output=True,quiet=True)
  File "/Users/mac/anaconda3/lib/python3.10/site-packages/ffmpeg/_run.py", line 325, in run
    raise Error('ffmpeg', out, err)
ffmpeg._run.Error: ffmpeg error (see stderr output for detail)

Trying app.py with GPU = Errors

I'm not a programmer so maybe I broke something..

When I installed ROOP I didn't have any issues the installation was smooth.

I followed the steps in the main REFACER github.
Once I activated REFACER environment and install all GPU requirements, the last step was to run the "app.py"

But then I get these errors:
cmd_2023-06-15_08-53-38

Can somebody please help me make REFACER run, there are no tutorials beside the page but since I'm not a programmer probably it's more complicated to install compare to ROOP.

Thanks ahead! πŸ™

Add pipeline for image processing - also may solve memory issue

Hi!

It may be good to add pipeline to image processing - for example, to use upscaler/face restorer after img making.

As an example, you can use this stuff: https://github.com/janvarev/chain-img-processor - there are framework, where pipeline stages adjusted as a separate plugins.

I've already implemented codeformer upscale/face restore, so it may be good to implement it in this project too.

There are two options to implement it:

  • You can use ChainImgProcessor, and just replace img processing stuff, adding pipeline at end.
  • Or you can use ChainVideoProcessor - it uses Richard's code, and effectively process video through pipeline in several threads WITHOUT need to load all frames to memory (I saw that there are problems with that #18 )

FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'

Traceback (most recent call last):
  File "/home/*/Desktop/refacer/app.py", line 17, in <module>
    refacer = Refacer(force_cpu=args.force_cpu,colab_performance=args.colab_performance)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/*/Desktop/refacer/refacer.py", line 32, in __init__
    self.__check_encoders()
  File "/home/*/Desktop/refacer/refacer.py", line 230, in __check_encoders
    commandout = subprocess.run(command, check=True, capture_output=True).stdout
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'

Error

1 validation error for PredictBody
event_id
Field required [type=missing, input_value={'data': [[{'data': 'data...on_hash': 'r9p16srjhgg'}, input_type=dict]

ffmpeg error

Everything fine, but when I try to make it work this error appears:
Something went wrong
ffmpeg error (see stderr output for detail)

What should I do to get throught this?

Out of memory error when refacing

This was happening in a similar manner yesterday, but as of the main branch at commit 63d501c , I am getting this error when attempting to run Refacer on a 380MB MP4 (h264):

Trying FFMPEG h264_nvenc encoder
FFMPEG h264_nvenc encoder works
Video codec for FFMPEG: h264_nvenc
CUDA mode with providers ['CUDAExecutionProvider', 'CPUExecutionProvider']
inswapper-shape: [1, 3, 128, 128]
Running on local URL: http://127.0.0.1:7860

To create a public link, set share=True in launch().
Total frames: 52567
Extracting frames: 21%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ | 11276/52567 [00:20<01:14, 557.87it/s]
Traceback (most recent call last):
File "D:\refacer-main\venv\lib\site-packages\gradio\routes.py", line 427, in run_predict
output = await app.get_blocks().process_api(
File "D:\refacer-main\venv\lib\site-packages\gradio\blocks.py", line 1323, in process_api
result = await self.call_function(
File "D:\refacer-main\venv\lib\site-packages\gradio\blocks.py", line 1051, in call_function
prediction = await anyio.to_thread.run_sync(
File "D:\refacer-main\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "D:\refacer-main\venv\lib\site-packages\anyio_backends_asyncio.py", line 877, in run_sync_in_worker_thread
return await future
File "D:\refacer-main\venv\lib\site-packages\anyio_backends_asyncio.py", line 807, in run
result = context.run(func, *args)
File "D:\refacer-main\app.py", line 31, in run
return refacer.reface(video_path,faces)
File "D:\refacer-main\refacer.py", line 196, in reface
flag, frame = cap.read()
cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\core\src\alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 2764800 bytes in function 'cv::OutOfMemoryError'

Although I have configured to use GPU (3090 with 24GB), the system RAM shot up from 17GB used to over 53GB (out of 64GB total) and I did not see GPU memory being allocated in the monitor.

As mentioned, I have experienced an out of memory error since the new (faster) codebase was pushed in the past day or so. While some files can process fine, I notice that smaller files are still hit-or-miss, so I can't supply a definite criteria of when this might occur.

Current video quality of the RESULT is very low

Currently the end result quality of the video is much lower.
I compared to ROOP which the default video quality result is great.

It will be great to have LOSSLESS or value to change from 0 (low) to 100 (highest) quality?

Issues with requirements.txt

Both CPU & GPU get multiple errors, from cuda installs to scikit-image refacer\lib\site-packages\onnxruntime\capi\onnxruntime_providers_cuda.dll" How did I install? Made a conda env called it refacer then I git cloned inside it and installed requirements. So Env/Refacer/refacer

Error with "ffmpeg"

OS: Ubuntu 22.04.2 LTS
Video: link
Command: python3 app.py
Video codec for FFMPEG: h264_nvenc
CPU mode with providers ['CPUExecutionProvider']

Output:

Total frames: 159
Extracting frames: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 159/159 [00:00<00:00, 1319.79it/s]
Processing frames: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 159/159 [02:02<00:00,  1.29it/s]
Merging audio with the refaced video...
Traceback (most recent call last):
  File "/home/serejajar/.local/lib/python3.10/site-packages/gradio/routes.py", line 427, in run_predict
    output = await app.get_blocks().process_api(
  File "/home/serejajar/.local/lib/python3.10/site-packages/gradio/blocks.py", line 1323, in process_api
    result = await self.call_function(
  File "/home/serejajar/.local/lib/python3.10/site-packages/gradio/blocks.py", line 1051, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "/home/serejajar/.local/lib/python3.10/site-packages/anyio/to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/home/serejajar/.local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "/home/serejajar/.local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "/home/serejajar/Documents/my/refacer/app.py", line 30, in run
    return refacer.reface(video_path,faces)
  File "/home/serejajar/Documents/my/refacer/refacer.py", line 189, in reface
    return self.__convert_video(video_path,output_video_path)
  File "/home/serejajar/Documents/my/refacer/refacer.py", line 113, in __convert_video
    out.run(overwrite_output=True,quiet=True)
  File "/home/serejajar/.local/lib/python3.10/site-packages/ffmpeg/_run.py", line 325, in run
    raise Error('ffmpeg', out, err)
ffmpeg._run.Error: ffmpeg error (see stderr output for detail)

FileNotFoundError when start

installed with tutorial, but when run app.py it seems like this:
Traceback (most recent call last):
File "D:\work\a\verify\refacer\app.py", line 17, in
refacer = Refacer(force_cpu=args.force_cpu,colab_performance=args.colab_performance)
File "D:\work\a\verify\refacer\refacer.py", line 32, in init
self.__check_encoders()
File "D:\work\a\verify\refacer\refacer.py", line 230, in __check_encoders
commandout = subprocess.run(command, check=True, capture_output=True).stdout
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

Error with refacer.py

PS D:\refacer> python app.py
Traceback (most recent call last):
File "D:\refacer\app.py", line 11, in
refacer = Refacer(force_cpu=args.force_cpu)
File "D:\refacer\refacer.py", line 30, in init
self.__check_encoders()
File "D:\refacer\refacer.py", line 195, in __check_encoders
commandout = subprocess.run(command, check=True, capture_output=True).stdout
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 503, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 971, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1440, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] НС удаСтся Π½Π°ΠΉΡ‚ΠΈ ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΉ Ρ„Π°ΠΉΠ»

Colab Works Fine But even 4090 is Too Slow

Thank you for this project,
Colab works like 4-6 it /s but even i use 4090 GPU, it's only doing 1 it on 5-6 secs.
I am sure i am missing something to make it use GPU.
I already installed requirements-GPU one but no speed increases

OutOfMemoryError (possible regression)

Hello,
The prior out of memory fix - which seemed to break up refacing actions into smaller segments of the larger video being processed - seems no longer in place, as recent builds attempt to process the entire video once again.

This is the result for an 185MB h264 MP4 video, 3840 x 2160 at 60fps:

Trying FFMPEG h264_nvenc encoder
FFMPEG h264_nvenc encoder works
Video codec for FFMPEG: h264_nvenc
CUDA mode with providers ['CUDAExecutionProvider', 'CPUExecutionProvider']
inswapper-shape: [1, 3, 128, 128]
Running on local URL: http://127.0.0.1:7860

To create a public link, set share=True in launch().
Total frames: 3711
Extracting frames: 24%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– | 877/3711 [00:15<00:49, 56.98it/s]
Traceback (most recent call last):
File "D:\refacer-main\venv\lib\site-packages\gradio\routes.py", line 427, in run_predict
output = await app.get_blocks().process_api(
File "D:\refacer-main\venv\lib\site-packages\gradio\blocks.py", line 1323, in process_api
result = await self.call_function(
File "D:\refacer-main\venv\lib\site-packages\gradio\blocks.py", line 1051, in call_function
prediction = await anyio.to_thread.run_sync(
File "D:\refacer-main\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "D:\refacer-main\venv\lib\site-packages\anyio_backends_asyncio.py", line 877, in run_sync_in_worker_thread
return await future
File "D:\refacer-main\venv\lib\site-packages\anyio_backends_asyncio.py", line 807, in run
result = context.run(func, *args)
File "D:\refacer-main\app.py", line 64, in run
return refacer.reface(video_path,faces)
File "D:\refacer-main\refacer.py", line 205, in reface
flag, frame = cap.read()
cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\core\src\alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 24883200 bytes in function 'cv::OutOfMemoryError'

Running on a relatively untaxed 64GB Windows 10 Pro system, with refacer installed to use the GPU (RTX-3090 24GB. although system RAM gets allocated, regardless.) I did a fresh install of the last few days of commits and all have the same symptom for me.

After the updte only CPU is using and its extremely slow

Hi,
I had the previous June 3rd version and its working perfectly and faster even it wont use all the resource of GPU. After the today's update its not using any GPU at all and using 100 percent of CPU and ram and its extremely slow. Hope you guys can fix that or let me know is it wrong in my installation. And thank you so much for making a amazing project.

Thanks & Best Regards
Allen

FileNotFoundError: [WinError 2] The system cannot find the file specified (Windows 11)

PS D:\Programs\RefacerAI\refacer> python app.py
Traceback (most recent call last):
File "D:\Programs\RefacerAI\refacer\app.py", line 17, in
refacer = Refacer(force_cpu=args.force_cpu,colab_performance=args.colab_performance)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Programs\RefacerAI\refacer\refacer.py", line 32, in init
self.__check_encoders()
File "D:\Programs\RefacerAI\refacer\refacer.py", line 230, in __check_encoders
commandout = subprocess.run(command, check=True, capture_output=True).stdout
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\subprocess.py", line 1026, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\subprocess.py", line 1538, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified

Memory issue

Hi!

Is it possible to solve high RAM consumption issue by splitting the video into parts, for example, 30 seconds each, processing them one by one and then combining them back together? Ffmpeg makes it quite easy to implement such a thing.

I tried implementing something similar with Roop and it worked.

CUDA issue

I got CUDA 12.1 installed on win11

I'm running as well roop with venv.
I'm running as well A111 with venv also.

For refacer, i run "pip install -r requirements-GPU.txt" successfuly also in a venv.

but when launching, i got this error related to CUDA, it doesn't find it. I'm puzzled because i didn't do anything special for roop and A1111.

(venv-refacer) C:\Users\xxx\IA\faceswap\refacer>python app.py
Trying FFMPEG h264_nvenc encoder
FFMPEG h264_nvenc encoder works
Video codec for FFMPEG: h264_nvenc
CUDA mode with providers ['CUDAExecutionProvider', 'CPUExecutionProvider']
EP Error D:\a\_work\1\s\onnxruntime\python\onnxruntime_pybind_state.cc:636 onnxruntime::python::CreateExecutionProviderInstance CUDA_PATH is set but CUDA wasn't able to be loaded. Please install the correct version of CUDA and cuDNN as mentioned in the GPU requirements page (https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements), make sure they're in the PATH, and that your GPU is supported.
 when using ['CUDAExecutionProvider', 'CPUExecutionProvider']
Falling back to ['CUDAExecutionProvider', 'CPUExecutionProvider'] and retrying.
Traceback (most recent call last):
  File "C:\Users\xxx\IA\faceswap\venv-refacer\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 383, in __init__
    self._create_inference_session(providers, provider_options, disabled_optimizers)
  File "C:\Users\xxx\IA\faceswap\venv-refacer\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 435, in _create_inference_session
    sess.initialize_session(providers, provider_options, disabled_optimizers)
RuntimeError: D:\a\_work\1\s\onnxruntime\python\onnxruntime_pybind_state.cc:636 onnxruntime::python::CreateExecutionProviderInstance CUDA_PATH is set but CUDA wasn't able to be loaded. Please install the correct version of CUDA and cuDNN as mentioned in the GPU requirements page (https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements), make sure they're in the PATH, and that your GPU is supported.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\xxx\IA\faceswap\refacer\app.py", line 17, in <module>
    refacer = Refacer(force_cpu=args.force_cpu,colab_performance=args.colab_performance)
  File "C:\Users\xxx\IA\faceswap\refacer\refacer.py", line 35, in __init__
    self.__init_apps()
  File "C:\Users\xxx\IA\faceswap\refacer\refacer.py", line 84, in __init_apps
    sess_face = rt.InferenceSession(model_path, self.sess_options, providers=self.providers)
  File "C:\Users\xxx\IA\faceswap\venv-refacer\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 394, in __init__
    raise fallback_error from e
  File "C:\Users\xxx\IA\faceswap\venv-refacer\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 389, in __init__
    self._create_inference_session(self._fallback_providers, None)
  File "C:\Users\xxx\IA\faceswap\venv-refacer\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 435, in _create_inference_session
    sess.initialize_session(providers, provider_options, disabled_optimizers)
RuntimeError: D:\a\_work\1\s\onnxruntime\python\onnxruntime_pybind_state.cc:636 onnxruntime::python::CreateExecutionProviderInstance CUDA_PATH is set but CUDA wasn't able to be loaded. Please install the correct version of CUDA and cuDNN as mentioned in the GPU requirements page (https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements), make sure they're in the PATH, and that your GPU is supported.

CUDA is available:

>>> import onnxruntime
>>> print(onnxruntime.get_available_providers())
['TensorrtExecutionProvider', 'CUDAExecutionProvider', 'CPUExecutionProvider']
>>>

any clue is welcome.

thanks

ConnectionResetError

This error pops up after muxing the frames and job completion. This doesn't seem to be affecting anything as app still works and does swapping repeatedly.

Exception in callback _ProactorBasePipeTransport._call_connection_lost(None)
handle: <Handle _ProactorBasePipeTransport._call_connection_lost(None)>
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "C:\Program Files\Python310\lib\asyncio\proactor_events.py", line 162, in _call_connection_lost
self._sock.shutdown(socket.SHUT_RDWR)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
Exception in callback _ProactorBasePipeTransport._call_connection_lost(None)
handle: <Handle _ProactorBasePipeTransport._call_connection_lost(None)>
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\asyncio\events.py", line 80, in _run

[Feature] Image support

Please add image support. It is possible to select image, but when I reface I got video with one frame.

Refacing operation does not seem to fully use GPU

Hello,
I tried the GPU installation instructions on Windows, but within a venv. It complained about the lack of torch libraries, so I reused the roop repo's GPU installation steps for refacer (not all items might have been necessary for refacer):

  • install cuda 11.7 (https://developer.nvidia.com/cuda-11-7-0-download-archive)
  • download cudnn 8.9.1 for cuda 11.x https://developer.nvidia.com/rdp/cudnn-archive
  • unpack cudnn over C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7 with replacement
  • install python 3.10.x (any 3.10)
  • download the last version of refacer
  • pip install virtualenv
  • virtualenv venv
  • venv\scripts\activate.bat
  • pip install torch torchvision torchaudio --force-reinstall --index-url https://download.pytorch.org/whl/cu117
  • pip install -r requirements-GPU.txt
  • Add ...\refacer-main\venv\Lib\site-packages\torch\lib to PATH (because refacer complained that one of the libraries was not visible during run time)
  • SET CUDA_VISIBLE_DEVICES=1 (optional, uses my second GPU)

Refacer initially starts with an aggressive speed and estimate (6 minutes at 54it/s) , but seconds later changes to use a far slower speed (1 hour at 5.2it/s). By comparison, the CPU-only refacer configuration almost triples the execution time.

By contrast, the similar roop codebase - when configured for GPU use - currently requires less than 15 minutes from start to finish.

I noticed that GPU monitors from ASUS and the built-in from WIndows 10 show a max of ~35% utilization with low VRAM allocation while refacer is processing a video. Those same monitors show >90% GPU utilization and far higher memory usage while processing the same video.

Not sure if refacer code is intended to be less taxing on the GPU because of its unique processing logic, if this might be a potential symptom of using venv or if it's possibly a bug situation, but I wanted to report in case it offers a helpful user perspective.

Antivirus detection

site-packages\gradio\frpc_windows_amd64_v0.2 can be used by intruders to damage computer or personal data.

HEUR:NetTool.Win64.FRP.gen

Any way to resolve this?

refacer and roop parralel installation causes problems.

when i install refacer after roop. then roop dont work anymore. then i installed roop again. when i do this refacer dont work anymore:

i think it has something to do with cuda environment variables. here is the error i get:

`
PS C:\tools\refacer\refacer> python .\app.py
Trying FFMPEG h264_nvenc encoder
FFMPEG h264_nvenc encoder works
Video codec for FFMPEG: h264_nvenc
CUDA mode with providers ['CUDAExecutionProvider', 'CPUExecutionProvider']
EP Error D:\a_work\1\s\onnxruntime\python\onnxruntime_pybind_state.cc:636 onnxruntime::python::CreateExecutionProviderInstance CUDA_PATH is set but CUDA wasn't able to be loaded. Please install the correct version of CUDA and cuDNN as mentioned in the GPU requirements page (https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements), make sure they're in the PATH, and that your GPU is supported.
when using ['CUDAExecutionProvider', 'CPUExecutionProvider']
Falling back to ['CUDAExecutionProvider', 'CPUExecutionProvider'] and retrying.
Traceback (most recent call last):
File "C:\Users\youba\AppData\Local\Programs\Python\Python310\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 383, in init
self._create_inference_session(providers, provider_options, disabled_optimizers)
File "C:\Users\youba\AppData\Local\Programs\Python\Python310\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 435, in _create_inference_session
sess.initialize_session(providers, provider_options, disabled_optimizers)
RuntimeError: D:\a_work\1\s\onnxruntime\python\onnxruntime_pybind_state.cc:636 onnxruntime::python::CreateExecutionProviderInstance CUDA_PATH is set but CUDA wasn't able to be loaded. Please install the correct version of CUDA and cuDNN as mentioned in the GPU requirements page (https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements), make sure they're in the PATH, and that your GPU is supported.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\tools\refacer\refacer\app.py", line 17, in
refacer = Refacer(force_cpu=args.force_cpu,colab_performance=args.colab_performance)
File "C:\tools\refacer\refacer\refacer.py", line 35, in init
self.__init_apps()
File "C:\tools\refacer\refacer\refacer.py", line 84, in __init_apps
sess_face = rt.InferenceSession(model_path, self.sess_options, providers=self.providers)
File "C:\Users\youba\AppData\Local\Programs\Python\Python310\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 394, in init
raise fallback_error from e
File "C:\Users\youba\AppData\Local\Programs\Python\Python310\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 389, in init
self._create_inference_session(self._fallback_providers, None)
File "C:\Users\youba\AppData\Local\Programs\Python\Python310\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 435, in _create_inference_session
sess.initialize_session(providers, provider_options, disabled_optimizers)
RuntimeError: D:\a_work\1\s\onnxruntime\python\onnxruntime_pybind_state.cc:636 onnxruntime::python::CreateExecutionProviderInstance CUDA_PATH is set but CUDA wasn't able to be loaded. Please install the correct version of CUDA and cuDNN as mentioned in the GPU requirements page (https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements), make sure they're in the PATH, and that your GPU is supported.

PS C:\tools\refacer\refacer>
`

newest version of cuda cudnn etc. is installed. and works properly in other aplications. only roop and refacer together makes problems.

please help

Crashing after new updates..

Now it takes awefully longer time to load and provide the link to UI. Evrything seems frozen and unresponsive.. To reconfirm, I did a fresh install but the result was no different. Attacching a video and environment path setup..
Gtx 1650ti 4gb..
It ran buttery smooth before the update.

Recording.2023-06-06.152840.2.mp4

Screenshot 2023-06-06 154312

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.