本文整理汇总了Java中org.nd4j.linalg.api.ndarray.INDArray.reshape方法的典型用法代码示例。如果您正苦于以下问题:Java INDArray.reshape方法的具体用法?Java INDArray.reshape怎么用?Java INDArray.reshape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.nd4j.linalg.api.ndarray.INDArray
的用法示例。
在下文中一共展示了INDArray.reshape方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.nd4j.linalg.api.ndarray.INDArray; //导入方法依赖的package包/类
public static void main(String[] args) {
MultiLayerNetwork restored;
try {
File locationToSave = new File(PATH_TO_MODEL_FILE);
restored = ModelSerializer.restoreMultiLayerNetwork(locationToSave);
BufferedImage img = ImageIO.read(new File("/Users/Emaraic/Desktop/UNKNOWN1.png"));
BufferedImage image = convertToBufferedImage(img.getScaledInstance(32, 32, Image.SCALE_DEFAULT)); //crop image to size 32 X 32
double[][] values = imageToMat(image);//convert image data to 2d matrix
double[] flat = Arrays.stream(values)// convert 2d array to 1d array
.flatMapToDouble(Arrays::stream)
.toArray();
double [] temp=new double [flat.length];
for (int i = 0; i < flat.length; i++) { //convert (Black char and weight background) image to (weight char and black background) image
if(flat[i]==255)
temp[i]=0.0;
else
temp[i]= 255.0;
}
INDArray ss = Nd4j.create(temp, new int[]{32, 32}); // reshape mat to 32X32 just fot printing it
System.out.println(ss);
INDArray ss1 = ss.reshape(new int[]{1, 1024}); // flat it again
INDArray output = restored.output(ss1); //feed input vector to restored nn and receive the output vector
System.out.println(output);
int idx = Nd4j.getExecutioner().execAndReturn(new IAMax(output)).getFinalResult();//get index of best result
System.out.println("Result is : "+ALPHABET[idx - 1]);
} catch (IOException ex) {
ex.printStackTrace();
}
}