Don't hold onto unnecessary numpy references while binding numpy objectas as inputs (#7881)

This commit is contained in:
Hariharan Seshadri 2021-05-30 21:12:32 -07:00 committed by GitHub
parent d8bcb3d6a4
commit 3a72932c4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -355,7 +355,7 @@ class IOBinding:
'''
def __init__(self, session):
self._iobinding = C.SessionIOBinding(session._sess)
self._numpy_obj_references = []
self._numpy_obj_references = {}
def bind_cpu_input(self, name, arr_on_cpu):
'''
@ -366,7 +366,7 @@ class IOBinding:
# Hold a reference to the numpy object as the bound OrtValue is backed
# directly by the data buffer of the numpy object and so the numpy object
# must be around until this IOBinding instance is around
self._numpy_obj_references.append(arr_on_cpu)
self._numpy_obj_references[name] = arr_on_cpu
self._iobinding.bind_input(name, arr_on_cpu)
def bind_input(self, name, device_type, device_id, element_type, shape, buffer_ptr):