@@ -150,6 +150,7 @@ local function save_preferences()
150
150
dt .preferences .write (MODULE , " ignore_tags" , " string" , fc .ignore_tags .text )
151
151
dt .preferences .write (MODULE , " category_tags" , " string" , fc .category_tags .text )
152
152
dt .preferences .write (MODULE , " known_image_path" , " directory" , fc .known_image_path .value )
153
+ dt .preferences .write (MODULE , " program_source" , " integer" , fc .program_source .selected )
153
154
local val = fc .tolerance .value
154
155
val = string.gsub (tostring (val ), " ," , " ." )
155
156
dt .preferences .write (MODULE , " tolerance" , " float" , tonumber (val ))
@@ -165,6 +166,7 @@ local function reset_preferences()
165
166
fc .ignore_tags .text = " "
166
167
fc .category_tags .text = " "
167
168
fc .known_image_path .value = dt .configuration .config_dir .. " /face_recognition"
169
+ fc .program_source .selected = 1
168
170
fc .tolerance .value = 0.6
169
171
fc .num_cores .value = - 1
170
172
fc .export_format .selected = 1
@@ -200,18 +202,24 @@ local function cleanup(img_list)
200
202
end
201
203
202
204
local function face_recognition ()
205
+ local program_source = fc .program_source .value
203
206
204
- local bin_path = df .check_if_bin_exists (" face_recognition" )
207
+ if string.match (program_source , " python" ) then
208
+ dt .print_log (string.match (program_source , " python" ))
209
+ local bin_path = df .check_if_bin_exists (" face_recognition" )
205
210
206
- if not bin_path then
207
- dt .print (_ (" Face recognition not found" ))
208
- return
211
+ if not bin_path then
212
+ dt .print (_ (" Face recognition for python not found" ))
213
+ return
214
+ end
209
215
end
210
216
211
217
save_preferences ()
212
218
213
219
-- Get preferences
214
- local knownPath = dt .preferences .read (MODULE , " known_image_path" , " directory" )
220
+ local containerKnownPath = " /known"
221
+ local containerUnknownPath = " /unknown/"
222
+ local hostKnownPath = dt .preferences .read (MODULE , " known_image_path" , " directory" )
215
223
local nrCores = dt .preferences .read (MODULE , " num_cores" , " integer" )
216
224
local ignoreTagString = dt .preferences .read (MODULE , " ignore_tags" , " string" )
217
225
local categoryTagString = dt .preferences .read (MODULE , " category_tags" , " string" )
@@ -245,15 +253,24 @@ local function face_recognition ()
245
253
end
246
254
247
255
-- Get path of exported images
248
- local path = df .get_path (img_list [1 ])
249
- dt .print_log (" Face recognition: Path to known faces: " .. knownPath )
250
- dt .print_log (" Face recognition: Path to unknown images: " .. path )
256
+ local hostUnknownPath = df .get_path (img_list [1 ])
257
+ dt .print_log (" Face recognition: Path to known faces: " .. hostKnownPath )
258
+ dt .print_log (" Face recognition: Path to unknown images: " .. hostUnknownPath )
251
259
dt .print_log (" Face recognition: Tag used for unknown faces: " .. unknownTag )
252
260
dt .print_log (" Face recognition: Tag used if non person is found: " .. nonpersonsfoundTag )
253
261
os.setlocale (" C" )
254
262
local tolerance = dt .preferences .read (MODULE , " tolerance" , " float" )
255
263
256
- local command = bin_path .. " --cpus " .. nrCores .. " --tolerance " .. tolerance .. " " .. knownPath .. " " .. path .. " > " .. OUTPUT
264
+ local hostCommand = " docker run --rm -v " .. hostKnownPath .. " :" .. containerKnownPath .. " -v " .. hostUnknownPath .. " :" .. containerUnknownPath
265
+ local contianerCommand = " face_recognition" .. " --cpus " .. nrCores .. " --tolerance " .. tolerance .. " " .. containerKnownPath .. " " .. containerUnknownPath .. " > " .. OUTPUT
266
+ local command = " "
267
+ if fc .program_source .value == " python" then
268
+ command = bin_path .. " --cpus " .. nrCores .. " --tolerance " .. tolerance .. " " .. hostKnownPath .. " " .. hostUnknownPath .. " > " .. OUTPUT
269
+ elseif fc .program_source .value == " docker-cpu" then
270
+ command = hostCommand .. " animcogn/face_recognition:cpu " .. contianerCommand
271
+ elseif fc .program_source .value == " docker-gpu" then
272
+ command = hostCommand .. " animcogn/face_recognition:gpu " .. contianerCommand
273
+ end
257
274
os.setlocale ()
258
275
dt .print_log (" Face recognition: Running command: " .. command )
259
276
dt .print (_ (" Starting face recognition..." ))
@@ -278,6 +295,9 @@ local function face_recognition ()
278
295
for line in io.lines (OUTPUT ) do
279
296
if not string.match (line , " ^WARNING:" ) and line ~= " " and line ~= nil then
280
297
local file , tag = string.match (line , " (.*),(.*)$" )
298
+ if fc .program_source .value == " docker-cpu" or fc .program_source .value == " docker-gpu" then
299
+ file = string.gsub (file , containerUnknownPath , hostUnknownPath )
300
+ end
281
301
tag = string.gsub (tag , " %d*$" , " " )
282
302
dt .print_log (" File:" .. file .. " Tag:" .. tag )
283
303
tag_object = {}
@@ -430,6 +450,25 @@ fc.known_image_path = dt.new_widget("file_chooser_button"){
430
450
end
431
451
}
432
452
453
+ fc .program_source = dt .new_widget (" combobox" ){
454
+ label = _ (" program_source" ),
455
+ tooltip = _ (" source of the face_recognition program" ),
456
+ selected = dt .preferences .read (MODULE , " program_source" , " integer" ),
457
+ changed_callback = function (this )
458
+ dt .preferences .write (MODULE , " program_source" , " integer" , this .selected )
459
+ if this .selected == 2 or this .selected == 3 then
460
+ fc .executable .visible = false
461
+ else
462
+ fc .executable .visible = true
463
+ end
464
+ end ,
465
+ " python" , " docker-cpu" , " docker-gpu" ,
466
+ }
467
+
468
+ if dt .configuration .running_os == " windows" or dt .configuration .running_os == " macos" then
469
+ fc .executable = df .executable_path_widget ({" face_recognition" })
470
+ end
471
+
433
472
fc .export_format = dt .new_widget (" combobox" ){
434
473
label = _ (" export image format" ),
435
474
tooltip = _ (" format for exported images" ),
@@ -470,27 +509,26 @@ local widgets = {
470
509
fc .category_tags ,
471
510
dt .new_widget (" label" ){ label = _ (" face data directory" )},
472
511
fc .known_image_path ,
512
+ dt .new_widget (" section_label" ){ label = _ (" source options" )},
513
+ fc .program_source ,
514
+ fc .executable ,
515
+ dt .new_widget (" section_label" ){ label = _ (" processing options" )},
516
+ fc .tolerance ,
517
+ fc .num_cores ,
518
+ fc .export_format ,
519
+ dt .new_widget (" box" ){
520
+ orientation = " horizontal" ,
521
+ dt .new_widget (" label" ){ label = _ (" width " )},
522
+ fc .width ,
523
+ },
524
+ dt .new_widget (" box" ){
525
+ orientation = " horizontal" ,
526
+ dt .new_widget (" label" ){ label = _ (" height " )},
527
+ fc .height ,
528
+ },
529
+ fc .execute
473
530
}
474
531
475
- if dt .configuration .running_os == " windows" or dt .configuration .running_os == " macos" then
476
- table.insert (widgets , df .executable_path_widget ({" face_recognition" }))
477
- end
478
- table.insert (widgets , dt .new_widget (" section_label" ){ label = _ (" processing options" )})
479
- table.insert (widgets , fc .tolerance )
480
- table.insert (widgets , fc .num_cores )
481
- table.insert (widgets , fc .export_format )
482
- table.insert (widgets , dt .new_widget (" box" ){
483
- orientation = " horizontal" ,
484
- dt .new_widget (" label" ){ label = _ (" width " )},
485
- fc .width ,
486
- })
487
- table.insert (widgets , dt .new_widget (" box" ){
488
- orientation = " horizontal" ,
489
- dt .new_widget (" label" ){ label = _ (" height " )},
490
- fc .height ,
491
- })
492
- table.insert (widgets , fc .execute )
493
-
494
532
fc .widget = dt .new_widget (" box" ){
495
533
orientation = vertical ,
496
534
reset_callback = function (this )
@@ -515,6 +553,10 @@ else
515
553
end
516
554
end
517
555
556
+ if fc .program_source .selected == 2 or fc .program_source .selected == 3 then
557
+ fc .executable .visible = false
558
+ end
559
+
518
560
fc .tolerance .value = dt .preferences .read (MODULE , " tolerance" , " float" )
519
561
520
562
-- preferences
0 commit comments