-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avletters #1
Open
saamc
wants to merge
9
commits into
master
Choose a base branch
from
avletters
base: master
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
Avletters #1
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8293e6e
adding file discovery and subsetting for avletters
7c9546c
removing swap file
f258ac0
Changes to be Py2.7 compatible. (Still used in official TF docker ima…
995bef3
Adding support for labels.\nPy27 compatibility.
4089321
Adding import for avletters.
7aaacdb
Adding support for reading mlf files.
273bd12
Adding script to import AVLetters data to current directory.
aaccba9
Py27 compatibility.
17b3b72
Adding __init__.py for Py27 compatibility.
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,7 +1,5 @@ | ||
from .avsr import AVSR | ||
from .avsr import run | ||
from . import utils | ||
|
||
|
||
|
||
|
||
from .avletters.files import request_files | ||
#from .ouluvs2 import files |
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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
from os import path | ||
try: | ||
from pathlib import Path | ||
except ImportError: | ||
from pathlib2 import Path # python 2 backport | ||
from natsort import natsorted | ||
from sys import argv | ||
import pprint | ||
import re | ||
|
||
_current_path = path.abspath(path.dirname(__file__)) | ||
|
||
split = re.compile("_|-") | ||
|
||
def request_files(dataset_dir, | ||
protocol='speaker_independent', | ||
speaker_id=None, content="video", condition="none"): | ||
|
||
files = get_files(dataset_dir, content, condition) | ||
speakers = get_speakers(files) | ||
|
||
if protocol == 'speaker_dependent': | ||
train, dev, test = _preload_files_speaker_dependent(files, speaker_id, utterance_types) | ||
elif protocol == 'speaker_independent': | ||
train, dev, test = _preload_files_speaker_independent(files, speakers, content, condition) | ||
else: | ||
raise Exception('undefined dataset split protocol') | ||
|
||
return natsorted(train), natsorted(dev), natsorted(test), | ||
|
||
|
||
def get_files(dataset_dir, content="video", condition=None): | ||
|
||
p = Path(dataset_dir) | ||
|
||
if content == "video": | ||
p = p.joinpath("Lips") | ||
files = p.glob("*.mat") | ||
elif content == "audio": | ||
#only mfcc in distribution, waveform dir empty | ||
p = p.joinpath("Audio").joinpath("mfcc").joinpath(condition) | ||
print p.as_posix() | ||
if p.exists() and p.is_dir(): | ||
files = p.glob("*.mfcc") | ||
else: | ||
raise Exception("unknown condition: " + condition + " in " + p.stem) | ||
elif content == "label": | ||
p = p.joinpath("Label") | ||
#we don't look for the extension here, as it's not a given | ||
files = p.glob("[A-Z][1-3]_*.*") | ||
else: | ||
raise Exception("unknown content: " + content) | ||
|
||
#the glob returns a generator that is empty once used | ||
return [f for f in files] | ||
|
||
|
||
def get_speakers(files): | ||
|
||
return list(set([get_speaker(f) for f in files])) | ||
|
||
def get_speaker(file_): | ||
return split.split(file_.stem)[1] | ||
|
||
|
||
#speaker_dependent means: we have some speakers that we trained on in the dev/test sets | ||
def _preload_files_speaker_dependent(files, speaker_id): | ||
|
||
raise Exception("speaker dependent protocol not implemented") | ||
|
||
### NEED TO BE CREATIVE HERE | ||
## we can basically split along repetitions but it's very little data | ||
|
||
#60/20/20 split by recursive split | ||
from sklearn.model_selection import train_test_split | ||
train, test = train_test_split(files, test_size=0.20, random_state=0) | ||
train, dev = train_test_split(train, test_size=0.25, random_state=0) | ||
|
||
return train, dev, test | ||
|
||
def _preload_files_speaker_independent(files, speakers, content="video", condition=None): | ||
|
||
#60/20/20 split by recursive split over speakers | ||
from sklearn.model_selection import train_test_split | ||
strain, stest = train_test_split(speakers, test_size=0.20, random_state=0) | ||
strain, sdev = train_test_split(strain, test_size=0.25, random_state=0) | ||
|
||
#map all files to their speaker | ||
speaker_files = {} | ||
for file_ in files: | ||
speaker = get_speaker(file_) | ||
try: | ||
speaker_files[speaker].append(file_) | ||
except: | ||
speaker_files[speaker] = [file_] | ||
|
||
train_files = [] | ||
dev_files = [] | ||
test_files = [] | ||
#for each subset | ||
for sset, fset in [(strain, train_files),(sdev, dev_files),(stest, test_files)]: | ||
for speaker in sset: | ||
fset.extend(speaker_files[speaker]) | ||
|
||
return train_files, dev_files, test_files | ||
|
||
if __name__ == "__main__": | ||
|
||
print argv[0],": ",argv[1] | ||
pp = pprint.PrettyPrinter(indent=4) | ||
|
||
train, dev, test = request_files(argv[1], protocol='speaker_independent', | ||
speaker_id=None, content="video", condition="none") | ||
|
||
print "train set:" | ||
pp.pprint(train) | ||
print "dev set:" | ||
pp.pprint(dev) | ||
print "test set:" | ||
pp.pprint(test) | ||
|
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
#this is not guarded against whitespace! | ||
src_dir=/data/corpora/audiovisual/avletters | ||
#import audio data as is with sub directories | ||
mkdir data | ||
ln -s $src_dir/Audio data/ | ||
#import video data with name change, dropping "-lips" from "xxx-lips.mat" | ||
mkdir data/Lips | ||
for f in $src_dir/Lips/*.mat; do ln -s $f data/Lips/$(basename ${f/-lips/}); done | ||
#make labels from the file name, this is just the first letter | ||
mkdir data/Label | ||
for f in data/Audio/mfcc/Clean/*.mfcc; do name=$(basename $f ".mfcc"); echo $name ${name/[0-9]_*} > data/Label/$name.mlf; done | ||
Oops, something went wrong.
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.
The bash scripts wouldn't play nice on Windows platforms. This one seems easy to port.
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.
probably just as fast to put it in a python script that runs anywhere
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.
weird, should be "data/Label/$name.lab"