本文整理匯總了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();
}
}