在python上有一个代码可以为分类准备图像:
test_image = image.load_img(image_path, target_size=(64, 64))
test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis=0)
test_image = test_image.astype('float') / 255.0
classifier = classifier_initialization()
classifier.load_weights('network.h5')
return classifier.predict(test_image)
有必要将其重写为Java,最接近原始结果的结果是:
NativeImageLoader loader = new NativeImageLoader(64, 64);
INDArray image = loader.asMatrix(file);
DataNormalization scalar = new ImagePreProcessingScaler(0,1);
scalar.transform(image);
INDArray output = model.output(image);
问题:要获得相同的结果还需要做些什么?