Last active
June 25, 2019 08:45
-
-
Save AbdelmajidB/19a605acbc57eb8ad3173f9f2f63a29a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ma.enset.brain_tumor_segmentation; | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.URI; | |
import java.util.Arrays; | |
import org.datavec.api.io.labels.PathLabelGenerator; | |
import org.datavec.api.writable.NDArrayWritable; | |
import org.datavec.api.writable.Writable; | |
import org.datavec.image.loader.BaseImageLoader; | |
import org.datavec.image.loader.NativeImageLoader; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class MyPathLabelGenerator3d implements PathLabelGenerator{ | |
protected static final Logger log = LoggerFactory.getLogger(MyPathLabelGenerator3d.class); | |
String labelsDir; | |
NativeImageLoader imageLoader = new NativeImageLoader(32,32, 1, BaseImageLoader.MultiPageMode.MINIBATCH); | |
File file; | |
public MyPathLabelGenerator3d(String path) { | |
labelsDir=path; | |
} | |
public Writable getLabelForPath(String path) { | |
// TODO Auto-generated method stub | |
String dirName; | |
file=new File(path); | |
if(path.toLowerCase().contains("training")) | |
dirName=labelsDir+"/training/rois/"+file.getName().split("\\.")[0]+".tiff"; | |
else | |
dirName=labelsDir+"/testing/rois/"+file.getName().split("\\.")[0]+".tiff"; | |
try | |
{ | |
log.info(Arrays.toString(imageLoader.asMatrix(new File(dirName)).shape())); | |
return new NDArrayWritable(imageLoader.asMatrix(new File(dirName)).reshape('c', 1, 1, 32, 32, 32)); | |
} | |
catch(IOException ioe) | |
{ | |
ioe.printStackTrace(); | |
return null; | |
} | |
} | |
public Writable getLabelForPath(URI uri) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public boolean inferLabelClasses() { | |
// TODO Auto-generated method stub | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment