Closed FirstDiscoverer closed 5 years ago
那你可以使用ManagedModel
在predict
函数里面使用with graph.as_default():
是这么操作了 还有会timeOut,原来的50ms太小了
那你可以使用
ManagedModel
在predict
函数里面使用with graph.as_default():
是这么操作了 还有会timeOut,原来的50ms太小了
timeout可能是worker初始化比较慢,超过了streamer的超时时间,可以用这个api试试https://github.com/ShannonAI/service-streamer/blob/19a2bad2cc54b20fc96f7e3093d2e785b19345fb/example/future_example.py#L18
streamer = Streamer(ManagedBertModel, batch_size=batch_size, max_latency=0.1, worker_num=4, cuda_devices=(0, 1, 2, 3))
ThreadedStreamer、 Streamer有啥区别?
建议graph可以通过接口传递进去,最后如果graph不为空就加上with graph.as_default():,否则为原来的的predict
ThreadedStreamer是用子线程作为worker;Streamer是会开新的进程,可以支持多worker。
streamer不希望知道框架(tf/pytorch),所以不太好加graph参数
好的 感谢老哥
好的 感谢老哥 这个问题,你解决了吗,我也遇到同样的问题,请问一下你的graph怎么加的。
贴一下解决方法,web我使用的tornado框架
注意在main方法中初始化streamer
if name == "main": streamer = Streamer(TextCnnModel, batch_size=global_config.batch_size, max_latency=global_config.max_latency, cuda_devices=global_config.cuda_device, worker_num=1)
然后再controller的方法中 data = streamer.predict([news])[0]调用就行了,注意不要在非main外边初始化就好了
ValueError: Tensor Tensor("dense_1/Softmax:0", shape=(?, 4), dtype=float32) is not an element of this graph.
参考这个链接 https://www.cnblogs.com/qhlblog/p/9233621.html 应该是tensorflow在做多线程的时候需要制定graph
_BaseStreamWorker.model_predict的使用应该制定 with graph.as_default():