2017-01-26 15 views
0

와 HALF 오류 :이 문제의 원인을 알 수 있다면java.lang.NoSuchFieldError : 나는 다음과 같은 오류를 얻을 내 자신의 프로젝트에서 MNIST 예제를 실행하면 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. DigitTrainer
  2. 라는 신경망 클래스 앱라는 메인 클래스
다음과 같이

앱의 코드는 다음과 같습니다

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

그 예외가 당신이 컴파일 할 때 사용하는 것보다 발생 . 런타임시 다른 v 전의 라이브러리가 컴파일하는 동안 사용 된 경우에 _ 생할 수 있습니다.