Skip to content

Fix: handle CUDA tensors in df_features() by moving audio to CPU before NumPy conversion #666

Open
F1xxs wants to merge 1 commit intoRikorose:mainfrom
F1xxs:main
Open

Fix: handle CUDA tensors in df_features() by moving audio to CPU before NumPy conversion #666
F1xxs wants to merge 1 commit intoRikorose:mainfrom
F1xxs:main

Conversation

@F1xxs
Copy link

@F1xxs F1xxs commented Nov 10, 2025

While working on a personal project using DeepFilterNet with an external model operating on CUDA tensors, I encountered the following error:

spec = df.analysis(audio.numpy())  # [C, Tf] -> [C, Tf, F]
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
^C

To resolve this, I applied .detach() and .cpu() on the audio tensor to remove it from autograd graph and move to the CPU.

spec = df.analysis(audio.detach().cpu().numpy())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant