Skip to content

Commit

Permalink
- more robust torch unit test. Will search for root directory
Browse files Browse the repository at this point in the history
- Added better explanation
  • Loading branch information
Peter Abeles committed May 12, 2016
1 parent 842a185 commit 57a4ddc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import deepboof.graph.ForwardSequence;
import deepboof.impl.forward.standard.*;
import deepboof.io.torch7.struct.TorchObject;
import deepboof.misc.TensorOps;
import org.junit.Test;

import java.io.File;
Expand All @@ -34,16 +35,14 @@
import static deepboof.io.torch7.ConvertTorchToBoofForward.convert;
import static deepboof.misc.TensorOps.TH;
import static deepboof.misc.TensorOps.WI;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;

/**
* @author Peter Abeles
*/
public class TestConvertTorchToBoofForward {

File pathToData = new File("../io/src/test/torch7/data");
File pathToData = new File(TensorOps.pathToRoot(),"modules/io/src/test/torch7/data");

@Test
public void relu() {
Expand Down Expand Up @@ -119,7 +118,11 @@ public void spatialDropout() {
private void checkFunction(String directory , Class functionClass ) {
File pathToOp = new File(pathToData,directory);
if( !pathToOp.exists() ) {
fail("Have you generated data using torch?");
System.err.println("Can't find torch generated test data. To generate data run the following Linux shell script");
System.err.println();
System.err.println("DeepBoof/modules/io/src/test/torch7/generate_all.sh");
System.err.println();
fail("Missing torch data for "+directory);
}

int count = 0;
Expand Down
35 changes: 35 additions & 0 deletions modules/main/src/main/java/deepboof/misc/TensorOps.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import deepboof.Tensor;
import deepboof.tensors.Tensor_F64;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -237,4 +238,38 @@ public static int outerLength(int[] shape , int startDimen ) {
}
return D;
}

public static File pathToRoot() {
File active = new File(".").getAbsoluteFile();

while( active != null ) {
boolean foundModules = false;
boolean foundExamples = false;
boolean foundSettings = false;

File[] children = active.listFiles();
if( children == null )
break;

for( File d : children ) {
if( d.isDirectory() && d.getName().endsWith("modules")) {
foundModules = true;
}
if( d.isDirectory() && d.getName().endsWith("examples")) {
foundExamples = true;
}
if( d.isFile() && d.getName().equals("settings.gradle")) {
foundSettings = true;
}
}

if( foundModules && foundExamples && foundSettings ) {
return active;
} else {
active = active.getParentFile();
}
}
throw new RuntimeException("Cant find the project root directory");

}
}

0 comments on commit 57a4ddc

Please sign in to comment.