2013-05-08 73 views
1

我面临从sdcard加载保存模型的问题。 在Weka的官方wiki中,我发现了两种反序列化序列化模型的方法,但其中没有一种适用于Android。如何在Weka-for-Android中反序列化保存的模型

//First Method 
RandomForest rf = (RandomForest) weka.core.SerializationHelper. 
    read(Environment.getExternalStorageDirectory().getPath() + "/BC.model"); 

//Second Method 
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
    Environment.getExternalStorageDirectory().getPath() + "/BC.model")); 
RandomForest rf = new RandomForest(); 
rf = (RandomForest) ois.readObject(); 

我得到的logcat此错误:

java.io.InvalidClassException: 
    weka.classifiers.trees.RandomForest; Incompatible class (SUID): 
    weka.classifiers.trees.RandomForest 

回答

0
 InputStream is = this.getAssets().open("example.model"); 
     ObjectInputStream ois = new ObjectInputStream(is); 
     cls = (Classifier) ois.readObject(); 
     ois.close(); 

你可以把它放到你的模型在资产的文件夹。请让我知道它是否有效。

+1

感谢Henry对你的回应:) 问题不在于我是否找到模型文件,我认为问题在于将ios.readObect转换为RandomForest。 我试图把它放在资产,但没有任何改变。 – 2013-05-29 15:38:14

1

在android中,您只能加载由您的android应用程序序列化的分类器模型。否则,由于不兼容的Serializable UID,您将得到异常。

相关问题