我是靠谱客的博主 淡然万宝路,这篇文章主要介绍【问题解决】同一机器上Flask部署TensorRT报错记录1.报错:UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.   image = Variable(image, volatile=True)2.报错:TypeError: Object of type int64 is not JSON serializable3.报错:pycuda._driver.,现在分享给大家,希望可以做个参考。

1.报错:UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  image = Variable(image, volatile=True)

解决办法:

with torch.no_grad():
        image = Variable(image)

2.报错:TypeError: Object of type int64 is not JSON serializable

原代码:

r = {"label": label, "label name": label_name,
                     "probability": float(prob)}

是由于其中的label默认int类型,json库不认识。

解决办法:手动转为字符串类型。

label = str(label)

3.报错:pycuda._driver.LogicError: explicit_context_dependent failed: invalid device context - no currently active context?

网上都说是由于pycuda.driver没有初始化,导致无法得到context,需要在导入pycuda.driver后再导入pycuda.autoinit。即:

import pycuda.driver as cuda
import pycuda.autoinit

但我的代码中有这两行。而且单独执行tensorrt推理过程,也就是不引入flask时,是不会报错的,所以考虑可能是flask服务器在请求进来时会产生新的进程导致的。

参考:https://www.coder.work/article/352714

解决办法:将flask中调用的函数修改为:

最后

以上就是淡然万宝路最近收集整理的关于【问题解决】同一机器上Flask部署TensorRT报错记录1.报错:UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.   image = Variable(image, volatile=True)2.报错:TypeError: Object of type int64 is not JSON serializable3.报错:pycuda._driver.的全部内容,更多相关【问题解决】同一机器上Flask部署TensorRT报错记录1.报错:UserWarning:内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(107)

评论列表共有 0 条评论

立即
投稿
返回
顶部