在flask中使用动态图模式,会卡死
Created by: Costwen
版本: paddle 1.8.3 cpu
当在flask上将输入转化为tensor 之后 使用 + - * / 等运算会卡死在原地
同时 也不能正常的使用return
`
@app.route('/selfie2anime',methods = ['POST','GET'])
def face2anime():
if request.method == 'POST':
selfie_file = request.files['selfie_file']
selfie_file.save("ActivitySelfie2anime/selfie_file.jpg")
with fluid.dygraph.guard():
genA2B = ResnetGenerator(in_channels=3, out_channels=3, ngf= 64, n_blocks=4)
genA2B_para, _ = fluid.load_dygraph("ActivitySelfie2anime/Parameters/genA2B124.pdparams")
genA2B.load_dict(genA2B_para)
img = np.array(Image.open("ActivitySelfie2anime/selfie_file.jpg").convert("RGB")).astype(np.float32)
img = cv2.resize(img,(256, 256))
img = img / 255.
img = (img - 0.5) / 0.5
img = totensor(img)
fakeA2B, _ , _ = genA2B(img)
fakeA2B = (denorm(tensor2numpy(fakeA2B[0])) * 255).astype(np.uint8)
fakeA2B = Image.fromarray(fakeA2B)
fakeA2B.save("ActivitySelfie2anime/anime.jpg")
anime_image = np.linspace(0,255,256*256*3).reshape(256,256,-1).astype(np.uint8)
ret,buf = cv2.imencode(".jpg",anime_image)
anime_image = Image.fromarray(np.uint8(buf)).tobytes()
resp = make_response(anime_image)
resp.headers['Anime-Type'] = 'image/jpeg'
print(resp)
return resp
` 当使用上述代码时 程序将会一直卡在return 这个地方并且不会返回,并且如果使用tensor去进行+ - / * 运算也会卡死在相对应处