Niv Sardi commited on
Commit
26ef429
1 Parent(s): 55a3f0e

make watcher accept arguments,

Browse files
Files changed (5) hide show
  1. README.org +4 -4
  2. detect.js +1 -1
  3. python/imtool.py +1 -1
  4. python/watcher.py +35 -12
  5. python/write_data.py +1 -1
README.org CHANGED
@@ -20,13 +20,13 @@ The process is pretty simple:
20
  # build the training dataset
21
  docker-compose up --build --remove-orphans -d
22
  docker-compose exec python ./run
23
-
24
  # run the training on your machine or collab
25
  # https://colab.research.google.com/drive/10R7uwVJJ1R1k6oTjbkkhxPDka7COK-WE
26
  git clone https://github.com/ultralytics/yolov5 # clone repo
27
  pip install -U -r yolov5/requirements.txt # install dependencies
28
  python3 yolov5/train.py --img 416 --batch 80 --epochs 100 --data ./ia/data.yaml --cfg ./ia/yolov5s.yaml --weights ''
29
-
30
  #+end_src
31
 
32
  * research
@@ -38,10 +38,10 @@ https://github.com/Hyuto/yolov5-tfjs
38
  there were a lot of augmentation solutions out there, because it had better
39
  piplines and multicore support we went with:
40
  - https://github.com/aleju/imgaug
41
-
42
  but leaving the other here for refs
43
  - https://github.com/srp-31/Data-Augmentation-for-Object-Detection-YOLO-
44
- - https://github.com/mdbloice/Augmentor
45
 
46
  ** proveedores
47
  http://www.bcra.gov.ar/SistemasFinancierosYdePagos/Proveedores-servicios-de-pago-ofrecen-cuentas-de-pago.asp
 
20
  # build the training dataset
21
  docker-compose up --build --remove-orphans -d
22
  docker-compose exec python ./run
23
+
24
  # run the training on your machine or collab
25
  # https://colab.research.google.com/drive/10R7uwVJJ1R1k6oTjbkkhxPDka7COK-WE
26
  git clone https://github.com/ultralytics/yolov5 # clone repo
27
  pip install -U -r yolov5/requirements.txt # install dependencies
28
  python3 yolov5/train.py --img 416 --batch 80 --epochs 100 --data ./ia/data.yaml --cfg ./ia/yolov5s.yaml --weights ''
29
+
30
  #+end_src
31
 
32
  * research
 
38
  there were a lot of augmentation solutions out there, because it had better
39
  piplines and multicore support we went with:
40
  - https://github.com/aleju/imgaug
41
+
42
  but leaving the other here for refs
43
  - https://github.com/srp-31/Data-Augmentation-for-Object-Detection-YOLO-
44
+ - https://github.com/mdbloice/Augmentor
45
 
46
  ** proveedores
47
  http://www.bcra.gov.ar/SistemasFinancierosYdePagos/Proveedores-servicios-de-pago-ofrecen-cuentas-de-pago.asp
detect.js CHANGED
@@ -4,7 +4,7 @@ let run = () => {
4
  // https://developer.chrome.com/extensions/match_patterns
5
  var ALL_SITES = { urls: ['<all_urls>'] }
6
 
7
- // Mozilla doesn't use tlsInfo in extraInfoSpec
8
  var extraInfoSpec = ['blocking'];
9
 
10
  // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/onHeadersReceived
 
4
  // https://developer.chrome.com/extensions/match_patterns
5
  var ALL_SITES = { urls: ['<all_urls>'] }
6
 
7
+ // Mozilla doesn't use tlsInfo in extraInfoSpec
8
  var extraInfoSpec = ['blocking'];
9
 
10
  // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/onHeadersReceived
python/imtool.py CHANGED
@@ -131,7 +131,7 @@ def cut_logo(im, l):
131
 
132
  def add_alpha(img):
133
  b, g, r = cv2.split(img)
134
- a = np.ones(b.shape, dtype=b.dtype) * 50
135
  return cv2.merge((b,g,r,a))
136
 
137
  def remove_white(img):
 
131
 
132
  def add_alpha(img):
133
  b, g, r = cv2.split(img)
134
+ a = np.ones(b.shape, dtype=b.dtype) * 50
135
  return cv2.merge((b,g,r,a))
136
 
137
  def remove_white(img):
python/watcher.py CHANGED
@@ -1,22 +1,45 @@
1
  import os
2
  import inotify.adapters
 
 
3
  from imtool import read_bounding_boxes, crop
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- def watch(dir):
6
- seen = 0
7
  i = inotify.adapters.Inotify()
8
- i.add_watch(dir)
 
9
  for event in i.event_gen(yield_nones=False):
10
  (_, type_names, path, filename) = event
11
 
12
- if filename.endswith(".png") and type_names[0] in ['IN_CLOSE_WRITE']:
13
- seen += 1
14
- print(f"{seen} PATH=[{path}] FILENAME=[{filename}] EVENT_TYPES={type_names}")
15
- try:
16
- bbs = read_bounding_boxes(os.path.join(path, filename.replace('.png', '.txt')))
17
- crop(os.path.join(path, filename), bbs)
18
- except Exception as e:
19
- print(f"error: {e}")
20
 
21
  if __name__ == '__main__':
22
- watch('./data')
 
 
 
1
  import os
2
  import inotify.adapters
3
+
4
+ import augment
5
  from imtool import read_bounding_boxes, crop
6
+ from common import defaults, mkdir
7
+
8
+ def handle_png(event):
9
+ (_, type_names, path, filename) = event
10
+
11
+ bbs = read_bounding_boxes(os.path.join(path, filename.replace('.png', '.txt')))
12
+ crop(os.path.join(path, filename), bbs)
13
+
14
+ def handle_csv(event):
15
+ (_, type_names, path, filename) = event
16
+
17
+ print('csv changed, will run vendor')
18
+ import vendor
19
+ vendor.from_csv(os.path.join(path, filename))
20
+ augment.process()
21
+
22
+ handlers = {
23
+ '.png': handle_png,
24
+ '.csv': handle_csv
25
+ }
26
 
27
+ def watch(dirs):
 
28
  i = inotify.adapters.Inotify()
29
+ [i.add_watch(d) for d in dirs]
30
+ print(f'watching {dirs}')
31
  for event in i.event_gen(yield_nones=False):
32
  (_, type_names, path, filename) = event
33
 
34
+ for k in handlers.keys():
35
+ if filename.endswith(k) and type_names[0] in ['IN_CLOSE_WRITE']:
36
+ print(f"PATH=[{path}] FILENAME=[{filename}] EVENT_TYPES={type_names}")
37
+ try:
38
+ handlers[k](event)
39
+ except Exception as e:
40
+ print(f'Error in {k} handler: {e}')
 
41
 
42
  if __name__ == '__main__':
43
+ dirs = ['./data', defaults.IMAGES_PATH, defaults.AUGMENTED_IMAGES_PATH]
44
+ mkdir.make_dirs(dirs)
45
+ watch(dirs)
python/write_data.py CHANGED
@@ -20,7 +20,7 @@ if __name__ == '__main__':
20
  parser = argparse.ArgumentParser(description='creates a YOLOv5 data.yaml')
21
  parser.add_argument('csv', metavar='csv', type=str,
22
  help='csv file')
23
- parser.add_argument('--data', metavar='data', type=str,
24
  help='data path', default='../data')
25
  args = parser.parse_args()
26
  bcos = entity.read_entities(args.csv)
 
20
  parser = argparse.ArgumentParser(description='creates a YOLOv5 data.yaml')
21
  parser.add_argument('csv', metavar='csv', type=str,
22
  help='csv file')
23
+ parser.add_argument('--data', metavar='data', type=str,
24
  help='data path', default='../data')
25
  args = parser.parse_args()
26
  bcos = entity.read_entities(args.csv)