2017-01-26 51 views
0

在執行了在自己的項目中,我得到以下錯誤MNIST例如:java.lang.NoSuchFieldError的:HALF誤差DL4J

o.n.l.f.Nd4jBackend - Loaded [CpuBackend] backend 
Exception in thread "main" java.lang.NoSuchFieldError: HALF 
    at org.nd4j.linalg.factory.Nd4j.initWithBackend(Nd4j.java:5593) 
    at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5554) 
    at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:189) 
    at org.deeplearning4j.nn.conf.NeuralNetConfiguration$Builder.seed(NeuralNetConfiguration.java:624) 
    at com.baus.visualagent.DigitTrainer.startTraining(DigitTrainer.java:47) 
    at com.baus.visualagent.App.main(App.java:17) 
    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:497) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) 

這將是可愛的,如果我能知道是什麼原因造成了這個問題。是否由於POM文件未正確配置或其他原因?

的POM文件內容是:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.baus.visualagent</groupId> 
    <artifactId>Visual Agent</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>Visual Agent</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <nd4j.backend>nd4j-native-platform</nd4j.backend> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <shadedClassifier>bin</shadedClassifier> 
     <java.version>1.8</java.version> 
     <nd4j.version>0.7.2</nd4j.version> 
     <dl4j.version>0.7.2</dl4j.version> 
     <datavec.version>0.7.2</datavec.version> 
     <arbiter.version>0.7.2</arbiter.version> 
     <rl4j.version>0.7.2</rl4j.version> 
     <guava.version>19.0</guava.version> 
     <logback.version>1.1.7</logback.version> 
     <jfreechart.version>1.0.13</jfreechart.version> 
     <jcommon.version>1.0.23</jcommon.version> 
     <maven-shade-plugin.version>2.4.3</maven-shade-plugin.version> 
     <exec-maven-plugin.version>1.4.0</exec-maven-plugin.version> 
     <maven.minimum.version>3.3.1</maven.minimum.version> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 

     <dependency> 
      <groupId>org.nd4j</groupId> 
      <artifactId>nd4j-native-platform</artifactId> 
      <version>${nd4j.version}</version> 
     </dependency> 

     <dependency> 
      <groupId>org.deeplearning4j</groupId> 
      <artifactId>deeplearning4j-core</artifactId> 
      <version>0.7.2</version> 
     </dependency> 

     <dependency> 
      <groupId>org.deeplearning4j</groupId> 
      <artifactId>deeplearning4j-nlp</artifactId> 
      <version>0.7.2</version> 
     </dependency> 

     <dependency> 
      <groupId>org.nd4j</groupId> 
      <artifactId>canova-nd4j-image</artifactId> 
      <version>0.0.0.17</version> 
     </dependency> 

     <dependency> 
      <groupId>org.nd4j</groupId> 
      <artifactId>canova-nd4j-codec</artifactId> 
      <version>0.0.0.17</version> 
     </dependency> 

     <dependency> 
      <groupId>org.nd4j</groupId> 
      <artifactId>nd4j-api</artifactId> 
      <version>0.7.2</version> 
     </dependency> 

     <dependency> 
      <groupId>org.nd4j</groupId> 
      <artifactId>nd4j-blas</artifactId> 
      <version>unknown</version> 
     </dependency> 
     <dependency> 
      <groupId>org.nd4j</groupId> 
      <artifactId>nd4j-x86</artifactId> 
      <version>0.4-rc3.8</version> 
     </dependency> 
     <dependency> 
      <groupId>org.nd4j</groupId> 
      <artifactId>nd4j-examples</artifactId> 
      <version>0.0.3.5.4</version> 
     </dependency> 
     <dependency> 
      <groupId>org.deeplearning4j</groupId> 
      <artifactId>dl4j-examples</artifactId> 
      <version>0.7-SNAPSHOT</version> 
     </dependency> 

     <dependency> 
      <groupId>org.deeplearning4j</groupId> 
      <artifactId>deeplearning4j-modelimport</artifactId> 
      <version>0.7.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.deeplearning4j</groupId> 
      <artifactId>deeplearning4j-nn</artifactId> 
      <version>0.7.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.deeplearning4j</groupId> 
      <artifactId>deeplearning4j-ui</artifactId> 
      <version>0.6.0</version> 
     </dependency> 

    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-enforcer-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>enforce-default</id> 
         <goals> 
          <goal>enforce</goal> 
         </goals> 
         <configuration> 
          <rules> 
           <requireMavenVersion> 
            <version>[${maven.minimum.version},)</version> 
            <message>********** Minimum Maven Version is ${maven.minimum.version}. Please upgrade Maven before continuing (run "mvn --version" to check). **********</message> 
           </requireMavenVersion> 
          </rules> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

該代碼由2類:

  1. 稱爲應用
  2. 稱爲DigitTrainer
  3. 神經網絡類的主要類

應用程序的代碼如下:

public class App 
{ 
    public static void main(String[] args)throws IOException 
    { 
     DigitTrainer t=new DigitTrainer(); 
     t.startTraining(); 
     t.startTesting(); 
    } 
} 

DigitTrainer的代碼如下:當你用不同的.class文件跑得比你使用,當你編譯

public class DigitTrainer { 
    private int layers; 
    private int rows; 
    private int cols; 
    private int out; 
    private int batch; 
    private int seed; 
    private int epochs; 
    private DataSetIterator test,train; 
    private MultiLayerConfiguration config; 
    private MultiLayerNetwork ann; 

    public DigitTrainer() throws IOException { 
     rows=28; 
     cols=28; 
     out=10; 
     batch=128; 
     seed=123; 
     epochs=20; 
     train=new MnistDataSetIterator(batch,true,seed); 
     test=new MnistDataSetIterator(batch,false,seed); 
    } 
    public void startTraining(){ 
     config = new NeuralNetConfiguration.Builder() 
       .seed(seed) 
       .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) 
       .iterations(1) 
       .learningRate(0.006) 
       .updater(Updater.NESTEROVS) 
       .momentum(0.9) 
       .regularization(true).l2(1e-4) 
       .list() 
       .layer(0, new DenseLayer.Builder() 
         .nIn(rows*cols) 
         .nOut(1000) 
         .activation(Activation.IDENTITY) 
         .weightInit(WeightInit.XAVIER) 
         .build()) 
       .layer(1, new DenseLayer.Builder() 
         .nIn(1000) 
         .nOut(out) 
         .activation(Activation.SIGMOID) 
         .weightInit(WeightInit.XAVIER) 
         .build()) 
       .pretrain(false) 
       .backprop(true) 
       .build(); 
     ann=new MultiLayerNetwork(config); 
     ann.init(); 
     ann.setListeners(new ScoreIterationListener(1)); 
     System.out.println("\n******Beginning Training******\n"); 
     for(int i=0;i<epochs;i++){ 
      ann.fit(train); 
     } 
     System.out.println("\n******Model Trained******\n"); 
    } 
    public void startTesting(){ 
     System.out.println("\n******Starting Testing******\n"); 
     Evaluation e=new Evaluation(out); 
     while(test.hasNext()){ 
      DataSet next = test.next(); 
      INDArray x=ann.output(next.getFeatureMatrix()); 
      e.eval(next.getLabels(),x); 
     } 
     System.out.println(e.stats()); 
    } 
} 
+0

請分享pom.xml中尋找到的東西也代碼,您正在執行 – nullpointer

回答

0

已解決。 我不得不降低依賴只包括:

<dependency> 
      <groupId>org.deeplearning4j</groupId> 
      <artifactId>deeplearning4j-core</artifactId> 
      <version>${dl4j.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.nd4j</groupId> 
      <artifactId>nd4j-native-platform</artifactId> 
      <version>${nd4j.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.datavec</groupId> 
      <artifactId>datavec-api</artifactId> 
      <version>${datavec.version}</version> 
     </dependency> 
    </dependencies> 

而且在配置層1的配置應該是:

.layer(1, new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD) 
         .nIn(1000) 
         .nOut(out) 
         .activation(Activation.SIGMOID) 
         .weightInit(WeightInit.XAVIER) 
         .build()) 
+0

對於未來的讀者,請注意:您的dl4j,nd4j和datavec版本應始終匹配。沒有例外。 –

0

發生時異常。當在運行時使用不同版本的庫時,會發生這種情況,而不是在編譯期間使用該庫。

相關問題