christoph_müßig asked . 2021-06-29

Why does not Matlab use the full capacity of my computer while training a neural network?

My goal is to train a neural network to classify objects form pictures of my webcam. I use transfer learning with Alexnet and I have a labeled training data set with 25,000 images.
My training script works perfectly, but the progress of the iterations during training is very slow. I have the Parallel Computing Toolbox installed and the training runs on the Single GPU. But when looking at the task manager, Matlab only uses 13 % of the CPU and just 2 % of the GPU. Why does not Matlab use more resources to speed up the training process?
The software is Windows 10 and I have the newest version of Matlab 64bit installed.

deep learning , neural network , gpu , matlab

Expert Answer

Kshitij Singh answered . 2024-12-21 17:48:25

 
You surely don't keep all 25000 images in memory at once. Instead, you probably use and re-use them. over and over again. So, what you probably should be doing is looking at your disk access rate. Reading an image takes relatively a lot of time, but it is not really CPU time that is consumed. The CPU spends much of its time just waiting for data. So the CPU is not shown as busy. This is just my prediction of course, as evidenced by the statistics you report.
Can you confirm this fact? Of course! You need to learn about the Profile topol that MATLAB provides. It allows you to turn the profiler on, then run your code. Then check where MATLAB was spending the most time. This is an important thing to do for ANY code. My prediction is when you do the profile on your code, it will show the most time is consumed in one line of code - probably a simple imread call.
Now, why did I recognize the issue is NOT single threading versus multi-threading?
For example, my computer has 4 cores on it. I can easily force MATLAB to access all 4 cores in an operation, because I know which operations MATLAB will tend to automatically multi-thread. Likewise, I can as easily force MATLAB to runflat out, but only on ONE thread, since again, I know that some operations are NOT automatically parallelized.
An example of the former would the multiplication of two very large matrices. MATLAB will do that on as many cores as it can get. In the latter case, a very large symbolic computation is a good example. That is a problem that appears to be often not so easily parallelized, so no matter how large, it will run in only one core.
Again, you can see this happening in a monitor that can report the activty of all of your cores. In the first case of the matrix multiply, it will show 400% core usage. (As well, my system fan will kick on to dissipate all the heat generated when that much work is being done.) But in the latter case of the single threaded symbolic computation, only one core will be seen, running flat out at 100%.
But what did you see? You saw 13%. What you probably could have looked at was your disk access rate. I'd bet that is high for the entire time your code runs.
Can you fix this? Many things are fixable through use of better coding skills. Sometimes you need to completely change your algorithm, keeping more information in memory at once, trying to avoid those repeated image loads. The problem is you don't have that much memory. Well, you might. And that could be one option. Can you afford to buy enough RAM to store them all in system memory, NOT on a hard disk?
Another option is to make sure you are using the FASTEST disk possible. SSD drives are pretty cheap these days, and they are fast.
Yes, I know that spending money on your computer may not be an option. But you asked to know what the problem is. One of the ways to solve it, if I am correct in my assessment, is to make those image reads much faster. Or, you can find a way to write better, more efficient code. No matter what, that will start with the profile utility in MATLAB.
And, when all else fails, you can recognize that big problems take big time. You can reduce the time needed by solving smaller problems. Or you can change the algorithms you use so that computation is more efficient.


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.