关于paddle的动态图部署到flask的问题
Created by: zt991211
@app.route('/predict/<name>')
def prediction(name):
path=basedir+'\\static\\img\\'+name+'.png'
img=Image.open(path)
org_ROI,ROI_PT=get_ROI_region(img)
with fluid.dygraph.guard(fluid.CPUPlace):
model = M_net()
model_state_dict, _ = fluid.load_dygraph('weights/mnet30.pdparams')
model.load_dict(model_state_dict)
model.eval()
img = []
img.append(transform_img(np.array(ROI_PT)))
img = np.array(img)
img = fluid.dygraph.to_variable(img)
out6, out7, out8, out9, out10 = model(img)
out10 = out10.numpy()
out10 = np.reshape(out10, (out10.shape[1], out10.shape[2], out10.shape[3]))
out10 = np.transpose(out10, (1, 2, 0))
disc_map = np.array(Image.fromarray(out10[:, :, 0]).resize((600, 600)))
cup_map = np.array(Image.fromarray(out10[:, :, 1]).resize((600, 600)))
disc_map[-round(DiscROI_size / 3):, :] = 0
cup_map[-round(DiscROI_size / 2):, :] = 0
De_disc_map = cv2.linearPolar(rotate(disc_map, 90), (DiscROI_size / 2, DiscROI_size / 2),
DiscROI_size / 2, cv2.WARP_FILL_OUTLIERS + cv2.WARP_INVERSE_MAP)
De_cup_map = cv2.linearPolar(rotate(cup_map, 90), (DiscROI_size / 2, DiscROI_size / 2),
DiscROI_size / 2, cv2.WARP_FILL_OUTLIERS + cv2.WARP_INVERSE_MAP)
ret, De_cup_map = cv2.threshold(De_cup_map, 0.5, 1, cv2.THRESH_BINARY)
res, De_disc_map = cv2.threshold(De_disc_map, 0.5, 1, cv2.THRESH_BINARY)
disc_h, disc_w = getCDR(De_disc_map)
cup_h, cup_w = getCDR(De_cup_map)
V_cdr=cup_h * 1.00 / disc_h
print(V_cdr)
res=make_response(jsonify({"size":str(V_cdr)}))
res.headers['Access-Control-Allow-Origin'] = '*'
使用了guard动态图模式后,该api无法执行返回操作,print操作正常,我推测是动态图的相关模式没有关掉,调用api一直处于等待没有返回值 之前利用函数封装的形式也是同样的问题,https://ai.baidu.com/forum/topic/show/960176 谢谢大佬帮我解答