Hi,
First, I tried to open a .engine file with the code below
def get_engine(engine_path):
# If a serialized engine exists, use it instead of building an engine.
print("Reading engine from file {}".format(engine_path))
with open(engine_path, "rb") as f, trt.Runtime(TRT_LOGGER) as runtime:
print("A serialized engine already exist.")
return runtime.deserialize_cuda_engine(f.read())
Then I got this error message
AttributeError Traceback (most recent call last)
Input In [8], in <module>
3 frame_count = 0
4 frame0_flag = 0 # stands for status of the first frame
----> 5 with get_engine(engine_path) as engine, engine.create_execution_context() as context:
6 buffers = allocate_buffers(engine, 1)
7 # image_size = (416, 416)
AttributeError: __enter__
After searching about the error I changed the loading function to a class like this:
class get_engine():
def __init__(self, engine_path):
self.engine_path = engine_path
self.f = open(self.engine_path, "rb")
print("Reading engine from file {}".format(engine_path))
print("A serialized engine already exist.")
self.engine = runtime.deserialize_cuda_engine(self.f.read())
return self.engine
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
return self
And now I am getting this:
AttributeError Traceback (most recent call last)
Input In [121], in <module>
3 frame_count = 0
4 frame0_flag = 0 # stands for status of the first frame
----> 6 with get_engine(engine_path) as engine, engine.create_execution_context() as context:
7 buffers = allocate_buffers(engine, 1)
8 # image_size = (416, 416)
AttributeError: 'get_engine' object has no attribute 'create_execution_context'
I double-checked the model’s path but had no success.
Any ideas, please?