[tflite] export SetNumThreads to TFLite Python API#25748
[tflite] export SetNumThreads to TFLite Python API#25748tensorflow-copybara merged 18 commits intotensorflow:masterfrom
Conversation
|
added @miaout17 to the reviewer list since it involves interpreter change. |
|
Mine built well, but I get an object has no attribute |
|
@jdinkel88 maybe you forgot to install the newly built pip wheel (remember to |
|
@petewarden can you review this? RPI right now runs the apps using the python binding on single core :( |
|
👍 |
|
@miaout17 can you help review this? it seems some guys using RPI really want this. |
|
@miaout17 is there anyone else you can nominate as reviewer in case you don't have cycles? |
dpsm
left a comment
There was a problem hiding this comment.
Verified on rpi that it indeed uses more than a single core
export SetNumThreadS() and add an option to set the number of threads in the `label_image.py` for TFLite.
| help='input standard deviation') | ||
| parser.add_argument( | ||
| '--num_threads', | ||
| default=1, |
There was a problem hiding this comment.
How about adding type=int here, so that line 66 can be just num_threads=args.num_threads?
| else: | ||
| print('{:08.6f}: {}'.format(float(results[i] / 255.0), labels[i])) | ||
|
|
||
| print("time: ", stop_time - start_time) |
There was a problem hiding this comment.
nit: wrap string with single quote
remove extra space after ":", the print statement adds space between arguments.
Preferably would be nicer to format this as something like 'time: {:.3f}ms'.format((stop_time - start_time) * 1000)
| def reset_all_variables(self): | ||
| return self._interpreter.ResetVariableTensors() | ||
|
|
||
|
|
| Py_RETURN_NONE; | ||
| } | ||
|
|
||
| PyObject* InterpreterWrapper::SetNumThreads(int i) { |
There was a problem hiding this comment.
give this more descriptive name :)
| // should be the interpreter object providing the memory. | ||
| PyObject* tensor(PyObject* base_object, int i); | ||
|
|
||
| PyObject* SetNumThreads(int i); |
| )pbdoc") | ||
| .def( | ||
| "SetNumThreads", | ||
| [](InterpreterWrapper& self, int i) { |
teijeong
left a comment
There was a problem hiding this comment.
Looks good, just one nit ;) Thanks!
| print('{:08.6f}: {}'.format(float(results[i] / 255.0), labels[i])) | ||
|
|
||
| print("time: ", stop_time - start_time) | ||
| #print("time: ", stop_time - start_time) |
There was a problem hiding this comment.
oops, that's embarrassing. Thanks.
There was a problem hiding this comment.
No worries, it happens all the time for me too ;)
| [TfLiteDelegate](https://www.tensorflow.org/lite/performance/delegates) | ||
| objects returned by lite.load_delegate(). | ||
| num_threads: Set the number of threads used by TFLite kernels. | ||
| If not set, kernels are running single-threaded. Note that currently, |
There was a problem hiding this comment.
This should really be:
"Sets the number of threads used by the interpreter and available to CPU kernels. If not set, the interpreter will use an implementation-dependent default number of threads. Currently, only a subset of kernels, such as conv, support multi-threading."
| help='input standard deviation') | ||
| parser.add_argument( | ||
| '--num_threads', | ||
| default=1, type=int, |
There was a problem hiding this comment.
Would prefer that the default be None, if possible?
|
@jdduke gentle ping if we need more changes here. |
jdduke
left a comment
There was a problem hiding this comment.
Can you add a test or two in interpreter_test.py? Validate that it throws an error for invalid input, and that 2 threads works as expected?
|
I can add the tests internally, so that we don't have to reimport the changes. Will do it by tomorrow and get this in. |
|
How can I make a pip package to test it on RPI 4? |
export SetNumThreads() and add an option to set the number of threads in the
label_image.pyfor TFLite. On PYNQ-Z1, a board with 2xCA9,