如何使用预先训练。模型文件Android Studio中的预测?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用预先训练。模型文件Android Studio中的预测?相关的知识,希望对你有一定的参考价值。
我已经练就了Weka 3.8 Dekstop版本决策表ML模型。我在我的资产文件夹中保存相应的型号和配置的wekaSTRIPPED.jar文件中。在这一点上,构建似乎在android Studio的是工作的罚款。然而,当我尝试使用Java中的分类模型,我得到了一些红色的亮点 - 错误 - 在我的代码,我无法自动修复。
我曾参观过一些在线指南here,并参观了这个常用秧鸡,Android的参考here和here。他们遵循相同的结构,我刚才在我的代码在做(不同型号),但我并没有在Android Studio中进行编译。
package com.example.owner.introductoryapplication;
import android.support.v7.app.AppCompatActivity;
import weka.classifiers.Classifier;
import weka.classifiers.rules.DecisionTable;
import weka.core.Attribute;
import weka.core.DenseInstance;
import weka.core.Instances;
import java.util.ArrayList;
public class Test extends AppCompatActivity {
public static void main(String[] args) throws Exception {
Test test = new Test();
test.start();
}
public void start() throws Exception {
//LOADS THE MODEL...
String rootPath = "/assets/";
String fileName = "PGBD_DecisionTableUPD.model";
//Classifier cls = null;
Classifier cls = (Classifier) weka.core.SerializationHelper.read(rootPath + fileName);
我希望输出简单地建立;我不希望因为我还没有指定的测试数据集的任何预测输出。然而,当我这样做单击编译,没有任何条款都突出红色的屏幕上。
具体来说,之后我运行它,我得到Compilation failed; see the compiler error output for details.
在构建控制台依次为:
"C:Program FilesAndroidAndroid Studiojreinjava.exe" -Didea.launcher.port=64163 "-Didea.launcher.bin.path=C:Program FilesAndroidAndroid Studioin" -Dfile.encoding=UTF-8 -classpath "C:UsersOwnerAppDataLocalAndroidSdkplatformsandroid-28android.jar;C:UsersOwnerAppDataLocalAndroidSdkplatformsandroid-28data
es;C:UsersOwnerAndroidStudioProjectsIntroductoryApplicationappuildintermediatesjavacdebugcompileDebugJavaWithJavacclasses;C:UsersOwnerAndroidStudioProjectsIntroductoryApplicationappuildgenerated
es
sdebug;C:UsersOwnerAndroidStudioProjectsIntroductoryApplicationappuildgenerated
es
esValuesdebug;C:UsersOwner.gradlecaches ransforms-1files-1.1customview-28.0.0.aar14e09720fc7f657365dec6e786490d47jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1localbroadcastmanager-28.0.0.aard791f241c61f09475b5d43561b131f77jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1support-vector-drawable-28.0.0.aarc8f91860fd6811b7040ad585c1bb749fjarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1interpolator-28.0.0.aar73289dbc6711e8292415efe83a859a43jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1support-core-utils-28.0.0.aar2dc7d30dd7abd1c4b0846462e1137cc4jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1support-core-ui-28.0.0.aar5199754cf7a7bf403b3073b69edcfe3jarsclasses.jar;C:UsersOwnerAndroidStudioProjectsIntroductoryApplicationapplibswekaSTRIPPED.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1slidingpanelayout-28.0.0.aar32aa91f4149120a8a428b24c5291b432jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1viewmodel-1.1.1.aar3477f32913f9b9934a8185f031c05533jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1drawerlayout-28.0.0.aarfb4eb97f205f1db9a43db5a200619a5jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1coordinatorlayout-28.0.0.aaraba273524bbeff5bfab162bc52fb07b9jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1coordinatorlayout-28.0.0.aaraba273524bbeff5bfab162bc52fb07b9
es;C:UsersOwner.gradlecachesmodules-2files-2.1com.android.supportcollections28.0.0c1bcdade4d3cc2836130424a3f3e4182c666a745collections-28.0.0.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1documentfile-28.0.0.aare49f57095504cc48cc7ba2b26757daf1jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1constraint-layout-1.1.3.aar96728e03169a340c5e642682fbd18ff8jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1constraint-layout-1.1.3.aar96728e03169a340c5e642682fbd18ff8
es;C:UsersOwner.gradlecaches ransforms-1files-1.1swiperefreshlayout-28.0.0.aara560a21fcde6d062081d9c09634c92a8jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1cursoradapter-28.0.0.aar733ca7f2a61e46bdb2164e238fe8c4b6jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1asynclayoutinflater-28.0.0.aarf950d05bc8679714fb0d7642259e29ebjarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1livedata-1.1.1.aar400a5420ad5e4bcef8ebbebf2123e101jarsclasses.jar;C:UsersOwner.gradlecachesmodules-2files-2.1android.arch.corecommon1.1.1e55b70d1f5620db124b3e85a7f4bdc7bd48d9f95common-1.1.1.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1versionedparcelable-28.0.0.aar12c3dd068050bf0422d8455749982d52jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1
untime-1.1.1.aar68e9f88e3e623f899ee79dd4aa8966f1jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1print-28.0.0.aarf12fdac753fb8cbf34b55eced23a29c7jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1loader-28.0.0.aar f1fa1caaba4127fdcb1d7bb76f1c144jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1viewpager-28.0.0.aardf7976216feddc6d17d8052bf1807dbjarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1support-fragment-28.0.0.aardf9931f8c3d84779819dccebe1aa6282jarsclasses.jar;C:UsersOwner.gradlecachesmodules-2files-2.1com.android.supportsupport-annotations28.0.0ed73f5337a002d1fd24339d5fb08c2c9d9ca60d8support-annotations-28.0.0.jar;C:UsersOwner.gradlecachesmodules-2files-2.1android.arch.lifecyclecommon1.1.1207a6efae6a3555e326de41f76bdadd9a239cbcecommon-1.1.1.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1livedata-core-1.1.1.aarf5b8b9e2bbbf6e16caa00d091d538f2fjarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1support-compat-28.0.0.aar fefdb1435b453663f8b867197d75a41jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1support-compat-28.0.0.aar fefdb1435b453663f8b867197d75a41
es;C:UsersOwner.gradlecaches ransforms-1files-1.1animated-vector-drawable-28.0.0.aar7eca742b05d3ca93c5f22855deb68690jarsclasses.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1appcompat-v7-28.0.0.aar5690672012030cd411a187af3fc56e5
es;C:UsersOwner.gradlecaches ransforms-1files-1.1appcompat-v7-28.0.0.aar5690672012030cd411a187af3fc56e5jarsclasses.jar;C:UsersOwner.gradlecachesmodules-2files-2.1com.android.support.constraintconstraint-layout-solver1.1.3de0667d7414c16ed62d3cfe993cff7f9d732373constraint-layout-solver-1.1.3.jar;C:UsersOwner.gradlecaches ransforms-1files-1.1
untime-1.1.1.aar33f18eb28c72c82424fc1a72a917596jarsclasses.jar;C:Program FilesAndroidAndroid Studiolibidea_rt.jar" com.intellij.rt.execution.application.AppMainV2 com.example.owner.introductoryapplication.Test
Exception in thread "main" java.lang.RuntimeException: Stub!
at android.content.Context.<init>(Context.java:67)
at android.content.ContextWrapper.<init>(ContextWrapper.java:30)
at android.view.ContextThemeWrapper.<init>(ContextThemeWrapper.java:40)
at android.app.Activity.<init>(Activity.java:643)
at android.support.v4.app.SupportActivity.<init>(ComponentActivity.java:46)
at android.support.v4.app.FragmentActivity.<init>(FragmentActivity.java:68)
at android.support.v7.app.AppCompatActivity.<init>(AppCompatActivity.java:62)
at com.example.owner.introductoryapplication.Test.<init>(Test.java:13)
at com.example.owner.introductoryapplication.Test.main(Test.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Process finished with exit code 1
不过,从我的理解,我已经列入我的资产文件夹中的文件.MODEL;应该认识到的文件路径。
因此,这引出了一个问题:如何将启用Android Studio来处理我的PGBD_DecisionTable.model
文件,我会怎么用它测试数据(直接在手机上的)?
使用.open("PGBD_DecisionTable.model")
的.open(PGBD_DecisionTable.model)
代替。
你正试图从一个常量表达式String
,不是一类名为PGBD_DecisionTable
的静态属性加载文件。
以上是关于如何使用预先训练。模型文件Android Studio中的预测?的主要内容,如果未能解决你的问题,请参考以下文章