Skip to content

Commit beb8612

Browse files
committed
Merge branch 'main' of github.com:lunit-io/ocelot23algo into main
2 parents 3fac348 + 02f478b commit beb8612

File tree

3 files changed

+120
-12
lines changed

3 files changed

+120
-12
lines changed

README.md

Lines changed: 112 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,113 @@
1-
# ocelot23algo Algorithm
1+
# OCELOT23: The algorithm
2+
3+
In this repository you will find the source code for the Grand Challenge OCELOT23 algorithm container. Ocelot is both a MICCAI challenge and an accepeted paper at CVPR 23.
4+
5+
# Input and output
6+
7+
* The input: the container searches loads and iterates over the validation images, test images and metadata from the already uploaded data in Grand Challenge. The implemented loader `DataLoader` at `util.gcio.py` will iterate over the samples for you!.
28

3-
The source code for the algorithm container for
4-
ocelot23algo, generated with
5-
evalutils version 0.4.0
6-
using Python 3.9.
9+
* The output: your algorithm needs to predict cells with the Multiple Points format. To make things easier like with the data loader, we implemented a simple writer class `DetectionWriter` to output the corresponding output file `cell_predictions.json`. An example of the output can be found in `test/output/example_output.json`.
10+
11+
```json
12+
{
13+
"type": "Multiple points",
14+
"points": [
15+
{
16+
"name": "0",
17+
"point": [
18+
128.0,
19+
620.0,
20+
1.0
21+
],
22+
"probability": 1.0
23+
},
24+
{
25+
"name": "0",
26+
"point": [
27+
128.0,
28+
621.0,
29+
1.0
30+
],
31+
"probability": 1.0
32+
},
33+
```
34+
35+
# Develop you algorithm
36+
37+
At `user/inference.py` you will find a dummy cell detection algorithm. Your task is to modify the function `process_patch_pair` trying to keep the format used below. Feel free to install any framework, such as PyTorch or Tensorflow to run your code. In addition, do not forget to add your dependencies in `requirement.txt` so that your container can be build correctly.
38+
39+
```python
40+
def process_patch_pair(cell_patch, tissue_patch, pair_id, meta_dataset):
41+
"""This function detects the cells in the cell patch, while additionally
42+
providing the broader tissue context
43+
44+
NOTE: this function offers a dummy example inference code. This must be
45+
updated by the participant.
46+
47+
Parameters
48+
----------
49+
cell_patch: np.ndarray
50+
Cell patch with shape [3, 1024, 1024]
51+
tissue_patch: np.ndarray
52+
Tissue patch with shape [3, 1024, 1024]
53+
pair_id: str
54+
identification number of the patch pair
55+
meta_dataset: Dict
56+
Dataset metadata in case you wish to compute statistics
57+
58+
Returns
59+
-------
60+
List[tuple]: list of tuples (x,y) coordinates of detections
61+
"""
62+
# Getting the metadata corresponding to the patch pair ID
63+
meta_pair = meta_dataset[pair_id]
64+
65+
#############################################
66+
#### YOUR INFERENCE ALGORITHM GOES HERE #####
67+
#############################################
68+
69+
# The following is a dummy cell detection algoritm
70+
prediction = np.copy(cell_patch[2, :, :])
71+
prediction[(cell_patch[2, :, :] <= 40)] = 1
72+
xs, ys = np.where(prediction.transpose() == 1)
73+
probs = [1.0] * len(xs) # Confidence score
74+
class_id = [1] * len(xs) # Type of cell
75+
76+
#############################################
77+
####### RETURN RESULS PER SAMPLE ############
78+
#############################################
79+
80+
# We need to return a list of tuples with 4 elements, i.e.:
81+
# - cell's x-coordinate in the cell patch
82+
# - cell's y-coordinate in the cell patch
83+
# - class id of the cell, either 1 (BC) or 2 (TC)
84+
# - confidence score of the predicted cell
85+
return list(zip(xs, ys, class_id, probs))
86+
```
87+
88+
# Submitting to GC
89+
90+
To submit your algorithm to the GC platform, you'll need to export the docker container wrapping your code.
91+
92+
### Build your docker image
93+
94+
```bash
95+
bash build.sh
96+
```
97+
98+
### Testing before submitting to GC
99+
100+
Before submitting your containers to GC, make sure this simple test works in your local machine. This script will create the image, run the container and verify that the output `cell_predictions.json` at the output directory. To do so, run the following command:
101+
102+
```bash
103+
bash test.sh
104+
```
105+
### Export algorithm docker image
106+
107+
Generate the `tar` file to be uploaded to GC by running the following command:
108+
109+
```bash
110+
bash export.sh
111+
```
112+
113+
# Cite

test.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ docker run --rm \
2424

2525
echo "Done initializing container"
2626

27-
docker run --rm \
28-
-v ocelot23algo-output:/output/ \
29-
python:3.9-slim cat /output/cell_predictions.json | python -m json.tool
27+
# To print the prediction outputs. This could be too verbose
28+
# docker run --rm \
29+
# -v ocelot23algo-output:/output/ \
30+
# python:3.9-slim cat /output/cell_predictions.json | python -m json.tool
3031

3132
echo "Done running the processing script"
3233

@@ -36,9 +37,9 @@ docker run --rm \
3637
python:3.9-slim python -c "import json, sys; f = json.load(open('/output/cell_predictions.json')); sys.exit(not len(f)>0);"
3738

3839
if [ $? -eq 0 ]; then
39-
echo "Tests successfully passed..."
40+
echo "Tests successfully passed"
4041
else
41-
echo "Expected output was not found..."
42+
echo "Expected output was not found"
4243
fi
4344

4445
docker volume rm ocelot23algo-output

user/inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def process_patch_pair(cell_patch, tissue_patch, pair_id, meta_dataset):
2727
meta_pair = meta_dataset[pair_id]
2828

2929
#############################################
30-
#### YOUR INFERENCE ALGORHTM GOES HERE ######
30+
#### YOUR INFERENCE ALGORITHM GOES HERE #####
3131
#############################################
3232

33-
# The following is a dummy cell detection algoritm
33+
# The following is a dummy cell detection algorithm
3434
prediction = np.copy(cell_patch[2, :, :])
3535
prediction[(cell_patch[2, :, :] <= 40)] = 1
3636
xs, ys = np.where(prediction.transpose() == 1)

0 commit comments

Comments
 (0)