コード例 #1
0
def testGenderClassification(network,networkFile,maleDataDir,femaleDataDir,signalClass,signalCount,resultsFolder):
   print '----------------------------------------------------------------'
   print '***** Running FeedForward Test with parameters:\n'
   print '* networkfile    : %s' %(networkFile)
   print '* signalCount    : %s' %(signalCount)
   print '* signalClass    : %s' %(signalClass.__name__)
   print '* maleDataDir    : %s' %(maleDataDir)
   print '* femaleDataDir  : %s' %(femaleDataDir)
   print '* resultsFolder  : %s' %(resultsFolder) 
   print '----------------------------------------------------------------'

   """
      Computing results folder
   """
   run_path = createRunFolder(resultsFolder=resultsFolder)

   print '**** Dumping results in directory: \"%s\"' %(run_path)
   print '----------------------------------------------------------------'
   input_params_file = os.path.join(run_path,'inputParams.txt')
   input_params = {
      'networkfile':networkFile,
      'signalCount':signalCount,
      'signalClass':signalClass.__name__,
      'maleDataDir':maleDataDir,
      'femaleDataDir':femaleDataDir,
      'resultsFolder':resultsFolder 
   }
   writeAsJson(input_params,input_params_file,indent=4)

   #extracting female and male samples. All samples will be used for testing
   _,female_test_samples = getData(femaleDataDir,network.signalLength,network.signalCount,testProportion=1.0)
   _,male_test_samples = getData(maleDataDir,network.signalLength,signalCount,testProportion=1.0)

   test_inputs,test_targets,test_mfccfiles = combineSamples(female_test_samples,male_test_samples)
   test_dataset = (test_inputs,test_targets,test_mfccfiles)   

   test_results_file = os.path.join(run_path,'test_results.txt')
   test_error = testOnCustomDataset(test_dataset,network,signalClass,test_results_file)

   test_accuracy = 1-test_error

   print '----------------------------------------------------------------'
   print '**** Dataset Test Results:'
   print '----------------------------------------------------------------'
   print '* Test Dataset Accuracy: %s' %(test_accuracy)
   print '* Test Dataset Error %s' %(test_error)
   print '----------------------------------------------------------------'
   print 'Dumping Results in \"test_results.txt\" file '
   print '----------------------------------------------------------------'