Проблема в том, что у меня есть два кода Python.
Скажите tennsrtcode.py и tenorflowcode.py.
tensorrtcode.py has
только тензорные коды.
def infer(engine, x, batch_size, context):
inputs = []
outputs = []
bindings = []
stream = cuda.Stream()
for binding in engine:
size = trt.volume(engine.get_binding_shape(binding)) * batch_size
dtype = trt.nptype(engine.get_binding_dtype(binding))
# Allocate host and device buffers
host_mem = cuda.pagelocked_empty(size, dtype)
device_mem = cuda.mem_alloc(host_mem.nbytes)
# Append the device buffer to device bindings.
bindings.append(int(device_mem))
# Append to the appropriate list.
if engine.binding_is_input(binding):
inputs.append(HostDeviceMem(host_mem, device_mem))
else:
outputs.append(HostDeviceMem(host_mem, device_mem))
img = np.array(x).ravel()
np.copyto(inputs[0].host, 1.0 - img / 255.0)
[cuda.memcpy_htod_async(inp.device, inp.host, stream) for inp in inputs]
context.execute_async(batch_size=batch_size, bindings=bindings, stream_handle=stream.handle)
# Transfer predictions back from the GPU.
[cuda.memcpy_dtoh_async(out.host, out.device, stream) for out in outputs]
# Synchronize the stream
stream.synchronize()
# Return only the host outputs.
return [out.host for out in outputs]
def main():
.....
infer(......)
.....
Затем tensorflowcode.py has
только тензор потока API и выполнить с session
.
self.graph = tf.get_default_graph()
self.persistent_sess = tf.Session(graph=self.graph, config=tf_config)
Проблема в том, когда мне нужно связать класс от tenorflow с классом тензорным,
объявите экземпляр класса кода tenorflow внутри главной сети tenorrt как
def main ():
.....
t_flow_code = tensorflowclass ()
Infer (......)
.....
тогда у меня ошибка как illegal memory access was encountered happened at stream.synchronize()
Проблема решается добавлением another session at tensorrt just before t_flow_code=tensorflowclass().
Я не понимаю, зачем мне это нужно, поскольку у меня есть собственный сеанс для выполнения в классе tenorflow. Зачем мне нужен еще один сеанс перед интерфейсом класса в коде тензоррта.