|
4 | 4 | "cell_type": "markdown", |
5 | 5 | "metadata": {}, |
6 | 6 | "source": [ |
7 | | - "This package provides convenience classes and functions for working with deepstack face API. \n", |
8 | | - "\n", |
9 | | - "Run deepstack with:\n", |
10 | | - "```\n", |
11 | | - "docker run -e VISION-FACE=True -e MODE=High -d \\\n", |
12 | | - " -v localstorage:/datastore -p 5000:5000 \\\n", |
13 | | - " -e API-KEY=\"Mysecretkey\" \\\n", |
14 | | - " --name deepstack deepquestai/deepstack:noavx\n", |
15 | | - "```" |
| 7 | + "Work with the deepstack face API. " |
16 | 8 | ] |
17 | 9 | }, |
18 | 10 | { |
|
37 | 29 | "IP_ADDRESS = 'localhost'\n", |
38 | 30 | "PORT = '5000'\n", |
39 | 31 | "API_KEY = \"Mysecretkey\"\n", |
40 | | - "TIMEOUT = 8" |
| 32 | + "TIMEOUT = 10 # Default is 10" |
41 | 33 | ] |
42 | 34 | }, |
43 | 35 | { |
|
96 | 88 | "name": "stdout", |
97 | 89 | "output_type": "stream", |
98 | 90 | "text": [ |
99 | | - "[{'confidence': 0.9999846, 'y_min': 162, 'x_min': 1620, 'y_max': 680, 'x_max': 1982}, {'confidence': 0.99997175, 'y_min': 230, 'x_min': 867, 'y_max': 729, 'x_max': 1199}]\n" |
| 91 | + "CPU times: user 8.38 ms, sys: 9.7 ms, total: 18.1 ms\n", |
| 92 | + "Wall time: 2.72 s\n" |
100 | 93 | ] |
101 | 94 | } |
102 | 95 | ], |
103 | 96 | "source": [ |
104 | | - "#%%time\n", |
| 97 | + "%%time\n", |
105 | 98 | "try:\n", |
106 | | - " dsface.process_file(image_path)\n", |
107 | | - " print(dsface.predictions)\n", |
| 99 | + " with open(image_path, \"rb\") as image_bytes:\n", |
| 100 | + " dsface.detect(image_bytes)\n", |
108 | 101 | "except ds.DeepstackException as exc:\n", |
109 | 102 | " print(exc)" |
110 | 103 | ] |
|
174 | 167 | }, |
175 | 168 | { |
176 | 169 | "cell_type": "code", |
177 | | - "execution_count": 8, |
| 170 | + "execution_count": 9, |
178 | 171 | "metadata": {}, |
179 | 172 | "outputs": [ |
180 | 173 | { |
181 | 174 | "name": "stdout", |
182 | 175 | "output_type": "stream", |
183 | 176 | "text": [ |
184 | | - "Taught face idris using file tests/images/couple.jpg\n" |
| 177 | + "CPU times: user 4.46 ms, sys: 3.62 ms, total: 8.09 ms\n", |
| 178 | + "Wall time: 2.78 s\n" |
185 | 179 | ] |
186 | 180 | } |
187 | 181 | ], |
188 | 182 | "source": [ |
189 | | - "dsface.register_face(name=\"idris\", file_path = 'tests/images/couple.jpg')" |
| 183 | + "%%time\n", |
| 184 | + "try:\n", |
| 185 | + " with open(image_path, \"rb\") as image_bytes:\n", |
| 186 | + " dsface.register_face(\"idris\", image_bytes)\n", |
| 187 | + "except ds.DeepstackException as exc:\n", |
| 188 | + " print(exc)" |
190 | 189 | ] |
191 | 190 | }, |
192 | 191 | { |
193 | | - "cell_type": "code", |
194 | | - "execution_count": 10, |
| 192 | + "cell_type": "markdown", |
195 | 193 | "metadata": {}, |
196 | | - "outputs": [ |
197 | | - { |
198 | | - "ename": "FileNotFoundError", |
199 | | - "evalue": "[Errno 2] No such file or directory: 'tests/images/couplesdf.jpg'", |
200 | | - "output_type": "error", |
201 | | - "traceback": [ |
202 | | - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
203 | | - "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", |
204 | | - "\u001b[0;32m<ipython-input-10-ab14dae0eb4a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdsface\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mregister_face\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"idris\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfile_path\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'tests/images/couplesdf.jpg'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", |
205 | | - "\u001b[0;32m~/Github/deepstack-python/deepstack/core.py\u001b[0m in \u001b[0;36mregister_face\u001b[0;34m(self, name, file_path)\u001b[0m\n\u001b[1;32m 155\u001b[0m \"\"\"\n\u001b[1;32m 156\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 157\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfile_path\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"rb\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mimage\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 158\u001b[0m response = post_image(\n\u001b[1;32m 159\u001b[0m \u001b[0murl\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mURL_FACE_REGISTRATION\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_ip_address\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_port\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
206 | | - "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'tests/images/couplesdf.jpg'" |
207 | | - ] |
208 | | - } |
209 | | - ], |
210 | 194 | "source": [ |
211 | | - "dsface.register_face(name=\"idris\", file_path = 'tests/images/couplesdf.jpg')" |
| 195 | + "## Face recognition\n", |
| 196 | + "Recoginition will match any faces that have been taught. This is slower than face detection" |
212 | 197 | ] |
213 | 198 | }, |
214 | 199 | { |
|
219 | 204 | "The package provides helper functions for extracting info out of deepstack predictions" |
220 | 205 | ] |
221 | 206 | }, |
222 | | - { |
223 | | - "cell_type": "code", |
224 | | - "execution_count": null, |
225 | | - "metadata": {}, |
226 | | - "outputs": [], |
227 | | - "source": [ |
228 | | - "name=\"idris\"\n", |
229 | | - "file_path=\"foo.jpg\"\n", |
230 | | - "print(\"Taught face {} using file {}\".format(name, file_path))" |
231 | | - ] |
232 | | - }, |
233 | 207 | { |
234 | 208 | "cell_type": "code", |
235 | 209 | "execution_count": null, |
|
0 commit comments