MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _safe_to_run

Method _safe_to_run

tensorflow/lite/python/interpreter.py:246–256  ·  view source on GitHub ↗

Returns true if there exist no numpy array buffers. This means it is safe to run tflite calls that may destroy internally allocated memory. This works, because in the wrapper.cc we have made the numpy base be the self._interpreter.

(self)

Source from the content-addressed store, hash-verified

244 return self._interpreter.AllocateTensors()
245
246 def _safe_to_run(self):
247 """Returns true if there exist no numpy array buffers.
248
249 This means it is safe to run tflite calls that may destroy internally
250 allocated memory. This works, because in the wrapper.cc we have made
251 the numpy base be the self._interpreter.
252 """
253 # NOTE, our tensor() call in cpp will use _interpreter as a base pointer.
254 # If this environment is the only _interpreter, then the ref count should be
255 # 2 (1 in self and 1 in temporary of sys.getrefcount).
256 return sys.getrefcount(self._interpreter) == 2
257
258 def _ensure_safe(self):
259 """Makes sure no numpy arrays pointing to internal buffers are active.

Callers 2

_ensure_safeMethod · 0.95
testBaseMethod · 0.80

Calls

no outgoing calls

Tested by 1

testBaseMethod · 0.64