@@ -5,12 +5,17 @@ import (
55 "log"
66 "os"
77 "path/filepath"
8+ "sync"
89
910 "github.com/CorentinB/DeepSort/pkg/logging"
1011 filetype "gopkg.in/h2non/filetype.v1"
1112)
1213
1314func run (arguments * Arguments ) {
15+ // Handle parallelization
16+ count := 0
17+ var wg sync.WaitGroup
18+ // Open input folder
1419 f , err := os .Open (arguments .Input )
1520 if err != nil {
1621 log .Fatal (err )
@@ -22,16 +27,27 @@ func run(arguments *Arguments) {
2227 os .Exit (1 )
2328 }
2429
30+ // Process files in the input folder
2531 for _ , file := range files {
2632 path := arguments .Input + "/" + file .Name ()
2733 buf , _ := ioutil .ReadFile (path )
2834 if filetype .IsImage (buf ) {
29- googleNetClassification (path , arguments )
35+ count ++
36+ wg .Add (1 )
37+ go googleNetClassification (path , arguments , & wg )
38+ if count == arguments .Jobs {
39+ wg .Wait ()
40+ count = 0
41+ }
3042 }
3143 }
3244}
3345
3446func runRecursively (arguments * Arguments ) ([]string , error ) {
47+ // Handle parallelization
48+ count := 0
49+ var wg sync.WaitGroup
50+ // Open input folder
3551 fileList := make ([]string , 0 )
3652 e := filepath .Walk (arguments .Input , func (path string , f os.FileInfo , err error ) error {
3753 fileList = append (fileList , path )
@@ -46,7 +62,13 @@ func runRecursively(arguments *Arguments) ([]string, error) {
4662 for _ , file := range fileList {
4763 buf , _ := ioutil .ReadFile (file )
4864 if filetype .IsImage (buf ) {
49- googleNetClassification (file , arguments )
65+ count ++
66+ wg .Add (1 )
67+ go googleNetClassification (file , arguments , & wg )
68+ }
69+ if count == arguments .Jobs {
70+ wg .Wait ()
71+ count = 0
5072 }
5173 }
5274
0 commit comments