-
Notifications
You must be signed in to change notification settings - Fork 232
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
Fixed and added precise choose script #25
Open
mikhaildmitrienko
wants to merge
6
commits into
MycroftAI:dev
Choose a base branch
from
mikhaildmitrienko:new-choose
base: dev
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c524df8
Merge pull request #1 from MycroftAI/dev
mikhaildmitrienko 49c53f6
Changed the maximum possible amount of units
mikhaildmitrienko 545166e
Removed redundant code
mikhaildmitrienko 3283499
Created choose.py
mikhaildmitrienko 1a96cb1
Changed spacing between file id and wakeword status
mikhaildmitrienko 79dd71f
Added choose.py to precise executables
mikhaildmitrienko 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from collections import namedtuple | ||
|
||
from prettyparse import create_parser | ||
|
||
from precise.network_runner import Listener | ||
from precise.params import inject_params | ||
from precise.train_data import TrainData | ||
from select import select | ||
from sys import stdin | ||
import pygame | ||
import time | ||
import os | ||
import shutil | ||
from collections import Counter | ||
|
||
usage = ''' | ||
Retag false negatives as wakeword or not wakeword | ||
|
||
:model str | ||
Either Keras (.net) or TensorFlow (.pb) model to test | ||
|
||
:-t --use-train | ||
Evaluate training data instead of test data | ||
|
||
:-nf --no-filenames | ||
Don't print out the names of files that failed | ||
|
||
:-ap --append | ||
Append new tags file to old one | ||
... | ||
''' | ||
|
||
Stats = namedtuple('Stats', 'false_pos false_neg true_pos true_neg') | ||
|
||
def calc_stats(filenames, targets, predictions) -> Stats: | ||
stats = Stats([], [], [], []) | ||
for name, target, prediction in zip(filenames, targets, predictions): | ||
{ | ||
(True, False): stats.false_pos, | ||
(True, True): stats.true_pos, | ||
(False, True): stats.false_neg, | ||
(False, False): stats.true_neg | ||
}[prediction[0] > 0.5, target[0] > 0.5].append(name) | ||
return stats | ||
|
||
def main(): | ||
args = TrainData.parse_args(create_parser(usage)) | ||
|
||
inject_params(args.model) | ||
|
||
data = TrainData.from_both(args.tags_file, args.tags_folder, args.folder) | ||
train, test = data.load(args.use_train, not args.use_train) | ||
inputs, targets = train if args.use_train else test | ||
|
||
filenames = sum(data.train_files if args.use_train else data.test_files, []) | ||
predictions = Listener.find_runner(args.model)(args.model).predict(inputs) | ||
stats = calc_stats(filenames, targets, predictions) | ||
false_negatives_array = stats.false_neg | ||
new_tags = open('tags.txt', 'w') | ||
|
||
|
||
changed_tags_array = [] | ||
for i in range(0, len(false_negatives_array)): | ||
pygame.mixer.init(frequency=8000, size=-16, channels=2, buffer=4096) | ||
pygame.mixer.music.load(false_negatives_array[i]) | ||
pygame.mixer.music.play() | ||
print('False negative ', (i + 1), ' of ', (len(false_negatives_array)) + 1) | ||
user_input = input('Enter y if wakeword, enter n for not wakeword \n') | ||
time.sleep(5) | ||
false_negatives_array[i] = false_negatives_array[i].lstrip('/Users/madmitrienko/wakewords/files/') | ||
false_negatives_array[i] = false_negatives_array[i].rstrip('.wav') | ||
if(user_input == 'y'): | ||
write_to_tags = '\n' + false_negatives_array[i] + ' wake-word' | ||
new_tags.write(write_to_tags) | ||
|
||
elif(user_input == 'n'): | ||
write_to_tags = '\n' + false_negatives_array[i] + ' not-wake-word' | ||
new_tags.write(write_to_tags) | ||
new_tags.close() | ||
tags.close() | ||
|
||
if __name__ == '__main__': | ||
main() |
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
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.
Need to generalize this and pass it to the script as a variable or an environmental setting.