Exemple #1
0
        static void Test(double[][] testData, string pathModel)
        {
            Console.WriteLine("Montando treino e target");
            SVMAudio mySVM = new SVMAudio();

            mySVM.LoadSVMFromFile(pathModel);
            int qtdAudio                 = testData.Length;
            int featuresSize             = testData[0].Length - 1;//menos a classe
            Image <Gray, float> features = new Image <Gray, float>(featuresSize, qtdAudio);
            Image <Gray, int>   target   = new Image <Gray, int>(1, qtdAudio);
            Image <Gray, float> results  = new Image <Gray, float>(1, qtdAudio);

            for (int audioIndex = 0; audioIndex < testData.Length; audioIndex++)
            {
                for (int j = 0; j < featuresSize; j++)
                {
                    features.Data[audioIndex, j, 0] = (float)testData[audioIndex][j];
                }
                target.Data[audioIndex, 0, 0] = (int)testData[audioIndex][featuresSize]; // posição da classe
            }
            Console.WriteLine("Testando");
            mySVM.Predict(features, results);
            int cont = 0;

            int[] qtd = new int[11];

            for (int i = 0; i < qtd.Length; i++)
            {
                qtd[i] = 0;
            }

            for (int i = 0; i < qtdAudio; i++)
            {
                Console.WriteLine("Correct: " + target.Data[i, 0, 0] + " Predicted: " + results.Data[i, 0, 0]);
                if (target.Data[i, 0, 0] == (int)results.Data[i, 0, 0])
                {
                    cont++;
                }
                qtd[target.Data[i, 0, 0]]++;
            }
            Console.WriteLine("Acc: " + (float)cont / qtdAudio);

            for (int i = 0; i < qtd.Length; i++)
            {
                Console.WriteLine("Quantidade " + i + ": " + qtd[i]);
            }
            Console.ReadKey();
        }
Exemple #2
0
        static void Train(double[][] trainData, string pathModel)
        {
            Console.WriteLine("Montando treino e target");
            SVMAudio            mySVM        = new SVMAudio();
            int                 qtdAudio     = trainData.Length;
            int                 featuresSize = trainData[0].Length - 1;//menos a classe
            Image <Gray, float> features     = new Image <Gray, float>(featuresSize, qtdAudio);
            Image <Gray, int>   target       = new Image <Gray, int>(1, qtdAudio);

            for (int audioIndex = 0; audioIndex < trainData.Length; audioIndex++)
            {
                for (int j = 0; j < featuresSize; j++)
                {
                    features.Data[audioIndex, j, 0] = (float)trainData[audioIndex][j];
                }
                target.Data[audioIndex, 0, 0] = (int)trainData[audioIndex][featuresSize]; // posição da classe
            }
            Console.WriteLine("Treinando");
            mySVM.Train(features, target);
            mySVM.SaveSVMToFile(pathModel);
        }
Exemple #3
0
        static float RecognizeAudio(string path, string svmModel)
        {
            SVMAudio mySVM = new SVMAudio();

            mySVM.LoadSVMFromFile(svmModel);
            double[] y = AudioFeatures.load2(path);
            double[,] mfcc_mass = MFCC_calculating.MFCC_20_calculation(y);
            double[]            features_vector = FeaturesFromMFCC(mfcc_mass);
            int                 features_size   = 100;
            Image <Gray, float> features        = new Image <Gray, float>(features_size, 1);
            Image <Gray, float> results         = new Image <Gray, float>(1, 1);

            AudioFeatures.NormalizeFromFile(@"C:\Projeto\autoleitura\paulorenato\AudioCSharp\Modelo\scaleSVMTrain.txt", features_vector);

            for (int i = 0; i < features_size; i++)
            {
                features.Data[0, i, 0] = (float)features_vector[i];
            }

            mySVM.Predict(features, results);
            return(results.Data[0, 0, 0]);
        }