├── README.md └── dsm.py /README.md: -------------------------------------------------------------------------------- 1 | # deepstack manager 2 | 3 | Simple command-line tool to manage faces "memory" of deepstack instance. It provides simple means to register, delete and list faces as well as submit images for face recognition or object detection. 4 | 5 | The script simplifies registering face with multiple images by submitting all image files present in current directory. 6 | 7 |
 8 | 
 9 | $ dsm -h
10 | usage: dsm [-h] [-H HOST] {register,recognize,detect,delete,list} ...
11 | 
12 | Deepstack management tool.
13 | 
14 | positional arguments:
15 |   {register,recognize,detect,delete,list}
16 | 
17 | optional arguments:
18 |   -h, --help            show this help message and exit
19 |   -H HOST, --host HOST  Address of deepstack server
20 | 
21 | 
22 | 
23 | $ dsm register -h
24 | usage: dsm register [-h] [-m MASK | -p PATH] name
25 | 
26 | positional arguments:
27 |   name                  Name to register
28 | 
29 | optional arguments:
30 |   -h, --help            show this help message and exit
31 |   -m MASK, --mask MASK  Mask for files to include
32 |   -p PATH, --path PATH  Path
33 | 
34 | 
35 | 
36 | $ dsm recognize -h
37 | usage: dsm recognize [-h] file
38 | 
39 | positional arguments:
40 |   file        File to submit for face recognition
41 | 
42 | 
43 | 
44 | $ dsm detect -h
45 | usage: dsm detect [-h] file
46 | 
47 | positional arguments:
48 |   file        File to submit for object detection
49 | 
50 | 
51 | 
52 | $ dsm delete -h
53 | usage: dsm delete [-h] name
54 | 
55 | positional arguments:
56 |   name        Name to delete
57 | 


--------------------------------------------------------------------------------
/dsm.py:
--------------------------------------------------------------------------------
 1 | #!/usr/bin/env python3
 2 | 
 3 | from PIL import Image
 4 | from time import sleep
 5 | import requests, json
 6 | import glob
 7 | import argparse
 8 | import os
 9 | import io
10 | 
11 | 
12 | DEEPSTACK_ADDRESS="localhost:5000"
13 | 
14 | parser = argparse.ArgumentParser(description='Deepstack management tool.')
15 | parser.add_argument('-H','--host', default=DEEPSTACK_ADDRESS, help='Address of deepstack server')
16 | subparser = parser.add_subparsers(dest='action')
17 | r_parser = subparser.add_parser('register')
18 | r_parser.add_argument('name', help='Name to register')
19 | group = r_parser.add_mutually_exclusive_group(required=False)
20 | group.add_argument('-m','--mask', default="*.jpg", help='Mask for files to include e.g. "*.jpg"')
21 | group.add_argument('-p','--path', default=".", help="Path")
22 | 
23 | rec_parser = subparser.add_parser('recognize')
24 | rec_parser.add_argument('file', help='File to submit for face recognition')
25 | det_parser = subparser.add_parser('detect')
26 | det_parser.add_argument('file', help='File to submit for object detection')
27 | d_parser = subparser.add_parser('delete')
28 | d_parser.add_argument('name', help='Name to delete')
29 | l_parser = subparser.add_parser('list')
30 | subparser.default = "list"
31 | args = parser.parse_args()
32 | 
33 | 
34 | if args.action == "register":
35 | 
36 |     if args.path:
37 |        path = args.path + "/" + args.mask
38 |     else:
39 |         path = os.getcwd() + "/" + args.mask
40 | 
41 |     output = io.BytesIO()
42 |     images = {}
43 |     i = 0
44 |     for file in glob.glob(path):
45 |         img = Image.open(file)
46 |         img.save(output, format='JPEG', quality=100, subsampling=0)
47 |         images["image"+str(i)] = output.getvalue()
48 |         i += 1
49 | 
50 |     if i > 0:
51 |       response = requests.post("http://"+args.host+"/v1/vision/face/register", files=images, data={"userid":args.name}).json()
52 |       print(response)
53 | 
54 | elif args.action == "recognize":
55 | 
56 |     output = io.BytesIO()
57 |     images = {}
58 |     img = Image.open(args.file)
59 |     img.save(output, format='JPEG', quality=100, subsampling=0)
60 |     images["image"] = output.getvalue()
61 | 
62 |     response = requests.post("http://"+args.host+"/v1/vision/face/recognize", files=images).json()
63 |     print(response)
64 | 
65 | elif args.action == "detect":
66 | 
67 |     output = io.BytesIO()
68 |     images = {}
69 |     img = Image.open(args.file)
70 |     img.save(output, format='JPEG', quality=100, subsampling=0)
71 |     images["image"] = output.getvalue()
72 | 
73 |     response = requests.post("http://"+args.host+"/v1/vision/detection", files=images).json()
74 |     print(response)
75 | 
76 | elif args.action == "delete":
77 |     response = requests.post("http://"+args.host+"/v1/vision/face/delete", data={"userid":args.name}).json()
78 |     print(response)
79 | 
80 | elif args.action == "list":
81 |     response = requests.post("http://"+args.host+"/v1/vision/face/list").json()
82 |     print(response)
83 | 


--------------------------------------------------------------------------------