保存的模型,预测结果与Notebook中的不一致
Created by: hubu-wangpei
使用相同的模型,相同的代码,结果不一致 linux下,用的版本是paddlepaddle-gpu 1.7.1.post97 ,Windows下自动安装的是paddlepaddle1.7.2 CPU版本
from paddle.fluid.dygraph import TracedLayer
import cv2
import random
import numpy as np
from scipy import misc
import os
import paddle
import paddle.fluid as fluid
from paddle.fluid.layer_helper import LayerHelper
from paddle.fluid.dygraph.nn import Conv2D, Pool2D, BatchNorm, Linear
from paddle.fluid.dygraph.base import to_variable
from paddle.fluid.initializer import NumpyArrayInitializer
def data_loader(filename):
filethpath="/home/aistudio/data/data26700/images_stego"
full_filename = os.path.join(filethpath, filename)
img = misc.imread(full_filename,0)
img = img[np.newaxis, :]
img = img[np.newaxis, :]
img = img.astype('float32')
return img
place = fluid.CPUPlace()
main_prog = fluid.Program()
startup_prog = fluid.Program()
exe = fluid.Executor(place)
exe.run(startup_prog)
path = "./saved_infer_model"
filename="6_1.pgm"
img = data_loader(filename)
[inference_program, feed_target_names, fetch_targets] = (fluid.io.load_inference_model(dirname=path, executor=exe))
results = exe.run(inference_program,
feed={feed_target_names[0]: img},
fetch_list=fetch_targets)
print(results)