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)
| 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. |
no outgoing calls