2013-05-08 68 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,您將得到異常。

相關問題