C0untFloyd / roop-unleashed

Evolved Fork of roop with Web Server and lots of additions
GNU Affero General Public License v3.0
2.06k stars 476 forks source link

DMDNet doesn't work with DirectML giving CUDA error #367

Closed YW5555 closed 8 months ago

YW5555 commented 9 months ago

Describe the bug When trying to process video with DMDNet post-processing, a CUDA error pops up due to using DirectML. I'm assuming DMDNet doesn't support DirectML yet?

To Reproduce Steps to reproduce the behavior:

  1. Run faceswap with DMDNet as the post-processor.

Details What OS are you using?

Are you using a GPU?

Which version of roop unleashed are you using? roop unleashed 3.3.4

Applied providers: ['DmlExecutionProvider', 'CPUExecutionProvider'], with options: {'DmlExecutionProvider': {}, 'CPUExecutionProvider': {}}
inswapper-shape: [1, 3, 128, 128]
Traceback (most recent call last):
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\gradio\queueing.py", line 388, in call_prediction
    output = await route_utils.call_process_api(
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\gradio\route_utils.py", line 219, in call_process_api
    output = await app.get_blocks().process_api(
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\gradio\blocks.py", line 1437, in process_api
    result = await self.call_function(
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\gradio\blocks.py", line 1109, in call_function    prediction = await anyio.to_thread.run_sync(
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run    result = context.run(func, *args)
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\gradio\utils.py", line 641, in wrapper
    response = f(*args, **kwargs)
  File "Z:\roop-unleashed\installer\roop-unleashed\ui\tabs\faceswap_tab.py", line 389, in on_preview_frame_changed
    current_frame = live_swap(current_frame, roop.globals.face_swap_mode, use_clip, clip_text, SELECTED_INPUT_FACE_INDEX)
  File "Z:\roop-unleashed\installer\roop-unleashed\roop\core.py", line 189, in live_swap
    process_mgr.initialize(roop.globals.INPUT_FACESETS, roop.globals.TARGET_FACES, options)
  File "Z:\roop-unleashed\installer\roop-unleashed\roop\ProcessMgr.py", line 87, in initialize
    p.Initialize(devicename)
  File "Z:\roop-unleashed\installer\roop-unleashed\roop\processors\Enhance_DMDNet.py", line 32, in Initialize
    self.model_dmdnet = self.create(devicename)
  File "Z:\roop-unleashed\installer\roop-unleashed\roop\processors\Enhance_DMDNet.py", line 197, in create
    weights = torch.load('./models/DMDNet.pth')
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\torch\serialization.py", line 809, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\torch\serialization.py", line 1172, in _load
    result = unpickler.load()
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\torch\serialization.py", line 1142, in persistent_load
    typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\torch\serialization.py", line 1116, in load_tensor
    wrap_storage=restore_location(storage, location),
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\torch\serialization.py", line 217, in default_restore_location
    result = fn(storage, location)
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\torch\serialization.py", line 182, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "Z:\roop-unleashed\installer\installer_files\env\lib\site-packages\torch\serialization.py", line 166, in validate_cuda_device
    raise RuntimeError('Attempting to deserialize object on a CUDA '
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
github-actions[bot] commented 8 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 8 months ago

This issue was closed because it has been stalled for 5 days with no activity.

aldemoth commented 7 months ago

Replacing line 197 of "roop-unleashed\roop\processors\Enhance_DMDNet.py" file solves the problem.

Original line:

    weights = torch.load('./models/DMDNet.pth') 

Fixed:

    weights = torch.load('./models/DMDNet.pth', map_location=self.torchdevice) 

This is CPU only. I didn't try implementing DirectML because I have no space in my ssd currently.

Mejituu commented 2 months ago

Replacing line 197 of "roop-unleashed\roop\processors\Enhance_DMDNet.py" file solves the problem.

Original line:

    weights = torch.load('./models/DMDNet.pth') 

Fixed:

    weights = torch.load('./models/DMDNet.pth', map_location=self.torchdevice) 

This is CPU only. I didn't try implementing DirectML because I have no space in my ssd currently.

DML Good