You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-18Lines changed: 39 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -13,20 +13,7 @@ Examples of [PythonGateway](https://github.com/intersystems-community/PythonGate
13
13
2. Load ObjectScript code (i.e. `do $system.OBJ.ImportDir("C:\InterSystems\Repos\PythongatewaySamples\","*.cls","c",,1)`) into Production (Ensemble-enabled) namespace. In case you want to Production-enable namespace call: `write ##class(%EnsembleMgr).EnableNamespace($Namespace, 1)`.
14
14
3. Load restaurant data with: `do ##class(ml.match.Restaurant).Import()`.
15
15
4. Load match data with: `do $system.OBJ.ImportDir("C:\InterSystems\Repos\PythongatewaySamples\","*.xml","c")`
@@ -69,19 +56,53 @@ Start `Predict Service` and `Check Service` to see model be automatically retrai
69
56
70
57
## Sample 3. Image Search engine
71
58
72
-
Do not forget to switch into `Cam` category.
59
+
This example shows image similarity search, by default we are using footwear dataset, but any type of image can be used, as long as the target object is the main object on the images in the dataset. Additionally this is how AI model can be exposed via REST API in InterSystems IRIS. This example can be used as a featuire in retail mobile app to allow user take product photos from a camera and find corresponding product(s) from the retailer shop.
60
+
61
+
### Walkthrough
62
+
63
+
-`ml.cam.data.Photo` class contains our dataset of photos. Use `LoadDir` method to add more photos.
64
+
-`ml.cam.ens.bp.LoaderProcess` receives ids of `ml.cam.data.Photo` and indexes them:
65
+
- Images are resized and rescaled
66
+
- Images are passed to the chosen NN to get feature vectors (note that we use NN without the last classification layer to get better results for image as a whole)
67
+
- Feature Vectors are indexed using cosive index
68
+
- Index is saved (mmaped) on disk for later reuse
69
+
- Corresponding variables are saved as a `isc.py.data.Context` to Intersystems IRIS
70
+
- On subsequent runs `ml.cam.ens.bp.LoaderProcess` first checks if saved context exists and if it does loads the index/variables instead of building it again
71
+
-`ml.cam.ens.bs.InitService` sends initial trainig request on production startup
72
+
-`ml.cam.ens.bp.MatcherProcess` receives one target image and uses index to find nearest matches
73
+
-`cam.rest.Main` exposes `ml.cam.ens.bp.MatcherProcess` as a REST API webapplication `/cam`
74
+
-`recommend.html` calls `/cam` to gest best matches for uploaded image
75
+
76
+
### Docker setup
77
+
78
+
To preserve the index mount volume to the `/usr/irissys/mgr/Temp` directory. `docker-compose.yml` contains an example.
79
+
80
+
Test page is available at `http://localhost:52773/csp/user/recommend.html`
81
+
73
82
74
83
### Host setup
75
84
76
85
1. Download and unpack any image dataset, for example [this](http://vision.cs.utexas.edu/projects/finegrained/utzap50k/ut-zap50k-images.zip).
77
86
2. Load dataset into InterSystems IRIS: `zw ##class(ml.cam.data.Photo).LoadDir(<dir>)`.
78
87
3. Restart production, it will resend initial trainig request.
79
-
4. Training will take between 10 minutes to 5 hours depending on your CPU/GPU.
88
+
4. Training will take 1-3 hours depending on your CPU/GPU.
80
89
5. Trainig process saves search index automatically so subsequent runs will take <1 minute.
81
90
6. Copy `recommend.html` to any web application.
82
91
7. Create new unauthenticated REST app named `/cam` with `ml.cam.rest.Main` dispatch class.
83
92
8. Open `recommend.html` in browser and send your test image
84
93
85
-
### Docker setup
86
94
87
-
To preserve index mount volume to the `/usr/irissys/mgr/Temp` directory. `docker-compose.yml` contains an example.
95
+
96
+
### Notes
97
+
98
+
- To train a new index execute:
99
+
100
+
```SQL
101
+
TRUNCATE TABLE isc_py_data.Context
102
+
TRUNCATE TABLE isc_py_data.Variable
103
+
```
104
+
105
+
- Sometimes after trainig the index might perform poorly. In that case restart the production.
106
+
- Prebuilt index is available [here](), corresponding globals [here](). Save index as `/usr/irissys/mgr/Temp/index.ann` (this is Default for Docker, in general use check `WorkDirectory` value for `ml.cam.ens.bp.LoaderProcess` and save the file there as `index.ann`.
0 commit comments