Skip to content

Commit ea40658

Browse files
author
slash6475
committed
[NEW] Sample auto extraction according to unknow input
[ADD] Default Nothing classifier in git [UPDATE] Change balance between yes and no in training program from (1/2 to 1/4)
1 parent fcea38f commit ea40658

12 files changed

+275
-56
lines changed

Nothing/Nothing.dat

31.3 MB
Binary file not shown.

Nothing/classifier-Nothing-L1.png

49.1 KB
Loading

Nothing/classifier-Nothing-L2.png

109 Bytes
Loading

Nothing/classifier-Nothing.nn

15.8 MB
Binary file not shown.

client/classifier_chart.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function ClassifierChart(parent, names){
44
var plots = this.plots = new Array();
55
this.dialog_chart_name = "dialog-neural-outputs";
66
parent.innerHTML +=
7-
'<div id="'+ this.dialog_chart_name +'" title="Neural Knowledge Units"></div>'+
7+
'<div id="'+ this.dialog_chart_name +'" title="Neural Memory"></div>'+
88
'<div id="dialog-info" title="Details" ></div>' +
99
'<div id="dialog-info-img" title="Hidden Layers" ></div>' +
1010
'<div id="dialog-database-new" title="Record database name">'+

client/speaker_stats.js

+212-38
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ function SpeakerStats(parent, names){
33

44
var speakers_count = [['Speaker', 'Score']];
55
var plots = this.plots = new Array();
6-
parent.innerHTML += '<div id="speaker_stats" title="Speaker Stats"><div id="speaker_stats_piechart" style="width:600px;height:600px; text-align:center;"></div>';
6+
parent.innerHTML += '<div id="speaker_stats" title="Speaker Stats"><div id="speaker_stats_piechart" style="width:600px;height:600px; text-align:center;"></div><div id="speaker_stats_lists">No member</div>';
7+
78

89
// New sample for cl (if cl do not exist, it will be create)
910
// socket.emit('sys', JSON.stringify( {sys:{sample: cl, classe:"+"}} ));
@@ -13,9 +14,13 @@ function SpeakerStats(parent, names){
1314
new_speaker = "";
1415
new_speaker_count = 0;
1516

16-
parent.innerHTML += '<div id="speaker_stats_new"> ' +
17+
/******************************************************************************/
18+
/* Views definitions */
19+
/******************************************************************************/
20+
21+
parent.innerHTML += '<div id="progressbar"><div id="progress-label">Loading...</div></div><div id="speaker_stats_new"> ' +
1722
' <div id="speaker_stats_new_init"><input type="text" id="speaker_stats_new_value"><input type="button" value="create" id="speaker_stats_new_button"></div>' +
18-
'<div id="speaker_stats_new_progress"> '+
23+
'<div id="speaker_stats_new_progress"> <input type="button" value="stop" id="speaker_stats_stop_button"> '+
1924
'<div id="speaker_stats_new_progress_bar"></div>'+
2025
"<br><strong>If using microphone,</strong><br>Please talk as clearly as possible while the extraction of samples. <br\> \
2126
<br>\
@@ -39,105 +44,278 @@ function SpeakerStats(parent, names){
3944
</div>" +
4045
'</div>'+
4146
'</div>';
42-
$('#speaker_stats_new_progress_bar').hide();
47+
$('#speaker_stats_new_progress').hide();
4348

44-
$('#speaker_stats_new_button').on('click',function(){
49+
$('#speaker_stats_stop_button').on('click',function(){
50+
stop_record = true;
51+
});
4552

53+
$('#speaker_stats_new_button').on('click',function(){
4654
socket.emit('sys', JSON.stringify( {sys:{control:'pause'}} ));
47-
4855
setTimeout( function(){
49-
console.log("create " + $('#speaker_stats_new_value').val());
56+
//console.log("create " + $('#speaker_stats_new_value').val());
5057
new_speaker = $('#speaker_stats_new_value').val();
5158
state == "record";
5259
new_speaker_count = 0;
5360
socket.emit('sys', JSON.stringify( {sys:{control:'next'}} ));
5461
}, 1000);
55-
5662
$('#speaker_stats_new_init').hide();
57-
$('#speaker_stats_new_progress_bar').show();
58-
63+
$('#speaker_stats_new_progress').show();
5964
})
6065

6166
var dialog_new = $("#speaker_stats_new").dialog({
6267
autoOpen:false,
63-
title:'Sample recorder',
64-
width:600
68+
title:'New record',
69+
width:600,
70+
height:400
6571
});
6672

67-
var html = ''
73+
74+
75+
// PROGRESS BAR
76+
77+
var progressbar_win = $("#progressbar").dialog({
78+
autoOpen:false,
79+
title:'Progress',
80+
width:300,
81+
height:120
82+
});
83+
84+
$('#progressbar').hide();
85+
var progressbar = $( "#progressbar" ),
86+
progressLabel = $( "#progress-label" );
87+
88+
progressbar.progressbar({
89+
value: false,
90+
change: function() {
91+
progressLabel.text( progressbar.progressbar( "value" ) + "%" );
92+
},
93+
complete: function() {
94+
progressLabel.text( "Complete!" );
95+
}
96+
});
97+
/******************************************************************************/
98+
/* State machine for voice recording, encoding, training program and learning */
99+
/******************************************************************************/
100+
function speaker_start(){
101+
socket.emit('sys', '{ "sys": { "classifier": { "reload": ""}}}');
102+
}
103+
104+
state_learning = '';
105+
// generate Training Program
106+
function speaker_build_classifier_init(){
107+
108+
function build_classifier_delay(name){
109+
setTimeout(function(){
110+
socket.emit('sys', '{ "sys": { "dataset": { "build": "' + name + '" } } }');
111+
}, (Math.ceil(1000 * Math.random()) ));
112+
}
113+
114+
state_learning = 'learning';
115+
progressbar_win.dialog("open");
116+
for (var i=0; i < dataset_list.length; i++)
117+
if(dataset_list[i].name.indexOf("Nothing") == -1)
118+
build_classifier_delay(dataset_list[i].name);
119+
}
120+
121+
// If training program is generated, start learning process
122+
function speaker_build_classifier(obj){
123+
if (state_learning != 'learning') return;
124+
125+
if(obj.sys.dataset)
126+
if (obj.sys.dataset.build && obj.sys.dataset.status){
127+
//console.log("TRAINING PROGRESS " + obj.sys.dataset.build)
128+
if(obj.sys.dataset.status == 'running'){
129+
progressLabel.text( "Preparing training program for " + obj.sys.dataset.build );
130+
if (obj.sys.dataset.data.indexOf("[DONE]") != -1){
131+
var val = progressbar.progressbar( "value" ) + Math.ceil(20 / (dataset_list.length) / 2);
132+
progressbar.progressbar( "value", val );
133+
}
134+
}
135+
136+
for (i=0; i < dataset_list.length; i++){
137+
if(dataset_list[i].name == obj.sys.dataset.build && obj.sys.dataset.status == 'done'){
138+
//console.log("TRAINING DONE\n")
139+
dataset_list[i].state = 'training';
140+
socket.emit('sys', '{ "sys": { "training": { '+
141+
'"build": "' + obj.sys.dataset.build + '", "structure":"24", "epoch":64, "learning_rate":0.01, "filter_low":0, "filter_high":'+Math.ceil((636- Math.ceil(4400-50)*0.042))+' } } }');
142+
}
143+
}
144+
}
145+
146+
if(obj.sys.training)
147+
if(obj.sys.training.build && obj.sys.training.status){
148+
149+
if(obj.sys.training.status == 'running'){
150+
progressLabel.text( "Learning process for " + obj.sys.training.build );
151+
if (obj.sys.training.data.indexOf("[DONE]") != -1) {
152+
var val = progressbar.progressbar( "value" ) + Math.ceil(20 / (dataset_list.length) / 2);
153+
progressbar.progressbar( "value", val );
154+
}
155+
156+
if( obj.sys.training.data.indexOf("classifier") != -1 ){
157+
console.log('ici ; ' + obj.sys.training.data)
158+
for (i=0; i < dataset_list.length; i++)
159+
if(dataset_list[i].name == obj.sys.training.build) {
160+
if( obj.sys.training.data.indexOf("Strong classifier") != -1 )
161+
dataset_list[i].state = 'built_strong';
162+
else if( obj.sys.training.data.indexOf("Weak classifier") != -1 )
163+
dataset_list[i].state = 'built_weak';
164+
}
165+
}
166+
167+
}
168+
169+
done = true;
170+
for (i=0; i < dataset_list.length; i++){
171+
if(dataset_list[i].name == obj.sys.training.build && obj.sys.training.status == 'done'){
172+
//console.log("LEARNING DONE\n")
173+
if (dataset_list[i].state.indexOf("built") == -1)
174+
dataset_list[i].state = 'error';
175+
}
176+
177+
// If all learnings are done, close the progress bar
178+
if (dataset_list[i].state.indexOf('built') == -1 && dataset_list[i].name != 'Nothing.dat')
179+
done = false;
180+
}
181+
if (done) {
182+
state_learning = '';
183+
progressbar_win.dialog("close");
184+
progressbar.progressbar( "value", 0 );
185+
}
186+
}
187+
}
68188

69189
state = "record";
70-
function speaker_stats_new_process (obj){
190+
stop_record = false;
191+
var dataset_list = [];
192+
lock_loop_new = -1;
71193

194+
function speaker_stats_new_record (obj){
195+
// console.log(JSON.stringify(obj));
72196
if (state == "encoding" && obj.sys.records){
73197
document.getElementById('speaker_stats_new_progress_bar').innerHTML = "Sample encoding processing, waiting ... " + obj.sys.records.build + "<br>" ;
74198
if (obj.sys.records.build == new_speaker && obj.sys.records.status == "done" ){
75199
new_speaker = "";
76200
state = "record";
77201
new_speaker_count = 0;
202+
stop_record = false;
78203
state = "record";
79204
$('#speaker_stats_new_init').show();
80-
$('#speaker_stats_new_progress_bar').hide();
81-
console.log("Terminated");
205+
$('#speaker_stats_new_progress').hide();
206+
//console.log("Terminated");
207+
208+
socket.emit('sys', JSON.stringify({sys:{dataset:{list:''}} }));
82209
dialog_new.dialog('close');
83210
}
84211
}
212+
// If input has been reset because finised
213+
// if(obj.sys.sample_count == 0 && lock_loop_new > 0)
214+
// lock_loop_new = 0;
85215

86216
if(state == "record" && obj.sys.state == 'ready' && new_speaker != ""){
87-
if (new_speaker_count > 10){
88-
console.log("Record Encoding");
217+
218+
if (new_speaker_count > 100 || stop_record){
219+
//console.log("Record Encoding");
89220
state = "encoding";
90221
socket.emit('sys', '{ "sys": { "records": { "build": "' + new_speaker + '" } } }');
91222
socket.emit('sys', JSON.stringify( {sys:{control:'play'}} ));
92-
93-
console.log("DONE");
223+
//console.log("DONE");
94224
}
95-
else setTimeout(function(){socket.emit('sys', JSON.stringify( {sys:{control:'next'}} ));}, 250);
225+
else if (Math.abs(obj.sys.sample_count - lock_loop_new) <= 1){
96226

97-
if(obj_data.analysis.result.length == 1 && obj_data.analysis.result[0] == "Don t Know" && new_speaker != ""){
98-
console.log("save sample\n");
99-
socket.emit('sys', JSON.stringify( {sys:{sample: new_speaker+'('+obj_data.chan+')', classe:"+"}} ));
100-
new_speaker_count ++;
227+
if(obj_data.analysis.result.length == 1 && obj_data.analysis.result[0] == "Don t Know" && new_speaker != ""){
228+
//console.log("save sample\n");
229+
socket.emit('sys', JSON.stringify( {sys:{sample: new_speaker+'('+obj_data.chan+')', classe:"+"}} ));
230+
new_speaker_count ++;
231+
}
232+
lock_loop_new = obj.sys.sample_count > lock_loop_new? obj.sys.sample_count: obj.sys.sample_count-1;
233+
setTimeout(function(){socket.emit('sys', JSON.stringify( {sys:{control:'next'}} ));}, 250);
101234
}
102-
document.getElementById('speaker_stats_new_progress_bar').innerHTML = 'Recording ... ' + new_speaker_count +" / 50 samples<br>";
235+
236+
else lock_loop_new = obj.sys.sample_count;
237+
document.getElementById('speaker_stats_new_progress_bar').innerHTML = 'Recording ... ' + new_speaker + " - "+ new_speaker_count +" / 100 samples<br>";
238+
}
239+
}
240+
241+
function speaker_stats_update_print(){
242+
var list = "";
243+
for (var i=0; i < dataset_list.length; i++){
244+
if (dataset_list[i].state == "recorded") color = "black";
245+
else if (dataset_list[i].state == "training") color = "blue";
246+
else if (dataset_list[i].state == "built_strong") color = "green";
247+
else if (dataset_list[i].state == "built_weak") color = "orange";
248+
else if (dataset_list[i].state == "error") color = "red";
249+
250+
list += '<span style="color:'+color+'; margin:10px;">' + dataset_list[i].name + '</span> ';
251+
}
252+
253+
$('#speaker_stats_lists').html(list);
254+
}
255+
256+
function speaker_stats_update_dataset_list(obj){
257+
if (obj.sys.dataset)
258+
if(obj.sys.dataset.list){
259+
dataset_list = new Array();
260+
var list = "";
261+
for (var i=0; i < obj.sys.dataset.list.length; i++)
262+
if(dataset_list.indexOf(obj.sys.dataset.list[i]) == -1)
263+
dataset_list.push({name:obj.sys.dataset.list[i], state:"recorded"});
103264
}
104265
}
105266

106267
socket.on('sys', function(msg){
107268
try {
108269
obj = JSON.parse(msg.toString());
109-
speaker_stats_new_process(obj);
270+
271+
speaker_stats_new_record(obj);
272+
speaker_build_classifier(obj);
273+
274+
speaker_stats_update_dataset_list(obj);
275+
speaker_stats_update_print();
110276
}
111277
catch(err){
112278
console.log("Error on sys: " + err + " MSG received: "+ msg.toString());
113279
}
114280
});
115281

116282

117-
/*
118-
* END AUTO RECORD OF NEW SPEAKER
119-
*/
283+
/******************************************************************************/
284+
/* Pie chart view */
285+
/******************************************************************************/
120286

121287
var dialog = this.dialog = $( '#speaker_stats' ).dialog({
122288
autoOpen: true,
123289
width:650,
124290
modal: false,
125291
dialogClass: 'speaker_stats',
126292
buttons:{
127-
NEW: function(){
128-
293+
RESET_ALL: function(){
294+
socket.emit('sys', JSON.stringify( {sys:{init:''}}));
295+
setTimeout(function(){
296+
socket.emit('sys', JSON.stringify({sys:{dataset:{list:''}} }));
297+
}, 500);
298+
},
299+
ADD_SPEAKER: function(){
129300
dialog_new.dialog('open');
130301
},
131-
BUILD: function(){
132-
302+
BUILD_ALL: function(){
303+
speaker_build_classifier_init();
133304
},
134305
START:function(){
135306
speakers_count = [['Speaker', 'Score']];
307+
speaker_start();
136308
},
137309
}
138310
});
139311

312+
140313
var speaker_stats_piechart = new google.visualization.PieChart(document.getElementById('speaker_stats_piechart'));
314+
// Load list of recorded dataset
315+
setTimeout(function(){
316+
socket.emit('sys', JSON.stringify({sys:{dataset:{list:''}} }));
317+
}, 500);
318+
141319
this.show = function(){
142320
this.dialog.dialog('open');
143321
}
@@ -156,7 +334,6 @@ function SpeakerStats(parent, names){
156334
height:"100%"
157335
}
158336
};
159-
160337
speaker_stats_piechart.draw(data, options);
161338
}
162339

@@ -165,11 +342,8 @@ function SpeakerStats(parent, names){
165342

166343
socket.on('sys', function(msg){
167344

168-
169-
170345
try {
171346
obj = JSON.parse(msg.toString());
172-
// speaker_stats_new_process(obj);
173347
}
174348
catch(err){
175349
console.log("Error on sys: " + err + " MSG received: "+ msg.toString());

0 commit comments

Comments
 (0)