-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joseph Marino
committed
Apr 4, 2022
1 parent
914462d
commit b504018
Showing
10 changed files
with
192 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Cloud Deployment | ||
If you don't have access to GPU or appropriate hardware and don't want to install ImageJ, we have also created a [cloud-native DeepLIIF deployment](https://deepliif.org) with a user-friendly interface to upload images, visualize, interact, and download the final results. | ||
|
||
DeepLIIF can also be accessed programmatically through an endpoint by posting a multipart-encoded request | ||
containing the original image file: | ||
|
||
``` | ||
POST /api/infer | ||
Parameters | ||
img (required) | ||
file: image to run the models on | ||
resolution | ||
string: resolution used to scan the slide (10x, 20x, 40x), defaults to 20x | ||
pil | ||
boolean: if true, use PIL.Image.open() to laod the image, instead of python-bioformats | ||
slim | ||
boolean: if true, return only the segmentation result image | ||
``` | ||
|
||
For example, in Python: | ||
|
||
```python | ||
import os | ||
import json | ||
import base64 | ||
from io import BytesIO | ||
|
||
import requests | ||
from PIL import Image | ||
|
||
# Use the sample images from the main DeepLIIF repo | ||
images_dir = './Sample_Large_Tissues' | ||
filename = 'ROI_1.png' | ||
|
||
res = requests.post( | ||
url='https://deepliif.org/api/infer', | ||
files={ | ||
'img': open(f'{images_dir}/{filename}', 'rb') | ||
}, | ||
# optional param that can be 10x, 20x (default) or 40x | ||
params={ | ||
'resolution': '20x' | ||
} | ||
) | ||
|
||
data = res.json() | ||
|
||
def b64_to_pil(b): | ||
return Image.open(BytesIO(base64.b64decode(b.encode()))) | ||
|
||
for name, img in data['images'].items(): | ||
output_filepath = f'{images_dir}/{os.path.splitext(filename)[0]}_{name}.png' | ||
with open(output_filepath, 'wb') as f: | ||
b64_to_pil(img).save(f, format='PNG') | ||
|
||
print(json.dumps(data['scoring'], indent=2)) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Testing | ||
|
||
## Serialize Model | ||
The installed `deepliif` uses Dask to perform inference on the input IHC images. | ||
Before running the `test` command, the model files must be serialized using Torchscript. | ||
To serialize the model files: | ||
``` | ||
deepliif serialize --models-dir /path/to/input/model/files | ||
--output-dir /path/to/output/model/files | ||
``` | ||
* By default, the model files are expected to be located in `DeepLIIF/model-server/DeepLIIF_Latest_Model`. | ||
* By default, the serialized files will be saved to the same directory as the input model files. | ||
|
||
## Testing | ||
To test the model: | ||
``` | ||
deepliif test --input-dir /path/to/input/images | ||
--output-dir /path/to/output/images | ||
--tile-size 512 | ||
``` | ||
* The latest version of the pretrained models can be downloaded [here](https://zenodo.org/record/4751737#.YKRTS0NKhH4). | ||
* Before running test on images, the model files must be serialized as described above. | ||
* The serialized model files are expected to be located in `DeepLIIF/model-server/DeepLIIF_Latest_Model`. | ||
* The test results will be saved to the specified output directory, which defaults to the input directory. | ||
* The default tile size is 512. | ||
* Testing datasets can be downloaded [here](https://zenodo.org/record/4751737#.YKRTS0NKhH4). | ||
|
||
If you prefer, it is possible to run the model using Torchserve. | ||
Please see below for instructions on how to deploy the model with Torchserve and for an example of how to run the inference. |
Oops, something went wrong.