如何使用预先训练。模型文件Android Studio中的预测?

问题描述 投票:3回答:1

我已经练就了Weka 3.8 Dekstop版本决策表ML模型。我在我的资产文件夹中保存相应的型号和配置的wekaSTRIPPED.jar文件中。在这一点上,构建似乎在Android Studio的是工作的罚款。然而,当我尝试使用Java中的分类模型,我得到了一些红色的亮点 - 错误 - 在我的代码,我无法自动修复。

我曾参观过一些在线指南here,并参观了这个常用秧鸡,Android的参考herehere。他们遵循相同的结构,我刚才在我的代码在做(不同型号),但我并没有在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 Files\Android\Android Studio\jre\bin\java.exe" -Didea.launcher.port=64163 "-Didea.launcher.bin.path=C:\Program Files\Android\Android Studio\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\Owner\AppData\Local\Android\Sdk\platforms\android-28\android.jar;C:\Users\Owner\AppData\Local\Android\Sdk\platforms\android-28\data\res;C:\Users\Owner\AndroidStudioProjects\IntroductoryApplication\app\build\intermediates\javac\debug\compileDebugJavaWithJavac\classes;C:\Users\Owner\AndroidStudioProjects\IntroductoryApplication\app\build\generated\res\rs\debug;C:\Users\Owner\AndroidStudioProjects\IntroductoryApplication\app\build\generated\res\resValues\debug;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\customview-28.0.0.aar\14e09720fc7f657365dec6e786490d47\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\localbroadcastmanager-28.0.0.aar\d791f241c61f09475b5d43561b131f77\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-vector-drawable-28.0.0.aar\c8f91860fd6811b7040ad585c1bb749f\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\interpolator-28.0.0.aar\73289dbc6711e8292415efe83a859a43\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-core-utils-28.0.0.aar\2dc7d30dd7abd1c4b0846462e1137cc4\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-core-ui-28.0.0.aar\b5199754cf7a7bf403b3073b69edcfe3\jars\classes.jar;C:\Users\Owner\AndroidStudioProjects\IntroductoryApplication\app\libs\wekaSTRIPPED.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\slidingpanelayout-28.0.0.aar\32aa91f4149120a8a428b24c5291b432\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\viewmodel-1.1.1.aar\3477f32913f9b9934a8185f031c05533\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\drawerlayout-28.0.0.aar\bfb4eb97f205f1db9a43db5a200619a5\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\coordinatorlayout-28.0.0.aar\aba273524bbeff5bfab162bc52fb07b9\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\coordinatorlayout-28.0.0.aar\aba273524bbeff5bfab162bc52fb07b9\res;C:\Users\Owner\.gradle\caches\modules-2\files-2.1\com.android.support\collections\28.0.0\c1bcdade4d3cc2836130424a3f3e4182c666a745\collections-28.0.0.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\documentfile-28.0.0.aar\e49f57095504cc48cc7ba2b26757daf1\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\constraint-layout-1.1.3.aar\96728e03169a340c5e642682fbd18ff8\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\constraint-layout-1.1.3.aar\96728e03169a340c5e642682fbd18ff8\res;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\swiperefreshlayout-28.0.0.aar\a560a21fcde6d062081d9c09634c92a8\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\cursoradapter-28.0.0.aar\733ca7f2a61e46bdb2164e238fe8c4b6\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\asynclayoutinflater-28.0.0.aar\f950d05bc8679714fb0d7642259e29eb\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\livedata-1.1.1.aar\400a5420ad5e4bcef8ebbebf2123e101\jars\classes.jar;C:\Users\Owner\.gradle\caches\modules-2\files-2.1\android.arch.core\common\1.1.1\e55b70d1f5620db124b3e85a7f4bdc7bd48d9f95\common-1.1.1.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\versionedparcelable-28.0.0.aar\12c3dd068050bf0422d8455749982d52\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\runtime-1.1.1.aar\68e9f88e3e623f899ee79dd4aa8966f1\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\print-28.0.0.aar\f12fdac753fb8cbf34b55eced23a29c7\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\loader-28.0.0.aar\0f1fa1caaba4127fdcb1d7bb76f1c144\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\viewpager-28.0.0.aar\bdf7976216feddc6d17d8052bf1807db\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-fragment-28.0.0.aar\df9931f8c3d84779819dccebe1aa6282\jars\classes.jar;C:\Users\Owner\.gradle\caches\modules-2\files-2.1\com.android.support\support-annotations\28.0.0\ed73f5337a002d1fd24339d5fb08c2c9d9ca60d8\support-annotations-28.0.0.jar;C:\Users\Owner\.gradle\caches\modules-2\files-2.1\android.arch.lifecycle\common\1.1.1\207a6efae6a3555e326de41f76bdadd9a239cbce\common-1.1.1.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\livedata-core-1.1.1.aar\f5b8b9e2bbbf6e16caa00d091d538f2f\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-compat-28.0.0.aar\0fefdb1435b453663f8b867197d75a41\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\support-compat-28.0.0.aar\0fefdb1435b453663f8b867197d75a41\res;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\animated-vector-drawable-28.0.0.aar\7eca742b05d3ca93c5f22855deb68690\jars\classes.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\b5690672012030cd411a187af3fc56e5\res;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\b5690672012030cd411a187af3fc56e5\jars\classes.jar;C:\Users\Owner\.gradle\caches\modules-2\files-2.1\com.android.support.constraint\constraint-layout-solver\1.1.3\bde0667d7414c16ed62d3cfe993cff7f9d732373\constraint-layout-solver-1.1.3.jar;C:\Users\Owner\.gradle\caches\transforms-1\files-1.1\runtime-1.1.1.aar\b33f18eb28c72c82424fc1a72a917596\jars\classes.jar;C:\Program Files\Android\Android Studio\lib\idea_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文件,我会怎么用它测试数据(直接在手机上的)?

java android machine-learning classification weka
1个回答
0
投票

使用.open("PGBD_DecisionTable.model").open(PGBD_DecisionTable.model)代替。

你正试图从一个常量表达式String,不是一类名为PGBD_DecisionTable的静态属性加载文件。

© www.soinside.com 2019 - 2024. All rights reserved.