Spaces:
Sleeping
Sleeping
| import os | |
| import gradio as gr | |
| # from model import predict | |
| import cv2 | |
| # os.system("cd ./D-MASTER_1/models/ops") | |
| os.system("sh ./D-MASTER_1/models/ops/make.sh") | |
| print("Layer building done!") | |
| # with gr.Blocks() as demo: | |
| # with gr.Column(): | |
| # title = "<h1 style='margin-bottom: -10px; text-align: center'>D-MASTER: Mask Annealed Transformer for Unsupervised Domain Adaptation in Breast Cancer Detection from Mammograms</h1>" | |
| # # gr.HTML(title) | |
| # gr.Markdown( | |
| # "<h1 style='text-align: center; margin-bottom: 1rem'>" | |
| # + title | |
| # + "</h1>" | |
| # ) | |
| # description = "<p style='font-size: 14px; margin: 5px; font-weight: 300; text-align: center'> <a href='' style='text-decoration:none' target='_blank'>Tajamul Ashraff<sup>*</sup></a>, <a href='' style='text-decoration:none' target='_blank'>Chetan Arora<sup>*</sup></a> </p>" \ | |
| # + "<p style='font-size: 16px; margin: 5px; font-weight: 600; text-align: center'> <a href='' target='_blank'>Publication</a> | <a href='' target='_blank'>Website</a> | <a href='' target='_blank'>Github Repo</a></p>" \ | |
| # + "<p style='text-align: center; margin: 5px; font-size: 14px; font-weight: 300;'> We focus on the problem of Unsupervised Domain Adaptation (UDA) for breast cancer detection from mammograms (BCDM) problem. Recent advancements have shown that masked image modeling serves as a robust pretext task for UDA. However, when applied to cross-domain BCDM, these techniques struggle with breast abnormalities such as masses, asymmetries, and micro-calcifications, in part due to the typically much smaller size of region of interest in comparison to natural images. This often results in more false positives per image (FPI) and significant noise in pseudo-labels typically used to bootstrap such techniques. Recognizing these challenges, we introduce a transformer-based Domain-invariant Mask Annealed Student Teacher autoencoder (D-MASTER) framework. D-MASTER adaptively masks and reconstructs multi-scale feature maps, enhancing the model’s ability to capture reliable target domain features. D-MASTER also includes adaptive confidence refinement to filter pseudo-labels, ensuring only high-quality detections are considered. We also provide a bounding box annotated subset of 1000 mammograms from the RSNA Breast Screening Dataset (referred to as RSNA-BSD1K) to support further research in BCDM. We evaluate D-MASTER on multiple BCDM datasets acquired from diverse domains. Experimental results show a significant improvement of 9% and 13% in sensitivity at 0.3 FPI over state-of-the-art UDA techniques on publicly available benchmark INBreast and DDSM datasets respectively. We also report an improvement of 11% and 17% on In-house and RSNA-BSD1K datasets respectively. To promote reproducible research and address the scarcity of accessible resources in BCDM, we will publicly release source code, and pre-trained D-MASTER model, along with RSNA-BSD1K annotations. To get started, you can try one of the present examples.</p>" \ | |
| # + "<p style='text-align: center; font-size: 14px; margin: 5px; font-weight: 300;'> [Note: Inference on CPU may take up to 2 minutes. On a GPU, inference time is approximately 1s.]</p>" | |
| # + "<p style='text-align: center; font-size: 14px; margin: 5px; font-weight: 300;'> Demo coming soon. Stay tuned!</p>" | |
| # # Use gr.Markdown or gr.HTML to render the description | |
| # # gr.HTML(description) | |
| # gr.Markdown(description) | |
| with gr.Blocks() as demo: | |
| with gr.Column(): | |
| title = "<h1 style='margin-bottom: -10px; text-align: center'>D-MASTER: Mask Annealed Transformer for Unsupervised Domain Adaptation in Breast Cancer Detection from Mammograms</h1>" | |
| gr.HTML(title) # Corrected to use gr.HTML directly with title | |
| description = """ | |
| <p style='font-size: 14px; margin: 5px; font-weight: 300; text-align: center'> | |
| <a href='' style='text-decoration:none' target='_blank'>Tajamul Ashraff<sup>*</sup></a>, | |
| <a href='' style='text-decoration:none' target='_blank'>Chetan Arora<sup>*</sup></a> | |
| </p> | |
| <p style='font-size: 16px; margin: 5px; font-weight: 600; text-align: center'> | |
| <a href='' target='_blank'>Publication</a> | | |
| <a href='' target='_blank'>Website</a> | | |
| <a href='' target='_blank'>Github Repo</a> | |
| </p> | |
| <p style='text-align: center; margin: 5px; font-size: 14px; font-weight: 300;'> | |
| We focus on the problem of Unsupervised Domain Adaptation (UDA) for breast cancer detection from mammograms (BCDM) problem. Recent advancements have shown that masked image modeling serves as a robust pretext task for UDA. However, when applied to cross-domain BCDM, these techniques struggle with breast abnormalities such as masses, asymmetries, and micro-calcifications, in part due to the typically much smaller size of region of interest in comparison to natural images. This often results in more false positives per image (FPI) and significant noise in pseudo-labels typically used to bootstrap such techniques. Recognizing these challenges, we introduce a transformer-based Domain-invariant Mask Annealed Student Teacher autoencoder (D-MASTER) framework. D-MASTER adaptively masks and reconstructs multi-scale feature maps, enhancing the model’s ability to capture reliable target domain features. D-MASTER also includes adaptive confidence refinement to filter pseudo-labels, ensuring only high-quality detections are considered. We also provide a bounding box annotated subset of 1000 mammograms from the RSNA Breast Screening Dataset (referred to as RSNA-BSD1K) to support further research in BCDM. We evaluate D-MASTER on multiple BCDM datasets acquired from diverse domains. Experimental results show a significant improvement of 9% and 13% in sensitivity at 0.3 FPI over state-of-the-art UDA techniques on publicly available benchmark INBreast and DDSM datasets respectively. We also report an improvement of 11% and 17% on In-house and RSNA-BSD1K datasets respectively. To promote reproducible research and address the scarcity of accessible resources in BCDM, we will publicly release source code, and pre-trained D-MASTER model, along with RSNA-BSD1K annotations. To get started, you can try one of the present examples. | |
| </p> | |
| <p style='text-align: center; font-size: 14px; margin: 5px; font-weight: 300;'> | |
| [Note: Inference on CPU may take up to 2 minutes. On a GPU, inference time is approximately 1s.] | |
| </p> | |
| <p style='text-align: center; font-size: 14px; margin: 5px; font-weight: 300;'> | |
| Demo coming soon. Stay tuned! | |
| </p> | |
| """ | |
| gr.HTML(description) # Corrected to use gr.HTML directly with description | |
| demo.launch() | |
| # head_html = gr.HTML(''' | |
| # <h1> | |
| # Deep Learning for Detection of iso-dense, obscure masses in mammographically dense breasts | |
| # </h1> | |
| # <p style='text-align: center;'> | |
| # Give bilateral mammograms(both left and right sides), and let our model find the cancers! | |
| # </p> | |
| # <p style='text-align: center;'> | |
| # This is an official demo for our paper: | |
| # `Deep Learning for Detection of iso-dense, obscure masses in mammographically dense breasts`. | |
| # Check out the paper and code for details! | |
| # </p> | |
| # ''') | |
| # gr.Markdown( | |
| # """ | |
| # [](https://arxiv.org/abs/) [](https://colab.research.google.com/drive/) | |
| # """) | |
| # def generate_preds(img1, img2): | |
| # print(img1, img2) | |
| # print(img1, img2) | |
| # img_out1 = predict(img1, img2) | |
| # if img_out1.shape[1] < img_out1.shape[2]: | |
| # ratio = img_out1.shape[2] / 800 | |
| # else: | |
| # ratio = img_out1.shape[1] / 800 | |
| # img_out1 = cv2.resize(img_out1, (0,0), fx=1 / ratio, fy=1 / ratio) | |
| # img_out2 = predict(img2, img1, baseIsLeft = False) | |
| # if img_out2.shape[1] < img_out2.shape[2]: | |
| # ratio = img_out2.shape[2] / 800 | |
| # else: | |
| # ratio = img_out2.shape[1] / 800 | |
| # img_out2 = cv2.resize(img_out2, (0,0), fx= 1 / ratio, fy= 1 / ratio) | |
| # cv2.imwrite('img_out1.jpg', img_out1) | |
| # cv2.imwrite('img_out2.jpg', img_out2) | |
| # return 'img_out1.jpg', 'img_out2.jpg' | |
| # with gr.Column(): | |
| # with gr.Row(variant = 'panel'): | |
| # with gr.Column(variant = 'panel'): | |
| # img1 = gr.Image(type="filepath", label="Left Image" ) | |
| # img2 = gr.Image(type="filepath", label="Right Image") | |
| # # with gr.Row(): | |
| # # sub_btn = gr.Button("Predict!", variant="primary") | |
| # with gr.Column(variant = 'panel'): | |
| # # img_out1 = gr.inputs.Image(type="file", label="Output Left Image") | |
| # # img_out2 = gr.inputs.Image(type="file", label="Output for Right Image") | |
| # img_out1 = gr.Image(type="filepath", label="Output for Left Image", shape = None) | |
| # img_out1.style(height=250 * 2) | |
| # with gr.Column(variant = 'panel'): | |
| # img_out2 = gr.Image(type="filepath", label="Output for Right Image", shape = None) | |
| # img_out2.style(height=250 * 2) | |
| # with gr.Row(): | |
| # sub_btn = gr.Button("Predict!", variant="primary") | |
| # gr.Examples([[f'sample_images/img{idx}_l.jpg', f'sample_images/img{idx}_r.jpg'] for idx in range(1,6)], inputs = [img1, img2]) | |
| # sub_btn.click(fn = lambda x,y: generate_preds(x,y), inputs = [img1, img2], outputs = [img_out1, img_out2]) | |
| if __name__ == '__main__': | |
| demo.launch(show_api=False) |