Skip to content

Commit

Permalink
Negative pred p-value example
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodore Zhao committed Nov 23, 2024
1 parent 5b95a98 commit 674be0c
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This repository hosts the code and resources for the paper **"A Foundation Model

![Example Predictions](assets/readmes/biomedparse_prediction_examples.png)

## News
- Nov. 22, 2024: We added negative prediction p-value example in inference_example_DICOM.ipynb
- Nov. 18, 2024: BiomedParse is officially online in [*Nature Methods*](https://aka.ms/biomedparse-paper)!

## Installation
```sh
git clone https://github.com/microsoft/BiomedParse.git
Expand Down
107 changes: 100 additions & 7 deletions inference_examples_DICOM.ipynb

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions inference_utils/output_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,26 @@ def check_mask_stats(img, mask, modality_type, target):
# modality_type: str, see target_dist.json for the list of modality types
# target: str, see target_dist.json for the list of targets

mask_stats = mask_stats(mask, img)
if modality_type not in target_dist:
raise ValueError(f"Currently support modality types: {list(target_dist.keys())}")

ps = [stats.ks_1samp([mask_stats[i]], stats.beta(param[0], param[1]).cdf).pvalue for i, param in enumerate(target_dist[modality_type][target])]
if target not in target_dist[modality_type]:
raise ValueError(f"Currently support targets for {modality_type}: {list(target_dist[modality_type].keys())}")

ms = mask_stats(mask, img)

ps = [stats.ks_1samp([ms[i]], stats.beta(param[0], param[1]).cdf).pvalue for i, param in enumerate(target_dist[modality_type][target])]
p_value = np.prod(ps)

return p_value
adj_p_value = p_value**0.24 # adjustment for four test products

return adj_p_value



def mask_stats(mask, img):
# mask is a prediction mask with pixel values in [0, 255] for probability in [0, 1]
# img is a RGB image with pixel values in [0, 255]
if mask.max() <= 127:
return [0, 0, 0, 0]
return [mask[mask>=128].mean()/256, img[:,:,0][mask>=128].mean()/256,
Expand Down

0 comments on commit 674be0c

Please sign in to comment.