Skip to content

Commit 236df57

Browse files
authored
Update README.md
1 parent 71e7ca9 commit 236df57

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

README.md

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,7 @@ Examples of [PythonGateway](https://github.com/intersystems-community/PythonGate
1313
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)`.
1414
3. Load restaurant data with: `do ##class(ml.match.Restaurant).Import()`.
1515
4. Load match data with: `do $system.OBJ.ImportDir("C:\InterSystems\Repos\PythongatewaySamples\","*.xml","c")`
16-
5. Install these libraries:
17-
18-
```
19-
pip install recordlinkage
20-
pip install dedupe
21-
pip install pandas
22-
pip install numpy
23-
pip install matplotlib
24-
pip install sklearn
25-
pip install seaborn
26-
pip install tensorflow
27-
pip install tensorflow_hub
28-
pip install annoy
29-
```
16+
5. Install required libraries: `pip install -r requirements.txt`
3017
6. Open and start `ml.Production`.
3118

3219
# Samples
@@ -69,19 +56,53 @@ Start `Predict Service` and `Check Service` to see model be automatically retrai
6956

7057
## Sample 3. Image Search engine
7158

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+
7382

7483
### Host setup
7584

7685
1. Download and unpack any image dataset, for example [this](http://vision.cs.utexas.edu/projects/finegrained/utzap50k/ut-zap50k-images.zip).
7786
2. Load dataset into InterSystems IRIS: `zw ##class(ml.cam.data.Photo).LoadDir(<dir>)`.
7887
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.
8089
5. Trainig process saves search index automatically so subsequent runs will take <1 minute.
8190
6. Copy `recommend.html` to any web application.
8291
7. Create new unauthenticated REST app named `/cam` with `ml.cam.rest.Main` dispatch class.
8392
8. Open `recommend.html` in browser and send your test image
8493

85-
### Docker setup
8694

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`.
107+
108+

0 commit comments

Comments
 (0)