@@ -4,8 +4,20 @@ VMX runs as a server and processes requests over HTTP.
44
55---
66
7+ By default, VMX runs on port 3000. If running locally, the address of
8+ VMX will be ` http://localhost:3000 ` and if running remotely, the
9+ address will be something like ` http://192.168.1.134:3000 ` where the
10+ IP address points to your server. If you're running on a vision.ai
11+ hosted machine which uses https, the address will be something like
12+ ` https://demo.vision.ai/ ` , without the port.
13+
714## VMX REST API
815
16+ The VMX REST API allows you to send commands to VMX to create new
17+ detection processes, perform object detection, create new models, as
18+ well as return the images inside a model's training set. The input and
19+ outputs are always in JSON format (unless specified otherwise).
20+
921VERB | Route | Description
1022----|-------------| ----------
1123GET | /session | List open sessions
@@ -26,6 +38,215 @@ GET | /models/#ModelId/data_set/first.jpg | Return first image in model
2638GET | /models/#ModelId/data_set/image.jpg | Return next image in model
2739GET | /models/#ModelId/data_set/random.jpg | Return random image in model
2840
41+ #### Using curl and jq
42+
43+ To use the VMX REST API from the command line, we will be using ` curl `
44+ to send/receive requests and ` jq ` to render the resulting JSONs with
45+ color. Your system should already have curl installed, and jq can be
46+ downloaded from
47+ [ http://stedolan.github.io/jq/ ] ( http://stedolan.github.io/jq/ ) .
48+
49+ ## Example 1: Check the number of models and sessions
50+
51+ In this example, we will use the command line to check the number of
52+ models as well as the number of open sessions. We will then create a
53+ new session with the model called "eyes", detect these objects
54+ in a single image, and then shut down the session.
55+
56+ ** Command line input**
57+ ```
58+ curl http://localhost:3000/model | jq .
59+ ```
60+
61+ ** Output**
62+ ```
63+ {
64+ "data": [
65+ {
66+ "image": "models/008db1b3-acd3-49fe-94ea-a51297926ada/image.jpg",
67+ "history": [],
68+ "num_pos": 1000,
69+ "num_neg": 462,
70+ "size": [
71+ 10,
72+ 8
73+ ],
74+ "uuid": "008db1b3-acd3-49fe-94ea-a51297926ada",
75+ "name": "hoc_faces",
76+ "start_time": "2015-04-14T06:04:23.684Z",
77+ "end_time": "2015-04-14T06:42:57.985Z",
78+ "meta": ""
79+ },
80+ {
81+ "image": "models/05883a2b-c2f8-4cc9-bdc3-a17dd38e7c6f/image.jpg",
82+ "history": [],
83+ "num_pos": 100,
84+ "num_neg": 200,
85+ "size": [
86+ 10,
87+ 8
88+ ],
89+ "uuid": "05883a2b-c2f8-4cc9-bdc3-a17dd38e7c6f",
90+ "name": "joker",
91+ "start_time": "2015-03-27T02:00:51.784Z",
92+ "end_time": "2015-04-13T08:29:21.932Z",
93+ "meta": ""
94+ }
95+ ...
96+ ```
97+
98+ This output can become quite long. To quickly count the number of
99+ available models from the command line, you can simply use the jq JSON
100+ command line processor as follows:
101+
102+ ** Command line input**
103+ ```
104+ curl -s http://localhost:3000/model | jq '.data | length'
105+ ```
106+
107+ ** Output**
108+ ```
109+ 64
110+ ```
111+
112+ Let's now check the number of running VMX sessions:
113+
114+ ** Command line input**
115+ ```
116+ curl -s http://localhost:3000/session | jq '.data | length'
117+ ```
118+
119+ ** Output**
120+ ```
121+ 0
122+ ```
123+
124+ We have 64 models, but no loaded sessions, so let's create a new
125+ session by POSTing to /session.
126+
127+ ## Example 2: Load "eyes" model and get detections
128+
129+ Let's first find the UUID of the
130+ model corresponding to the name "eyes". You can manually inspect
131+ the returned JSON, or use jq to find the data element with the
132+ matching name.
133+
134+ ** Command line input**
135+ ```
136+ curl -s http://localhost:3000/model | jq -r '.data[] | select(.name=="eyes") .uuid'
137+ ```
138+
139+ ** Output**
140+ ```
141+ e018112b-c9ba-437f-959d-49280acb8c9c
142+ ```
143+
144+ UUIDs are unique and assigned to object models at creation time, so
145+ your personal model library will have different UUIDs. *** Note:*** If
146+ you are showing 0 models, then you'll need to create some using the
147+ VMX GUI.
148+
149+ Let's create a new VMX session with this model UUID.
150+
151+ ** Command line input**
152+ ```
153+ curl -X POST -d '{"uuids":["e018112b-c9ba-437f-959d-49280acb8c9c"]}' http://localhost:3000/session
154+ ```
155+
156+ The output will give us a new session id.
157+
158+ ** Output**
159+ ```
160+
161+ { "data": {
162+ "id": "15c3a5dc-cffb-43ac-a5dd-6755f5376c81"
163+ }
164+ }
165+ ```
166+
167+ We can now verify that the number of sessions is 1.
168+
169+ ** Command line input**
170+ ```
171+ curl -s localhost:3000/session | jq .
172+ ```
173+
174+ ** Output**
175+ ```
176+ {
177+ "data": [
178+ {
179+ "model": {
180+ "image": "models/1ad3282b-3fce-4f56-ae90-2a4d16d2f40d/image.jpg",
181+ "num_pos": 200,
182+ "num_neg": 200,
183+ "size": [
184+ 10,
185+ 10
186+ ],
187+ "uuid": "1ad3282b-3fce-4f56-ae90-2a4d16d2f40d",
188+ "name": "open_mouth",
189+ "start_time": "2015-04-15T02:58:01.115Z",
190+ "end_time": "2015-04-15T06:55:53.230Z"
191+ },
192+ "id": "24f362c8-75aa-43ca-8fc3-f9ceeaf5cef0"
193+ }
194+ ]
195+ }
196+ ```
197+
198+ Let's now send an image URL to this VMX session and get the results of
199+ the "eyes" detection. We will be using the following image:
200+
201+ [ http://people.csail.mit.edu/tomasz/img/tomasz_blue_crop.jpg ] ( http://people.csail.mit.edu/tomasz/img/tomasz_blue_crop.jpg )
202+
203+ <img src =" http://people.csail.mit.edu/tomasz/img/tomasz_blue_crop.jpg " ></img >
204+
205+ ** Command line input**
206+ ```
207+ curl -s -X POST -d '{"images":[{"image":"http://people.csail.mit.edu/tomasz/img/tomasz_blue_crop.jpg"}]}' localhost:3000/session/15c3a5dc-cffb-43ac-a5dd-6755f5376c81
208+ ```
209+
210+ ** Output**
211+ ```
212+ {
213+ "error": 0,
214+ "message": "Process Image Success",
215+ "time": 0.194657229,
216+ "model": {
217+ "uuid": "e018112b-c9ba-437f-959d-49280acb8c9c",
218+ "name": "eyes",
219+ "size": [
220+ 4,
221+ 10
222+ ],
223+ "num_pos": 882,
224+ "num_neg": 360,
225+ "start_time": "2015-03-16T04:29:36.921Z",
226+ "end_time": "2015-04-15T07:36:46.837Z",
227+ "image": "models/e018112b-c9ba-437f-959d-49280acb8c9c/image.jpg"
228+ },
229+ "objects": [
230+ {
231+ "name": "eyes",
232+ "bb": [
233+ 103.7099005310307,
234+ 172.78516300280293,
235+ 274.2637297891478,
236+ 242.85019767944317
237+ ],
238+ "score": 8.147063606844702
239+ }
240+ ]
241+ }
242+ ```
243+
244+ In this example, we created a new VMX session with the "eyes"
245+ detector, sent it the location of an image, and obtained the resulting
246+ JSON which shows the location of the object as well as the resulting
247+ confidence score.
248+
249+
29250---
30251
31252## VMXserver API
0 commit comments