Skip to content
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
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions choose.py
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/')
Copy link
Contributor

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.

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()
3 changes: 1 addition & 2 deletions precise/scripts/train_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def run(self):
print("\n= %d = (example #%d)" % (i + 1, len(self.bb.get_data()["examples"]) + 1))

params = ModelParams(
recurrent_units=self.bb.randint("units", 1, 100, guess=50),
recurrent_units=self.bb.randint("units", 1, 70, guess=50),
dropout=self.bb.uniform("dropout", 0.1, 0.9, guess=0.6),
extra_metrics=self.args.extra_metrics,
skip_acc=self.args.no_validation,
Expand Down Expand Up @@ -119,7 +119,6 @@ def run(self):
"fitness": fitness
})

print(false_positives)
print("False positive: ", false_positives * 100, "%")

self.bb.maximize(fitness)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'precise-train-optimize=precise.scripts.train_optimize:main',
'precise-train-sampled=precise.scripts.train_sampled:main',
'precise-train-incremental=precise.scripts.train_incremental:main',
'precise-choose=precise.scripts.choose:main',
]
},
install_requires=[
Expand Down