Bug 504185 - 100% CPU usage on all cores for no apparent reason
Summary: 100% CPU usage on all cores for no apparent reason
Status: REPORTED
Alias: None
Product: digikam
Classification: Applications
Component: Faces-Engine (other bugs)
Version First Reported In: 8.7.0
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-05-13 23:32 UTC by MarcP
Modified: 2025-08-23 20:25 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Windows Task Manager with all 16 cores at 100% usage (91.75 KB, image/png)
2025-08-23 20:25 UTC, MarcP
Details

Note You need to log in before you can comment on or make changes to this bug.
Description MarcP 2025-05-13 23:32:29 UTC
SUMMARY
Hi, for a few weeks I've been experiencing this behavior, but I'm still unsure what's triggering it. Basically, after a few minutes of using digikam, I notice the computer getting sluggish. If I check the Taskbar, I see that Digikam is using all the CPU threads at 100% usage (I'm using a Intel i7 5700X processor). And it lasts for several minutes before it goes back to normal.

Initially, I thought it was related to the background face training and scanning (although in my experience, it was much more light on resources), but I disabled the 'Enable background face recognition scan' option, restarted digikam, and the issue is still there. 

These days I'm mostly tagging faces, but I don't know if it's related to that or not. I can use DebugView and get the logs if you want, just let me know.

STEPS TO REPRODUCE
1. Use digikam normally, tagging some faces
2. Wait a few minutes. Observe CPU usage.

OBSERVED RESULT
- CPU usage at 100% for several minutes.

EXPECTED RESULT
- Normal CPU usage.

SOFTWARE/OS VERSIONS
Windows: Win 10 22H2
digiKam-8.7.0-20250513T170124-Qt6-Win64.exe

ADDITIONAL INFORMATION
Comment 1 MarcP 2025-05-14 02:29:50 UTC
Hi,

I ran the DebugView to see what was causing that CPU usage. I just started digikam, let it do the initial scan for now files, and didn't touch it at all. 

High CPU usage kicked in at the 5 minute mark, and stayed that way for another 5 minutes.

This is the complete log file. I stopped it at the moment the CPU went back to idle.
http://158.101.198.126:9011/share/33RuXex5

The two relevant lines that match the timestamps appear to be these ones:

00001116	683.82061768	[45528] digikam.facesengine: FaceClassifier::loadTrainingData: SVM calcError is:  3.187462	
00001117	683.82067871	[45528] digikam.facesengine: FaceClassifier::loadTrainingData: training completed in  338768 ms
Comment 2 caulier.gilles 2025-05-14 08:51:09 UTC
SVM message come from face engine...
Comment 3 caulier.gilles 2025-05-14 09:54:46 UTC
The SVN CalcError is just informative about the computation results, it's not a processing error. Code relevant is here :

https://invent.kde.org/graphics/digikam/-/blob/master/core/libs/facesengine/recognition/faceclassifier.cpp?ref_type=heads#L378

Gilles Caulier
Comment 4 Michael Miller 2025-05-14 16:04:54 UTC
(In reply to caulier.gilles from comment #3)
> The SVN CalcError is just informative about the computation results, it's
> not a processing error. Code relevant is here :
> 
> https://invent.kde.org/graphics/digikam/-/blob/master/core/libs/facesengine/
> recognition/faceclassifier.cpp?ref_type=heads#L378
> 
> Gilles Caulier

Hi all,
Gilles, you are correct. The SVM calcError is shown for debugging purposes.  The value reflects the percentage of labels that lie beyond the hyperplane boundry generated by the kernel function for a given label cluster (class) during training.  In other words, it's the estimated margin of error for the SVM classifier.  This value should always be less than 5.0 (5%). Lower values are better.

Cheers,
Mike
Comment 5 Michael Miller 2025-05-14 16:08:00 UTC
(In reply to MarcP from comment #1)
> Hi,
> 
> I ran the DebugView to see what was causing that CPU usage. I just started
> digikam, let it do the initial scan for now files, and didn't touch it at
> all. 
> 
> High CPU usage kicked in at the 5 minute mark, and stayed that way for
> another 5 minutes.
> 
> This is the complete log file. I stopped it at the moment the CPU went back
> to idle.
> http://158.101.198.126:9011/share/33RuXex5
> 
> The two relevant lines that match the timestamps appear to be these ones:
> 
> 00001116	683.82061768	[45528] digikam.facesengine:
> FaceClassifier::loadTrainingData: SVM calcError is:  3.187462	
> 00001117	683.82067871	[45528] digikam.facesengine:
> FaceClassifier::loadTrainingData: training completed in  338768 ms

The concerning line in this backtrace is "FaceClassifier::loadTrainingData: training completed in  338768 ms". This means it took 338 seconds, or over 5 minutes to train the classifier.  CPU usage will be high when training the classifier. Training the classifier should take under 60 seconds.

How many confirmed faces do you have in your library?

Cheers,
Mike
Comment 6 MarcP 2025-05-14 22:28:58 UTC
>  How many confirmed faces do you have in your library?

Just checked. 155382 confirmed faces in 1050 different people.
Comment 7 Michael Miller 2025-05-15 13:27:14 UTC
(In reply to MarcP from comment #6)
> >  How many confirmed faces do you have in your library?
> 
> Just checked. 155382 confirmed faces in 1050 different people.

Thanks Marc, I'll see if I can recreate the issue with that many faces, and see if there is a way to tune the classifier training algorithm.  I'm almost certain the issue is with training the SVM with that many faces.

Cheers,
Mike
Comment 8 Michael Miller 2025-06-01 12:09:27 UTC
(In reply to Michael Miller from comment #7)
> (In reply to MarcP from comment #6)
> > >  How many confirmed faces do you have in your library?
> > 
> > Just checked. 155382 confirmed faces in 1050 different people.
> 
> Thanks Marc, I'll see if I can recreate the issue with that many faces, and
> see if there is a way to tune the classifier training algorithm.  I'm almost
> certain the issue is with training the SVM with that many faces.
> 
> Cheers,
> Mike

Hi Marc,
Yes, I've confirmed the issue is with training the SVM classifier as part of the overall ensemble of internal classifiers in the face classifier when you have over 100,000 confirmed faces.

There's good news and bad news. The good news is the face classifier "falls back" to less efficient approach while the SVM is being trained, so face recognition is usable while it's happening.

The bad news is there's no way to fix this without rewriting the entire face classifier.  I'll add rewriting the face classifier to eliminate the the SVM classifier to my 8.8.0 to-do list.

Cheers,
Mike
Comment 9 MarcP 2025-06-02 21:21:00 UTC
(In reply to Michael Miller from comment #8)
> (In reply to Michael Miller from comment #7)
> > (In reply to MarcP from comment #6)
> > > >  How many confirmed faces do you have in your library?
> > > 
> > > Just checked. 155382 confirmed faces in 1050 different people.
> > 
> > Thanks Marc, I'll see if I can recreate the issue with that many faces, and
> > see if there is a way to tune the classifier training algorithm.  I'm almost
> > certain the issue is with training the SVM with that many faces.
> > 
> > Cheers,
> > Mike
> 
> Hi Marc,
> Yes, I've confirmed the issue is with training the SVM classifier as part of
> the overall ensemble of internal classifiers in the face classifier when you
> have over 100,000 confirmed faces.
> 
> There's good news and bad news. The good news is the face classifier "falls
> back" to less efficient approach while the SVM is being trained, so face
> recognition is usable while it's happening.
> 
> The bad news is there's no way to fix this without rewriting the entire face
> classifier.  I'll add rewriting the face classifier to eliminate the the SVM
> classifier to my 8.8.0 to-do list.
> 
> Cheers,
> Mike

Thanks Michael for looking into it. Let me know when there's any change or you want me to test anything.
Comment 10 caulier.gilles 2025-06-23 14:47:53 UTC
Hi Michael,

Any progress in this file as proposed in comment 8...

Best

Gilles
Comment 11 caulier.gilles 2025-07-14 18:24:51 UTC
Git commit e43d260e3950b67cd31c3b93b759147a87210848 by Gilles Caulier.
Committed on 14/07/2025 at 18:22.
Pushed by cgilles into branch 'master'.

by default the scan for face in background option must be disabled, and inplicitly enabled by the users, as this option
idle the computer a lot.

M  +1    -1    core/libs/settings/applicationsettings.cpp
M  +1    -1    core/libs/settings/applicationsettings_p.h

https://invent.kde.org/graphics/digikam/-/commit/e43d260e3950b67cd31c3b93b759147a87210848

diff --git a/core/libs/settings/applicationsettings.cpp b/core/libs/settings/applicationsettings.cpp
index c853af8de5..ee91da7977 100644
--- a/core/libs/settings/applicationsettings.cpp
+++ b/core/libs/settings/applicationsettings.cpp
@@ -230,7 +230,7 @@ void ApplicationSettings::readSettings()
     d->scrollItemToCenter                = group.readEntry(d->configScrollItemToCenterEntry,                          false);
     d->showOnlyPersonTagsInPeopleSidebar = group.readEntry(d->configShowOnlyPersonTagsInPeopleSidebarEntry,           true);
     d->detectFacesInNewImages            = group.readEntry(d->configDetectFacesInNewImagesEntry,                      false);
-    d->faceRecognitionBackgroundScan     = group.readEntry(d->configFaceRecognitionBackgroundScanEntry,               true);
+    d->faceRecognitionBackgroundScan     = group.readEntry(d->configFaceRecognitionBackgroundScanEntry,               false);
     d->stringComparisonType              = (StringComparisonType)
                                                group.readEntry(d->configStringComparisonTypeEntry,                    (int) Natural);

diff --git a/core/libs/settings/applicationsettings_p.h b/core/libs/settings/applicationsettings_p.h
index 594d62dd46..4caa4fd9c1 100644
--- a/core/libs/settings/applicationsettings_p.h
+++ b/core/libs/settings/applicationsettings_p.h
@@ -215,7 +215,7 @@ public:
     bool                                         showOnlyPersonTagsInPeopleSidebar                  = false;

     bool                                         detectFacesInNewImages                             = false;
-    bool                                         faceRecognitionBackgroundScan                      = true;
+    bool                                         faceRecognitionBackgroundScan                      = false;

     /// icon view settings
     bool                                         iconShowName                                       = true;
Comment 12 MarcP 2025-07-14 23:34:42 UTC
Thanks. Although I must mention that the issue happens regardless that option being enabled or disabled.
Comment 13 MarcP 2025-08-23 20:25:33 UTC
Created attachment 184387 [details]
Windows Task Manager with all 16 cores at 100% usage
Comment 14 MarcP 2025-08-23 20:25:54 UTC
Hi, I was wondering if there has been any update or progress on this issue. It still affects my workflow quite a bit. Thank you for your work!