This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
forked from cvqluu/simple_diarizer
-
Notifications
You must be signed in to change notification settings - Fork 2
Add device control #2
Open
Jeronymous
wants to merge
4
commits into
NME_SC
Choose a base branch
from
trial_gpu
base: NME_SC
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
# ipython>=7.9.0 | ||
# matplotlib>=3.5.1 | ||
pandas>=1.3.5 | ||
# pandas>=1.3.5 | ||
scikit-learn>=1.0.2 | ||
speechbrain>=0.5.11 | ||
torchaudio>=0.10.1 | ||
onnxruntime>=1.14.0 | ||
scipy<=1.8.1 # newer version can provoke segmentation faults | ||
onnxruntime-gpu>=1.14.0 | ||
scipy<=1.8.1 # newer version can provoke segmentation faults | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
|
||
class Diarizer: | ||
def __init__( | ||
self, embed_model="xvec", cluster_method="sc", window=1.5, period=0.75 | ||
self, embed_model="xvec", cluster_method="sc", window=1.5, period=0.75, device=None | ||
): | ||
|
||
assert embed_model in [ | ||
|
@@ -38,25 +38,33 @@ def __init__( | |
|
||
self.vad_model, self.get_speech_ts = self.setup_VAD() | ||
|
||
self.run_opts = ( | ||
{"device": "cuda:0"} if torch.cuda.is_available() else {"device": "cpu"} | ||
) | ||
|
||
if device is None: | ||
self.device = "cuda" if torch.cuda.is_available() else "cpu" | ||
elif device=="cpu": | ||
os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # force torch.cuda.is_available() = False | ||
self.device = "cpu" | ||
elif device=="cuda": | ||
os.environ['CUDA_VISIBLE_DEVICES'] = '0' | ||
device_num=torch.cuda.current_device() | ||
to_cuda = f'cuda:{device_num}' | ||
self.device = to_cuda | ||
|
||
if embed_model == "xvec": | ||
self.embed_model = EncoderClassifier.from_hparams( | ||
source="speechbrain/spkrec-xvect-voxceleb", | ||
savedir="pretrained_models/spkrec-xvect-voxceleb", | ||
run_opts=self.run_opts, | ||
run_opts={"device": self.device}, | ||
) | ||
if embed_model == "ecapa": | ||
self.embed_model = EncoderClassifier.from_hparams( | ||
source="speechbrain/spkrec-ecapa-voxceleb", | ||
savedir="pretrained_models/spkrec-ecapa-voxceleb", | ||
run_opts=self.run_opts, | ||
run_opts={"device": self.device}, | ||
) | ||
|
||
self.window = window | ||
self.period = period | ||
|
||
|
||
def setup_VAD(self): | ||
model, utils = torch.hub.load( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The device should also be used here |
||
|
@@ -95,7 +103,7 @@ def windowed_embeds(self, signal, fs, window=1.5, period=0.75): | |
|
||
segments.append([start, len_signal - 1]) | ||
embeds = [] | ||
|
||
with torch.no_grad(): | ||
for i, j in segments: | ||
signal_seg = signal[:, i:j] | ||
|
@@ -192,7 +200,11 @@ def diarize( | |
enhance_sim=True, | ||
extra_info=False, | ||
outfile=None, | ||
|
||
): | ||
|
||
|
||
|
||
""" | ||
Diarize a 16khz mono wav file, produces list of segments | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two "elif" are useless.
Remove them and Keep It Simple