Skip to content

Conversation

@freedomtan
Copy link
Contributor

@freedomtan freedomtan commented Feb 14, 2019

export SetNumThreads() and add an option to set the number of threads in the label_image.py for TFLite. On PYNQ-Z1, a board with 2xCA9,

$ python tensorflow/lite/examples/python/label_image.py --num_threads 1
0.415686: 653:military uniform
0.352941: 907:Windsor tie
0.058824: 668:mortarboard
0.035294: 458:bow tie, bow-tie, bowtie
0.035294: 835:suit, suit of clothes
time:  0.691580057144

$ python tensorflow/lite/examples/python/label_image.py --num_threads 2
0.415686: 653:military uniform
0.352941: 907:Windsor tie
0.058824: 668:mortarboard
0.035294: 458:bow tie, bow-tie, bowtie
0.035294: 835:suit, suit of clothes
time:  0.412344932556

@pragyaak pragyaak self-assigned this Feb 14, 2019
@pragyaak pragyaak added the size:S CL Change Size: Small label Feb 14, 2019
@pragyaak pragyaak added the awaiting review Pull request awaiting review label Feb 14, 2019
@jianlijianli
Copy link
Contributor

added @miaout17 to the reviewer list since it involves interpreter change.

@jdinkel88
Copy link

Mine built well, but I get an object has no attribute
Traceback (most recent call last):
File "./label_image.py", line 74, in
interpreter.set_num_threads(int(args.num_threads))
File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/lite/python/interpreter.py", line 260, in set_num_threads
return self._interpreter.SetNumThreads(i)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/lite/python/interpreter_wrapper/tensorflow_wrap_interpreter_wrapper.py", line 97, in
getattr = lambda self, name: _swig_getattr(self, InterpreterWrapper, name)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/lite/python/interpreter_wrapper/tensorflow_wrap_interpreter_wrapper.py", line 74, in _swig_getattr
return _swig_getattr_nondynamic(self, class_type, name, 0)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/lite/python/interpreter_wrapper/tensorflow_wrap_interpreter_wrapper.py", line 69, in _swig_getattr_nondynamic
return object.getattr(self, name)
AttributeError: type object 'object' has no attribute 'getattr'

@freedomtan
Copy link
Contributor Author

@jdinkel88 maybe you forgot to install the newly built pip wheel (remember to pip3 install -U YOUR_NEWLY_BUILT_PIP_WHEEL) or ran a wrong python interpreter (make sure that the python interpreter uses the newly installed one)?

@pragyaak pragyaak added the awaiting review Pull request awaiting review label Feb 19, 2019
@pragyaak pragyaak assigned rthadur and unassigned pragyaak Feb 23, 2019
@dpsm
Copy link

dpsm commented Mar 8, 2019

@petewarden can you review this? RPI right now runs the apps using the python binding on single core :(

@dpsm
Copy link

dpsm commented Mar 8, 2019

👍

@freedomtan
Copy link
Contributor Author

@miaout17 can you help review this? it seems some guys using RPI really want this.

@dpsm
Copy link

dpsm commented Mar 12, 2019

@miaout17 is there anyone else you can nominate as reviewer in case you don't have cycles?

dpsm
dpsm previously approved these changes Mar 18, 2019
Copy link

@dpsm dpsm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on rpi that it indeed uses more than a single core

@rthadur rthadur requested review from jdduke and removed request for jianlijianli and miaout17 March 18, 2019 20:31
@tensorflowbutler tensorflowbutler removed the awaiting review Pull request awaiting review label Mar 19, 2019
@jdduke jdduke requested a review from miaout17 March 19, 2019 18:32
freedomtan and others added 2 commits March 21, 2019 14:47
export SetNumThreadS() and add an option to set the number of
threads in the `label_image.py` for TFLite.
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label May 22, 2020
[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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

help='input standard deviation')
parser.add_argument(
'--num_threads',
default=1, type=int,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer that the default be None, if possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@freedomtan freedomtan dismissed stale reviews from gbaned and teijeong via fd546da May 27, 2020 07:33
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label May 27, 2020
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels May 27, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label May 27, 2020
@gbaned gbaned added ready to pull PR ready for merge process and removed ready to pull PR ready for merge process labels May 28, 2020
@rthadur rthadur removed the ready to pull PR ready for merge process label Jun 1, 2020
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Jun 1, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 1, 2020
@google-ml-butler google-ml-butler bot added the kokoro:force-run Tests on submitted change label Jun 1, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 1, 2020
@rthadur
Copy link
Contributor

rthadur commented Jun 5, 2020

@jdduke gentle ping if we need more changes here.

@gbaned gbaned added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Jun 9, 2020
Copy link
Member

@jdduke jdduke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@srjoglekar246
Copy link
Contributor

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.

@tensorflow-copybara tensorflow-copybara merged commit ad4363b into tensorflow:master Jun 12, 2020
@metanav
Copy link

metanav commented Jun 13, 2020

How can I make a pip package to test it on RPI 4?

@teijeong
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes comp:lite TF Lite related issues ready to pull PR ready for merge process size:S CL Change Size: Small stat:awaiting tensorflower Status - Awaiting response from tensorflower

Projects

None yet

Development

Successfully merging this pull request may close these issues.