简体   繁体   中英

NullReferenceException when trying to load Encog network from EG file

I'm trying to load Encog created network in C# code:

private void buttonImportNetwork_Click(object sender, EventArgs e)
{
    NeuralNetworkEffect.Network =
        (BasicNetwork) EncogDirectoryPersistence.LoadObject(new FileInfo(_networkFilePath));
}

I'm getting System.NullReferenceException. Here is the call stack:

"at Encog.Neural.Networks.PersistBasicNetwork.Read(Stream mask0)
at Encog.Persist.EncogDirectoryPersistence.LoadObject(Stream mask0)
at Encog.Persist.EncogDirectoryPersistence.LoadObject(FileInfo file)"

I tried multiple times with various files and paths, result the same. What am I doing wrong, did anybody encounter this and solved the issue?

OK, I found the reason. The EG file containing network definition produced by Encog Workbench contained invalid type for activation function, probably compatible with Java version of Encog package, but not with .Net version. In the EG file it was: "org.encog.engine.network.activation.ActivationTANH" but it should be: "ActivationTANH" . After removing Java namespaces the network was loaded without issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM