代码拉取完成,页面将自动刷新
源自github用户yjj19920505:
在很多示例代码里边都有下面这段代码,不过关于如何使用这个pkl的代码几乎没有。
Save the inference topology to protobuf.
with open("inference_topology.pkl", 'wb') as f:
inference_topology.serialize_for_inference(f)
我只查到下面这段记录,它用保存的params和inference_topology构造了一个inference。
with open(tarfn) as param_f, open(topology_filepath) as topo_f:
params = paddle.parameters.Parameters.from_tar(param_f)
inferer = paddle.inference.Inference(parameters=params, fileobj=topo_f)
这个inference的预测方法如下:
r = inferer.infer([d], feeding=feeding, field=fields)
和现有示例代码的预测方法完全不同
probs = paddle.infer(output_layer = y_pre, input = test_data, parameters = parameters)
因此想了解下inference_topology.pkl的具体使用方法。谢谢
源自github用户luotao1:
训练好的模型分两部分序列化,一个是网络拓扑结构,一个是参数。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
源自github用户zishuaiz:
hi @ luotao
请教个问题:
数字识别那个
from PIL import Image
import numpy as np
import os
def load_image(file):
im = Image.open(file).convert('L')
im = im.resize((28, 28), Image.ANTIALIAS)
im = np.array(im).astype(np.float32).flatten()
im = im / 255.0
return im
test_data = []
cur_dir = os.getcwd()
test_data.append((load_image(cur_dir + '/image/infer_3.png'),))
probs = paddle.infer(
output_layer=predict, parameters=parameters, input=test_data)
lab = np.argsort(-probs) # probs and lab are the results of one batch data
print "Label of image/infer_3.png is: %d" % lab[0][0]
这里的predict是在train阶段定义的,当inference时还要重新把以前的代码再写一遍吗,还是把train文件中的train()函数注销掉?
train和infer用同一个文件?
可不可以解耦合成两个文件?
源自github用户lcy-seso:
请参考 Paddle Models 下面的例子,训练和测试可以分开定义。
登录 后才可以发表评论