-
Notifications
You must be signed in to change notification settings - Fork 2
HDBSCAN clustering method added for Bragg peaks inferred from DL model #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f5670e9
HDBSCAN clustering method added
warunawickramasingha 4a2ba29
resolved conflicts
warunawickramasingha fa55698
torch.load future warning fixed
warunawickramasingha 661c29e
kwargs parameter added for clustering
warunawickramasingha 23898fe
KMeans removed and updated to pass kwargs
warunawickramasingha 593cb24
HDBSCAN link added
warunawickramasingha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,17 +1,29 @@ | ||
| Bragg Peaks detection using a pre-trained Faster RCNN deep neural network | ||
| ================ | ||
|
|
||
| Inorder to use the pre-trained Faster RCNN model inside mantid using an IDAaaS instance, below steps are required. | ||
| Inorder to run the pre-trained Faster RCNN model via mantid inside an IDAaaS instance, below steps are required. | ||
|
|
||
| * Launch an IDAaaS instance with GPUs from WISH > Wish Single Crystal GPU Advanced | ||
| * Launch Mantid workbench nightly from Applications->Software->Mantid->Mantid Workbench Nightly | ||
| * Launch an IDAaaS instance with GPUs selected from WISH > Wish Single Crystal GPU Advanced | ||
| * From IDAaaS, launch Mantid workbench nightly from Applications->Software->Mantid->Mantid Workbench Nightly | ||
| * Download `scriptrepository\diffraction\WISH` directory from mantid's script repository as instructed here https://docs.mantidproject.org/nightly/workbench/scriptrepository.html | ||
| * Check whether `<local path>\diffraction\WISH` path is listed under `Python Script Directories` tab from `File->Manage User Directories` of Mantid workbench. | ||
| * Below is an example code snippet to test the code. It will create a peaks workspace with the inferred peaks from the cnn and will do a peak filtering using the q_tol provided using `BaseSX.remove_duplicate_peaks_by_qlab`. | ||
| * Below is an example code snippet to use the pretrained model for Bragg peak detection. It will create a peaks workspace with the inferred peaks from the model. The valid values for the `clustering` argument are `QLab` or `HDBSCAN`. For `QLab` method the default value of `q_tol=0.05` will be used for `BaseSX.remove_duplicate_peaks_by_qlab` method. | ||
| ```python | ||
| from cnn.BraggDetectCNN import BraggDetectCNN | ||
| model_weights = r'/mnt/ceph/auxiliary/wish/BraggDetect_FasterRCNN_Resnet50_Weights_v1.pt' | ||
| cnn_peaks_detector = BraggDetectCNN(model_weights_path=model_weights, batch_size=64) | ||
| cnn_peaks_detector.find_bragg_peaks(workspace='WISH00042730', output_ws_name="CNN_Peaks", conf_threshold=0.0, q_tol=0.05) | ||
| cnn_peaks_detector.find_bragg_peaks(workspace='WISH00042730', output_ws_name="CNN_Peaks", conf_threshold=0.0, clustering="QLab") | ||
warunawickramasingha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
| * If the above import is not working, check whether the `<local path>\diffraction\WISH` path is listed under `Python Script Directories` tab from `File->Manage User Directories`. | ||
| * Depending on the selected `clustering` method in the above, the user can provide custom parameters using `kwargs` as shown below. | ||
| ``` | ||
| kwargs={"q_tol": 0.1} | ||
| cnn_peaks_detector.find_bragg_peaks(workspace='WISH00042730', output_ws_name="CNN_Peaks", conf_threshold=0.0, clustering="QLab", **kwargs) | ||
|
|
||
| or | ||
|
|
||
| kwargs={"cluster_selection_method": "leaf", "algorithm": "brute", "keep_ignored_labels": False} | ||
| cnn_peaks_detector.find_bragg_peaks(workspace='WISH00042730', output_ws_name="CNN_Peaks", conf_threshold=0.0, clustering="HDBSCAN", **kwargs) | ||
| ``` | ||
| * The documentation for using HDBSCAN can be found here: https://scikit-learn.org/1.5/modules/generated/sklearn.cluster.HDBSCAN.html | ||
| * The documentation for using `BaseSX.remove_duplicate_peaks_by_qlab` can be found here: https://docs.mantidproject.org/nightly/techniques/ISIS_SingleCrystalDiffraction_Workflow.html | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,4 @@ | ||
| -f https://download.pytorch.org/whl/cu118 | ||
| torch | ||
| torchvision | ||
|
|
||
| torch==2.5.1 | ||
| torchvision==0.20.1 | ||
| albumentations==1.4.0 | ||
| tqdm==4.66.3 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.