Emgu.CV DTrees训练System.AccessViolationException

时间:2017-10-04 08:41:38

标签: c# artificial-intelligence emgucv

我使用此函数从Emgu.CV库中训练我的DTrees对象。

public void Learn_Internal(double[][] aadMlInpFv, int[] anMlOutGt)
{
    if (aadMlInpFv == null || aadMlInpFv.Length == 0) return;
    try
    {
        //Use the first 80% of data as training sample
        int trainingSampleCount = (int)(aadMlInpFv.Length * 0.8);

        Matrix<Byte> varType = new Matrix<byte>(aadMlInpFv[0].Length + 1, 1);
        varType.SetValue((byte)VarType.Categorical); //the data is categorical

        Matrix<byte> sampleIdx = new Matrix<byte>(aadMlInpFv.Length, 1);
        using (Matrix<byte> sampleRows = sampleIdx.GetRows(0, trainingSampleCount, 1))
            sampleRows.SetValue(255);

        //Matrix<double> trainData = new Matrix<double>(aadMlInpFv.Length, aadMlInpFv[0].Length);
        Matrix<float> trainData = new Matrix<float>(aadMlInpFv.Length, aadMlInpFv[0].Length);
        for (int i = 0; i < aadMlInpFv.Length; i++)
        {
            for (int j = 0; j < aadMlInpFv[i].Length; j++)
            {
                trainData[i, j] = (float)aadMlInpFv[i][j];
            }
        }

        Matrix<int> trainClasses = new Matrix<int>(anMlOutGt);
        using (TrainData td = new TrainData(trainData, DataLayoutType.RowSample, trainClasses))
        {
            m_oModelDTree.Train(td);
        }
    }
    catch (Exception ex)
    {
    }
}

它会导致异常:System.AccessViolationException:'尝试读取或写入受保护的内存。这通常表明其他记忆已经腐败。 m_oModelDTree是DTrees初始化的对象:

m_oModelDTree = new DTrees()
        {
            MaxDepth = 8,
            MinSampleCount = 10,
            RegressionAccuracy = 0,
            UseSurrogates = true,
            MaxCategories = 15,
            CVFolds = 10,
            Use1SERule = true,
            TruncatePrunedTree = true
        };

我已经在Emgu.CV中实现了其他分类器模型,如KNN,AdaBoost等,就像这种方法一样,除了DTrees之外,它们都可以工作。 这有什么问题?

修改 抛出异常:m_oModelDTree.Train(td);

0 个答案:

没有答案