« first day (45 days earlier)    last day (15 days later) » 

A_A
5:46 PM
It really depends on what you are trying to do. For example, one thread may be doing the calculations and pushing the results to some deque where the GUI thread is picking it up from. The deque, especially in python solves a lot of problems to do with synchronisation in threads
 
@A_A i see some examples that use queue though? what is the advantage of deque over queue?
 
A_A
@TanMath so, there is nothing really "fixed". There are tools and techniques that can be used for different solutions. Multiprocessing is a way to spread computation across all cores of a CPU
 
@A_A i assume multiprocessing is only good for parallel tasks?
@A_A but i think there are some functions in multiprocessing that can be used for threading, in particular ThreadPool
In fact that is what the opencv threading example uses
 
A_A
@TanMath indeed. You can have two cores dealing with independent tasks
@TanMath a queue is strictly logo a deque can operate as FIFO and logo
LIFO
Not logo....LIFO
The point is what are you trying to do
 
In computer science, a queue ( KYEW) is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the principle (or only) operations on the collection are the addition of entities to the rear terminal position, known as enqueue, and removal of entities from the front terminal position, known as dequeue. This makes the queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that once a new element is added, all...
"This makes the queue a First-In-First-Out (FIFO) data structure"
Am I missing something here?
 
A_A
6:02 PM
@TanMath Yes, that a queue is FIFO but a deque can operate both as FIFO and LIFO I may have switched them around above
@TanMath What are you trying to do?
 
@A_A well so I have my frames that are being captured and processed to output an HR, and there is a GUI which displays the HR.... i need the system to be real-time and minimal delays...
@A_A what is the importance of operating as a LIFO?
 
A_A
@TanMath it's not going to be real time. You can forget that. A real time system is one where the processing performed can finish withing 1/Fs time. Clearly this is not happening in your case. "Minimal delays" says nothing. "Minimal delays" is not a number. You can't design a system with a specification of "minimal delays". Which delays? What is the least delay you can achieve? Where are the delays coming from?
 
@A_A actually i think i have a system that the processing is a little under 1/Fs... if I use a resolution of 1280x720 and use an optimized version of OpenCV, then it runs reasonably fast it seems...
 
A_A
@TanMath Perhaps, if you changed the pipeline, as far as I can remember from the measurements we did, the system was barely finishing at the time it took for 1 frame to be acquired
@TanMath The minimal example with two threads is to have them to communicate via a deque. Esepcially in python the deque is thread safe. This means that you, the programmer, don't have to be bothered with implementing synchronisation
@TanMath If you didn't have the deque you would have to implement synchronisation to ensure that each time only one thread acquires memory (i.e. writes or reads from the deque), either using semaphores or events.
 
6:24 PM
@A_A wait so what would the two threads do?
 
A_A
@TanMath They could be doing anything. In your case, probably one thread does the acquisition and the other the processing. It really depends on what you are trying to do.
 
@A_A well i just want to make the system efficient, especially since now I have the GUI
@A_A so how would I set up this simplistic system then?
Would I make functions for the two threads?
 
A_A
I don't know what is the structure of the rest of the software you are building and multi threading is not something that you simply bolt on to some script
@TanMath But there are lots of examples out there which you can probably adapt
 
@A_A well I haven't found an example that describes what you are saying here...
@A_A and many of them use different methods to implement their threads
 
A_A
@TanMath Yep, you are going to have to select what is best for your use case.
 
6:39 PM
@A_A so how do I decide that?
 
A_A
@TanMath We are going around in circles. I don't know how you decide that because I don't know what you are dealing with and you don't seem to have clear specifications too. Compartmentalise the code, see which parts can run concurrently (IF required) and turn them into threads. If there is any need for communications between them, use the appropriate data structure. Which data structure depends on what you are trying to do. There are no magic bullets.
 
@A_A so this is like the functions i have... the all-frame processing and sliding window processing is what we discussed before...
all-frame processing meaning like the ROI detection, and sliding-window is all the signal processing that is done in the sliding window
So i guess it would seem that frame capture is one thread, face tracking+all-frame processing is another thread, but then i don't know how to integrate my sliding window with all of this...
does this clear things up a little bit?
 
A_A
6:55 PM
@TanMath It's not up to me to design the system for you. If you ask (me or the rest of the board) a specific question, you will receive a specific answer. You do not seem to be getting this. If you ask me a million questions and your implementation depends on the series of "yes/ no" you receive, then what is your contribution to the solution of the problem?
 
@A_A I guess I am new to multithreading and am confused on how it would be implemented for my system because there are so many functions and data structures etc. Looking at tutorials it seems easy for these simplistic examples but once I go to any sort of video processing examples I start getting confused...
 
A_A
@TanMath That is fine. You will learn. Everybody started from zero. But you will definitely not learn if you are looking for ready made solutions. What tutorials have you been looking at?
 
A_A
@TanMath Great, what did you make of all this?
 
886
Q: How to use threading in Python?

albrunoI am trying to understand threading in Python. I've looked at the documentation and examples, but quite frankly, many examples are overly sophisticated and I'm having trouble understanding them. How do you clearly show tasks being divided for multi-threading?

 
A_A
7:04 PM
@TanMath this last link seems to be very informative. What did you make of all this with respect to the problem you are working on?
 
@A_A really? I wasn't sure if it was helpful because it was mainly discussing map, which i felt was not so useful for me when a lot of my code is sequential
 
A_A
@TanMath Which parts would you perceive as sequential?
 
@A_A well for sure the face tracking is sequential...
 
A_A
@TanMath Sequential with what?
@TanMath Weren't you in a tight deadline by the way? It seems to have passed (?)
 
based on the algorithm, it needs to look at the previous frame and see the movement of the face in the current frame with respect to the previous frame
@A_A the deadlines are confusing... technically it all will end on june 9th... the other deadlines were mainly milestones and that I have to keep improving my system
 
A_A
7:09 PM
@TanMath That's not what sequential means. This is the sequence of actions within the same task. In threading, sequential is looked at from the point of view of tasks that have to wait for other tasks to finish (so they would have to happen IN SEQUENCE) as opposed to tasks that do not have to wait for other tasks (and therefore can happen in parallel).
@TanMath So, with this in mind, which parts do you think should run in sequence and which should run in parallel ?
 
@A_A well then I still think most of the algorithm is sequential
 
A_A
@TanMath ...then what's the point of multithreading?
 
@A_A I thought it would be for frame capture, processing, and GUI there would be three threads...
 
A_A
@TanMath By the way, we have talked about this again...maybe two or three times when you were asking about multithreadingearlier
@TanMath You seem to be in two minds. What is it? That there are no sequential parts or that there are three sequential parts
?
@TanMath Or three that some of them could run in parallel (?)
 
8:08 PM
@A_A what is the advantage of deque over queue?
 
A_A
@TanMath It is difficult to say without a concrete example. The difference between the deque and the queue is that a Queue can only be operated from one end while a deque can be operated from both. For more information please see this link
 
@A_A i think i figured out that i would just have two threads, one for frame capture + processing and one for GUI
@A_A but like why would you need to access from both sides?
 
A_A
8:49 PM
@TanMath To exchange data
@TanMath between the threads
 

« first day (45 days earlier)    last day (15 days later) »