[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-nyukat--breast_cancer_classifier":3,"tool-nyukat--breast_cancer_classifier":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",156804,2,"2026-04-15T11:34:33",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":72,"owner_avatar_url":73,"owner_bio":74,"owner_company":75,"owner_location":75,"owner_email":75,"owner_twitter":75,"owner_website":76,"owner_url":77,"languages":78,"stars":91,"forks":92,"last_commit_at":93,"license":94,"difficulty_score":95,"env_os":96,"env_gpu":97,"env_ram":96,"env_deps":98,"category_tags":111,"github_topics":112,"view_count":32,"oss_zip_url":75,"oss_zip_packed_at":75,"status":17,"created_at":123,"updated_at":124,"faqs":125,"releases":158},7833,"nyukat\u002Fbreast_cancer_classifier","breast_cancer_classifier","Deep Neural Networks Improve Radiologists' Performance in Breast Cancer Screening","breast_cancer_classifier 是一个基于深度神经网络的开源项目，旨在辅助放射科医生提升乳腺癌筛查的准确率。该工具通过处理标准的乳腺 X 光摄影图像（包含左右两侧的 CC 和 MLO 四种视图），自动分析并输出每侧乳房患有良性或恶性病变的概率预测。它有效解决了传统人工阅片可能存在的漏诊或误诊问题，为医生提供客观的量化参考，从而优化诊断决策。\n\n该项目主要适合医疗 AI 研究人员、深度学习开发者以及相关领域的学者使用。需要注意的是，根据官方声明，此模型版本发布于 2019 年，其精度已落后于团队后续研发的新模型，且明确未在任何临床场景中实际部署，因此仅适用于学术研究、算法复现或教学演示，不可直接用于临床诊断。\n\n在技术亮点方面，breast_cancer_classifier 提供了两种预训练模式：一种是仅输入图像的“纯图像模型”，另一种是结合图像与热力图输入的“图像加热力图模型”，后者能更精细地定位可疑区域。项目基于 PyTorch 框架构建，同时也提供了 TensorFlow 版本的实现代码，并附带了示例数据和完整的运行脚本，方便用户快速上手实验与二次开发。","# DISCLAIMER: this model is not used clinically at NYU Langone Health. As it was created in 2019, its accuracy is far behind the strongest model we trained since then. If you are interested in discussing our recent models in any capacity, please email [Krzysztof J. Geras](mailto:krzysztof.geras@nyulangone.org).\n\n# Deep Neural Networks Improve Radiologists' Performance in Breast Cancer Screening\n\n## Introduction\nThis is an implementation of the model used for breast cancer classification as described in our paper [Deep Neural Networks Improve Radiologists' Performance in Breast Cancer Screening](https:\u002F\u002Fieeexplore.ieee.org\u002Fdocument\u002F8861376). The implementation allows users to get breast cancer predictions by applying one of our pretrained models: a model which takes images as input (*image-only*) and a model which takes images and heatmaps as input (*image-and-heatmaps*). \n\n* Input images: 2 CC view mammography images of size 2677x1942 and 2 MLO view mammography images of size 2974x1748. Each image is saved as 16-bit png file and gets standardized separately before being fed to the models.\n* Input heatmaps: output of the patch classifier constructed to be the same size as its corresponding mammogram. Two heatmaps are generated for each mammogram, one for benign and one for malignant category. The value of each pixel in both of them is between 0 and 1.\n* Output: 2 predictions for each breast, probability of benign and malignant findings: `left_benign`, `right_benign`, `left_malignant`, and `right_malignant`.\n\nBoth models act on screening mammography exams with four standard views (L-CC, R-CC, L-MLO, R-MLO). As a part of this repository, we provide 4 sample exams (in `sample_data\u002Fimages` directory and exam list stored in `sample_data\u002Fexam_list_before_cropping.pkl`). Heatmap generation model and cancer classification models are implemented in PyTorch. \n\n**Update (2019\u002F10\u002F26)**: [Our paper](https:\u002F\u002Fieeexplore.ieee.org\u002Fdocument\u002F8861376) will be published in the IEEE Transactions on Medical Imaging!\n\n**Update (2019\u002F08\u002F26)**: We have added a [TensorFlow implementation](using_tensorflow.md) of our *image-wise* model.\n\n**Update (2019\u002F06\u002F21)**: We have included the *image-wise* model as described in the paper that generates predictions based on a single mammogram image. This model slightly under-performs the *view-wise* model used above, but can be used on single mammogram images as opposed to full exams.\n\n**Update (2019\u002F05\u002F15)**: Fixed a minor bug that caused the output DataFrame columns (`left_malignant`, `right_benign`) to be swapped. Note that this does not affect the operation of the model.\n\n## Prerequisites\n\n* Python (3.6)\n* PyTorch (0.4.1)\n* torchvision (0.2.0)\n* NumPy (1.14.3)\n* SciPy (1.0.0)\n* H5py (2.7.1)\n* imageio (2.4.1)\n* pandas (0.22.0)\n* tqdm (4.19.8)\n* opencv-python (3.4.2)\n\n## License\n\nThis repository is licensed under the terms of the GNU AGPLv3 license.\n\n## How to run the code\n\n### Exam-level\n\nHere we describe how to get predictions from *view-wise* model, which is our best-performing model. This model takes 4 images from each view as input and outputs predictions for each exam.\n\n```bash\nbash run.sh\n``` \nwill automatically run the entire pipeline and save the prediction results in csv. \n\nWe recommend running the code with a gpu (set by default). To run the code with cpu only, please change `DEVICE_TYPE` in `run.sh` to 'cpu'.  \n\nIf running the individual Python scripts, please include the path to this repository in your `PYTHONPATH` . \n\nYou should obtain the following outputs for the sample exams provided in the repository. \n\nPredictions using *image-only* model (found in `sample_output\u002Fimage_predictions.csv` by default):\n\n| index | left_benign | right_benign | left_malignant | right_malignant |\n| ----- | ----------- | ------------ | -------------- | --------------- |\n| 0     | 0.0580      | 0.0754       | 0.0091         | 0.0179          |\n| 1     | 0.0646      | 0.9536       | 0.0012         | 0.7258          |\n| 2     | 0.4388      | 0.3526       | 0.2325         | 0.1061          |\n| 3     | 0.3765      | 0.6483       | 0.0909         | 0.2579          |\n\n\nPredictions using *image-and-heatmaps* model (found in `sample_output\u002Fimageheatmap_predictions.csv` by default):\n\n| index | left_benign  | right_benign | left_malignant | right_malignant |\n| ----- | ------------ | ------------ | -------------- | --------------- |\n| 0     | 0.0612       | 0.0555       | 0.0099         | 0.0063          |\n| 1     | 0.0507       | 0.8025       | 0.0009         | 0.9000          |\n| 2     | 0.2877       | 0.2286       | 0.2524         | 0.0461          |\n| 3     | 0.4181       | 0.3172       | 0.3174         | 0.0485          |\n\n### Single Image\n\nHere we also upload *image-wise* model, which is different from and performs worse than the *view-wise* model described above. The csv output from *view-wise* model will be different from that of *image-wise* model in this section. Because this model has the benefit of creating predictions for each image separately, we make this model public to facilitate transfer learning.\n\nTo use the *image-wise* model, run a command such as the following:\n\n```bash\nbash run_single.sh \"sample_data\u002Fimages\u002F0_L_CC.png\" \"L-CC\"\n``` \n\nwhere the first argument is path to a mammogram image, and the second argument is the view corresponding to that image.\n\nYou should obtain the following output based on the above example command:\n\n```\nStage 1: Crop Mammograms\nStage 2: Extract Centers\nStage 3: Generate Heatmaps\nStage 4a: Run Classifier (Image)\n{\"benign\": 0.040191903710365295, \"malignant\": 0.008045293390750885}\nStage 4b: Run Classifier (Image+Heatmaps)\n{\"benign\": 0.052365876734256744, \"malignant\": 0.005510155577212572}\n```\n\n#### Image-level Notebook\n\nWe have included a [sample notebook](sample_notebook.ipynb) that contains code for running the classifiers with and without heatmaps (excludes preprocessing).\n\n## Data\n\nTo use one of the pretrained models, the input is required to consist of at least four images, at least one for each view (L-CC, L-MLO, R-CC, R-MLO). \n\nThe original 12-bit mammograms are saved as rescaled 16-bit images to preserve the granularity of the pixel intensities, while still being correctly displayed in image viewers.\n\n`sample_data\u002Fexam_list_before_cropping.pkl` contains a list of exam information before preprocessing. Each exam is represented as a dictionary with the following format:\n\n```python\n{\n  'horizontal_flip': 'NO',\n  'L-CC': ['0_L_CC'],\n  'R-CC': ['0_R_CC'],\n  'L-MLO': ['0_L_MLO'],\n  'R-MLO': ['0_R_MLO'],\n}\n```\n\nWe expect images from `L-CC` and `L-MLO` views to be facing right direction, and images from `R-CC` and `R-MLO` views are facing left direction. `horizontal_flip` indicates whether all images in the exam are flipped horizontally from expected. Values for `L-CC`, `R-CC`, `L-MLO`, and `R-MLO` are list of image filenames without extension and directory name. \n\nAdditional information for each image gets included as a dictionary. Such dictionary has all 4 views as keys, and the values are the additional information for the corresponding key. For example, `window_location`, which indicates the top, bottom, left and right edges of cropping window, is a dictionary that has 4 keys and has 4 lists as values which contain the corresponding information for the images. Additionally, `rightmost_pixels`, `bottommost_pixels`, `distance_from_starting_side` and `best_center` are added after preprocessing. \nDescription for these attributes can be found in the preprocessing section. \nThe following is an example of exam information after cropping and extracting optimal centers:\n\n```python\n{\n  'horizontal_flip': 'NO',\n  'L-CC': ['0_L_CC'],\n  'R-CC': ['0_R_CC'],\n  'L-MLO': ['0_L_MLO'],\n  'R-MLO': ['0_R_MLO'],\n  'window_location': {\n    'L-CC': [(353, 4009, 0, 2440)],\n    'R-CC': [(71, 3771, 952, 3328)],\n    'L-MLO': [(0, 3818, 0, 2607)],\n    'R-MLO': [(0, 3724, 848, 3328)]\n   },\n  'rightmost_points': {\n    'L-CC': [((1879, 1958), 2389)],\n    'R-CC': [((2207, 2287), 2326)],\n    'L-MLO': [((2493, 2548), 2556)],\n    'R-MLO': [((2492, 2523), 2430)]\n   },\n  'bottommost_points': {\n    'L-CC': [(3605, (100, 100))],\n    'R-CC': [(3649, (101, 106))],\n    'L-MLO': [(3767, (1456, 1524))],\n    'R-MLO': [(3673, (1164, 1184))]\n   },\n  'distance_from_starting_side': {\n    'L-CC': [0],\n    'R-CC': [0],\n    'L-MLO': [0],\n    'R-MLO': [0]\n   },\n  'best_center': {\n    'L-CC': [(1850, 1417)],\n    'R-CC': [(2173, 1354)],\n    'L-MLO': [(2279, 1681)],\n    'R-MLO': [(2185, 1555)]\n   }\n}\n```\n\nThe labels for the included exams are as follows:\n\n| index | left_benign | right_benign | left_malignant | right_malignant |\n| ----- | ----------- | ------------ | -------------- | --------------- |\n| 0     | 0           | 0            | 0              | 0               |\n| 1     | 0           | 0            | 0              | 1               |\n| 2     | 1           | 0            | 0              | 0               |\n| 3     | 1           | 1            | 1              | 1               |\n\n\n## Pipeline\n\nThe pipeline consists of four stages.\n\n1. Crop mammograms\n2. Calculate optimal centers\n3. Generate Heatmaps\n4. Run classifiers\n\nThe following variables defined in `run.sh` can be modified as needed:\n* `NUM_PROCESSES`: The number of processes to be used in preprocessing (`src\u002Fcropping\u002Fcrop_mammogram.py` and `src\u002Foptimal_centers\u002Fget_optimal_centers.py`). Default: 10.\n* `DEVICE_TYPE`: Device type to use in heatmap generation and classifiers, either 'cpu' or 'gpu'. Default: 'gpu'\n* `NUM_EPOCHS`: The number of epochs to be averaged in the output of the classifiers. Default: 10.\n* `HEATMAP_BATCH_SIZE`: The batch size to use in heatmap generation. Default: 100.\n* `GPU_NUMBER`: Specify which one of the GPUs to use when multiple GPUs are available. Default: 0. \n\n* `DATA_FOLDER`: The directory where the mammogram is stored.\n* `INITIAL_EXAM_LIST_PATH`: The path where the initial exam list without any metadata is stored.\n* `PATCH_MODEL_PATH`: The path where the saved weights for the patch classifier is saved.\n* `IMAGE_MODEL_PATH`: The path where the saved weights for the *image-only* model is saved.\n* `IMAGEHEATMAPS_MODEL_PATH`: The path where the saved weights for the *image-and-heatmaps* model is saved.\n\n* `CROPPED_IMAGE_PATH`: The directory to save cropped mammograms.\n* `CROPPED_EXAM_LIST_PATH`: The path to save the new exam list with cropping metadata.\n* `EXAM_LIST_PATH`: The path to save the new exam list with best center metadata.\n* `HEATMAPS_PATH`: The directory to save heatmaps.\n* `IMAGE_PREDICTIONS_PATH`: The path to save predictions of *image-only* model.\n* `IMAGEHEATMAPS_PREDICTIONS_PATH`: The path to save predictions of *image-and-heatmaps* model.\n\n\n### Preprocessing\n\nRun the following commands to crop mammograms and calculate information about augmentation windows.\n\n#### Crop mammograms\n```bash\npython3 src\u002Fcropping\u002Fcrop_mammogram.py \\\n    --input-data-folder $DATA_FOLDER \\\n    --output-data-folder $CROPPED_IMAGE_PATH \\\n    --exam-list-path $INITIAL_EXAM_LIST_PATH  \\\n    --cropped-exam-list-path $CROPPED_EXAM_LIST_PATH  \\\n    --num-processes $NUM_PROCESSES\n```\n`src\u002Fimport_data\u002Fcrop_mammogram.py` crops the mammogram around the breast and discards the background in order to improve image loading time and time to run segmentation algorithm and saves each cropped image to `$PATH_TO_SAVE_CROPPED_IMAGES\u002Fshort_file_path.png` using h5py. In addition, it adds additional information for each image and creates a new image list to `$CROPPED_IMAGE_LIST_PATH` while discarding images which it fails to crop. Optional --verbose argument prints out information about each image. The additional information includes the following:\n- `window_location`: location of cropping window w.r.t. original dicom image so that segmentation map can be cropped in the same way for training.\n- `rightmost_points`: rightmost nonzero pixels after correctly being flipped.\n- `bottommost_points`: bottommost nonzero pixels after correctly being flipped.\n- `distance_from_starting_side`: records if zero-value gap between the edge of the image and the breast is found in the side where the breast starts to appear and thus should have been no gap. Depending on the dataset, this value can be used to determine wrong value of `horizontal_flip`.\n\n\n#### Calculate optimal centers\n```bash\npython3 src\u002Foptimal_centers\u002Fget_optimal_centers.py \\\n    --cropped-exam-list-path $CROPPED_EXAM_LIST_PATH \\\n    --data-prefix $CROPPED_IMAGE_PATH \\\n    --output-exam-list-path $EXAM_LIST_PATH \\\n    --num-processes $NUM_PROCESSES\n```\n`src\u002Foptimal_centers\u002Fget_optimal_centers.py` outputs new exam list with additional metadata to `$EXAM_LIST_PATH`. The additional information includes the following:\n- `best_center`: optimal center point of the window for each image. The augmentation windows drawn with `best_center` as exact center point could go outside the boundary of the image. This usually happens when the cropped image is smaller than the window size. In this case, we pad the image and shift the window to be inside the padded image in augmentation. Refer to [the data report](https:\u002F\u002Fcs.nyu.edu\u002F~kgeras\u002Freports\u002Fdatav1.0.pdf) for more details.\n\n\n### Heatmap Generation\n```bash\npython3 src\u002Fheatmaps\u002Frun_producer.py \\\n    --model-path $PATCH_MODEL_PATH \\\n    --data-path $EXAM_LIST_PATH \\\n    --image-path $CROPPED_IMAGE_PATH \\\n    --batch-size $HEATMAP_BATCH_SIZE \\\n    --output-heatmap-path $HEATMAPS_PATH \\\n    --device-type $DEVICE_TYPE \\\n    --gpu-number $GPU_NUMBER\n```\n\n`src\u002Fheatmaps\u002Frun_producer.py` generates heatmaps by combining predictions for patches of images and saves them as hdf5 format in `$HEATMAPS_PATH` using `$DEVICE_TYPE` device. `$DEVICE_TYPE` can either be 'gpu' or 'cpu'. `$HEATMAP_BATCH_SIZE` should be adjusted depending on available memory size.  An optional argument `--gpu-number`  can be used to specify which GPU to use.\n\n### Running the models\n\n`src\u002Fmodeling\u002Frun_model.py` can provide predictions using cropped images either with or without heatmaps. When using heatmaps, please use the`--use-heatmaps` flag and provide appropriate the `--model-path` and `--heatmaps-path` arguments. Depending on the available memory, the optional argument `--batch-size` can be provided. Another optional argument `--gpu-number` can be used to specify which GPU to use.\n\n#### Run image only model\n```bash\npython3 src\u002Fmodeling\u002Frun_model.py \\\n    --model-path $IMAGE_MODEL_PATH \\\n    --data-path $EXAM_LIST_PATH \\\n    --image-path $CROPPED_IMAGE_PATH \\\n    --output-path $IMAGE_PREDICTIONS_PATH \\\n    --use-augmentation \\\n    --num-epochs $NUM_EPOCHS \\\n    --device-type $DEVICE_TYPE \\\n    --gpu-number $GPU_NUMBER\n```\n\nThis command makes predictions only using images for `$NUM_EPOCHS` epochs with random augmentation and outputs averaged predictions per exam to `$IMAGE_PREDICTIONS_PATH`. \n\n#### Run image+heatmaps model \n```bash\npython3 src\u002Fmodeling\u002Frun_model.py \\\n    --model-path $IMAGEHEATMAPS_MODEL_PATH \\\n    --data-path $EXAM_LIST_PATH \\\n    --image-path $CROPPED_IMAGE_PATH \\\n    --output-path $IMAGEHEATMAPS_PREDICTIONS_PATH \\\n    --use-heatmaps \\\n    --heatmaps-path $HEATMAPS_PATH \\\n    --use-augmentation \\\n    --num-epochs $NUM_EPOCHS \\\n    --device-type $DEVICE_TYPE \\\n    --gpu-number $GPU_NUMBER\n```\n\nThis command makes predictions using images and heatmaps for `$NUM_EPOCHS` epochs with random augmentation and outputs averaged predictions per exam to `$IMAGEHEATMAPS_PREDICTIONS_PATH`. \n\n## Getting image from dicom files and saving as 16-bit png files\n\nDicom files can be converted into png files with the following function, which then can be used by the code in our repository (pypng 0.0.19 and pydicom 1.2.2 libraries are required). \n\n```python3\nimport png\nimport pydicom\n\ndef save_dicom_image_as_png(dicom_filename, png_filename, bitdepth=12):\n    \"\"\"\n    Save 12-bit mammogram from dicom as rescaled 16-bit png file.\n    :param dicom_filename: path to input dicom file.\n    :param png_filename: path to output png file.\n    :param bitdepth: bit depth of the input image. Set it to 12 for 12-bit mammograms.\n    \"\"\"\n    image = pydicom.read_file(dicom_filename).pixel_array\n    with open(png_filename, 'wb') as f:\n        writer = png.Writer(height=image.shape[0], width=image.shape[1], bitdepth=bitdepth, greyscale=True)\n        writer.write(f, image.tolist())\n```\n\n## Reference\n\nIf you found this code useful, please cite our paper:\n\n**Deep Neural Networks Improve Radiologists' Performance in Breast Cancer Screening**\\\nNan Wu, Jason Phang, Jungkyu Park, Yiqiu Shen, Zhe Huang, Masha Zorin, Stanisław Jastrzębski, Thibault Févry, Joe Katsnelson, Eric Kim, Stacey Wolfson, Ujas Parikh, Sushma Gaddam, Leng Leng Young Lin, Kara Ho, Joshua D. Weinstein, Beatriu Reig, Yiming Gao, Hildegard Toth, Kristine Pysarenko, Alana Lewin, Jiyon Lee, Krystal Airola, Eralda Mema, Stephanie Chung, Esther Hwang, Naziya Samreen, S. Gene Kim, Laura Heacock, Linda Moy, Kyunghyun Cho, Krzysztof J. Geras\\\nIEEE Transactions on Medical Imaging\\\n2019\n\n    @article{wu2019breastcancer, \n        title = {Deep Neural Networks Improve Radiologists' Performance in Breast Cancer Screening},\n        author = {Nan Wu and Jason Phang and Jungkyu Park and Yiqiu Shen and Zhe Huang and Masha Zorin and Stanis\\l{}aw Jastrz\\k{e}bski and Thibault F\\'{e}vry and Joe Katsnelson and Eric Kim and Stacey Wolfson and Ujas Parikh and Sushma Gaddam and Leng Leng Young Lin and Kara Ho and Joshua D. Weinstein and Beatriu Reig and Yiming Gao and Hildegard Toth and Kristine Pysarenko and Alana Lewin and Jiyon Lee and Krystal Airola and Eralda Mema and Stephanie Chung and Esther Hwang and Naziya Samreen and S. Gene Kim and Laura Heacock and Linda Moy and Kyunghyun Cho and Krzysztof J. Geras}, \n        journal = {IEEE Transactions on Medical Imaging},\n        year = {2019}\n    }\n","# 免责声明：该模型目前未在纽约大学朗格尼健康中心用于临床实践。由于它是2019年开发的，其准确率远低于我们此后训练出的最先进模型。如果您有意讨论我们近期的任何模型，请发送邮件至 [Krzysztof J. Geras](mailto:krzysztof.geras@nyulangone.org)。\n\n# 深度神经网络提升放射科医生乳腺癌筛查表现\n\n## 引言\n这是我们在论文《深度神经网络提升放射科医生乳腺癌筛查表现》（IEEE Transactions on Medical Imaging, 2019）中描述的乳腺癌分类模型的实现。该实现允许用户通过应用我们预训练的两种模型来获取乳腺癌预测结果：一种仅以图像为输入的模型（“仅图像”模型），另一种同时接受图像和热图作为输入的模型（“图像与热图”模型）。\n\n* 输入图像：2张CC位乳腺X线摄影图像，尺寸为2677×1942；2张MLO位乳腺X线摄影图像，尺寸为2974×1748。每张图像保存为16位PNG文件，并在输入模型前分别进行标准化处理。\n* 输入热图：由补丁分类器生成，其大小与对应的乳腺X线片相同。每张乳腺X线片会生成两张热图，分别对应良性与恶性类别。两张热图中每个像素的值均介于0到1之间。\n* 输出：每侧乳房的两项预测结果，即良性与恶性的概率：`left_benign`、`right_benign`、`left_malignant` 和 `right_malignant`。\n\n两种模型均针对包含四个标准视图（左CC、右CC、左MLO、右MLO）的筛查性乳腺X线检查进行处理。作为本仓库的一部分，我们提供了4个示例检查（位于 `sample_data\u002Fimages` 目录中，检查列表存储在 `sample_data\u002Fexam_list_before_cropping.pkl` 文件中）。热图生成模型和癌症分类模型均采用PyTorch实现。\n\n**更新（2019年10月26日）**：我们的论文（IEEE Transactions on Medical Imaging, 2019）即将发表！\n\n**更新（2019年8月26日）**：我们新增了基于TensorFlow的 *逐图像* 模型实现（参见 `using_tensorflow.md`）。\n\n**更新（2019年6月21日）**：我们加入了论文中描述的 *逐图像* 模型，该模型基于单张乳腺X线片生成预测结果。虽然该模型的性能略逊于上述 *逐视图* 模型，但它可以应用于单张乳腺X线片，而无需完整的检查数据。\n\n**更新（2019年5月15日）**：修复了一个小错误，该错误会导致输出DataFrame中的列（`left_malignant` 和 `right_benign`）顺序颠倒。请注意，此问题并不影响模型的正常运行。\n\n## 系统要求\n\n* Python (3.6)\n* PyTorch (0.4.1)\n* torchvision (0.2.0)\n* NumPy (1.14.3)\n* SciPy (1.0.0)\n* H5py (2.7.1)\n* imageio (2.4.1)\n* pandas (0.22.0)\n* tqdm (4.19.8)\n* opencv-python (3.4.2)\n\n## 许可证\n本仓库遵循GNU AGPLv3许可证条款。\n\n## 如何运行代码\n\n### 检查级别\n\n以下介绍如何使用我们性能最佳的 *逐视图* 模型获取预测结果。该模型以每个视图的4张图像作为输入，输出每份检查的预测结果。\n\n```bash\nbash run.sh\n```\n将自动运行整个流程，并将预测结果保存为CSV文件。\n\n建议使用GPU运行代码（默认设置）。若仅使用CPU运行，请将 `run.sh` 中的 `DEVICE_TYPE` 改为 'cpu'。\n\n如果单独运行Python脚本，请确保将本仓库路径添加到您的 `PYTHONPATH` 中。\n\n对于仓库中提供的示例检查，您应得到如下输出：\n\n使用 *仅图像* 模型的预测结果（默认保存于 `sample_output\u002Fimage_predictions.csv`）：\n\n| index | left_benign | right_benign | left_malignant | right_malignant |\n| ----- | ----------- | ------------ | -------------- | --------------- |\n| 0     | 0.0580      | 0.0754       | 0.0091         | 0.0179          |\n| 1     | 0.0646      | 0.9536       | 0.0012         | 0.7258          |\n| 2     | 0.4388      | 0.3526       | 0.2325         | 0.1061          |\n| 3     | 0.3765      | 0.6483       | 0.0909         | 0.2579          |\n\n使用 *图像与热图* 模型的预测结果（默认保存于 `sample_output\u002Fimageheatmap_predictions.csv`）：\n\n| index | left_benign  | right_benign | left_malignant | right_malignant |\n| ----- | ------------ | ------------ | -------------- | --------------- |\n| 0     | 0.0612       | 0.0555       | 0.0099         | 0.0063          |\n| 1     | 0.0507       | 0.8025       | 0.0009         | 0.9000          |\n| 2     | 0.2877       | 0.2286       | 0.2524         | 0.0461          |\n| 3     | 0.4181       | 0.3172       | 0.3174         | 0.0485          |\n\n### 单张图像\n\n在此我们还提供了 *逐图像* 模型，它与上述 *逐视图* 模型不同，且性能稍逊。本节中 *逐视图* 模型的CSV输出将不同于 *逐图像* 模型。由于该模型具有对每张图像单独生成预测结果的优势，我们将其公开，以方便迁移学习的应用。\n\n要使用 *逐图像* 模型，请运行类似以下的命令：\n\n```bash\nbash run_single.sh \"sample_data\u002Fimages\u002F0_L_CC.png\" \"L-CC\"\n```\n\n其中第一个参数是乳腺X线片的路径，第二个参数是该图像对应的视图。\n\n根据上述示例命令，您应获得如下输出：\n\n```\n阶段1：裁剪乳腺X线片\n阶段2：提取中心区域\n阶段3：生成热图\n阶段4a：运行分类器（仅图像）\n{\"benign\": 0.040191903710365295, \"malignant\": 0.008045293390750885}\n阶段4b：运行分类器（图像+热图）\n{\"benign\": 0.052365876734256744, \"malignant\": 0.005510155577212572}\n```\n\n#### 图像级别笔记本\n\n我们附带了一个[示例笔记本](sample_notebook.ipynb)，其中包含了运行带热图和不带热图的分类器的代码（不包括预处理步骤）。\n\n## 数据\n\n要使用其中一个预训练模型，输入必须包含至少四张图像，每种视图（左乳CC位、左乳MLO位、右乳CC位、右乳MLO位）各一张。\n\n原始的12位乳腺X线片以重新缩放后的16位图像形式保存，以便保留像素强度的精细度，同时仍能在图像查看器中正确显示。\n\n`sample_data\u002Fexam_list_before_cropping.pkl` 包含预处理前的检查信息列表。每个检查以字典形式表示，格式如下：\n\n```python\n{\n  'horizontal_flip': 'NO',\n  'L-CC': ['0_L_CC'],\n  'R-CC': ['0_R_CC'],\n  'L-MLO': ['0_L_MLO'],\n  'R-MLO': ['0_R_MLO'],\n}\n```\n\n我们期望来自 `L-CC` 和 `L-MLO` 视图的图像朝向右侧，而来自 `R-CC` 和 `R-MLO` 视图的图像则朝向左侧。`horizontal_flip` 表示该次检查中的所有图像是否相对于预期方向进行了水平翻转。`L-CC`、`R-CC`、`L-MLO` 和 `R-MLO` 的值是不含扩展名和目录名的图像文件名列表。\n\n每张图像的附加信息会以字典形式包含在内。该字典以四种视图为键，对应的值则是相应视图的附加信息。例如，`window_location` 用于指示裁剪窗口的上、下、左、右边界，它是一个包含四个键的字典，每个键对应一个列表，其中包含了相应图像的裁剪窗口信息。此外，在预处理之后，还添加了 `rightmost_pixels`、`bottommost_pixels`、`distance_from_starting_side` 和 `best_center` 等信息。\n这些属性的说明可在预处理部分找到。\n以下是裁剪并提取最佳中心点后的检查信息示例：\n\n```python\n{\n  'horizontal_flip': 'NO',\n  'L-CC': ['0_L_CC'],\n  'R-CC': ['0_R_CC'],\n  'L-MLO': ['0_L_MLO'],\n  'R-MLO': ['0_R_MLO'],\n  'window_location': {\n    'L-CC': [(353, 4009, 0, 2440)],\n    'R-CC': [(71, 3771, 952, 3328)],\n    'L-MLO': [(0, 3818, 0, 2607)],\n    'R-MLO': [(0, 3724, 848, 3328)]\n   },\n  'rightmost_points': {\n    'L-CC': [((1879, 1958), 2389)],\n    'R-CC': [((2207, 2287), 2326)],\n    'L-MLO': [((2493, 2548), 2556)],\n    'R-MLO': [((2492, 2523), 2430)]\n   },\n  'bottommost_points': {\n    'L-CC': [(3605, (100, 100))],\n    'R-CC': [(3649, (101, 106))],\n    'L-MLO': [(3767, (1456, 1524))],\n    'R-MLO': [(3673, (1164, 1184))]\n   },\n  'distance_from_starting_side': {\n    'L-CC': [0],\n    'R-CC': [0],\n    'L-MLO': [0],\n    'R-MLO': [0]\n   },\n  'best_center': {\n    'L-CC': [(1850, 1417)],\n    'R-CC': [(2173, 1354)],\n    'L-MLO': [(2279, 1681)],\n    'R-MLO': [(2185, 1555)]\n   }\n}\n```\n\n所包含检查的标签如下：\n\n| index | 左乳良性 | 右乳良性 | 左乳恶性 | 右乳恶性 |\n| ----- | ----------- | ------------ | -------------- | --------------- |\n| 0     | 0           | 0            | 0              | 0               |\n| 1     | 0           | 0            | 0              | 1               |\n| 2     | 1           | 0            | 0              | 0               |\n| 3     | 1           | 1            | 1              | 1               |\n\n## 流程\n\n该流程由四个阶段组成。\n\n1. 裁剪乳腺X线片\n2. 计算最佳中心点\n3. 生成热力图\n4. 运行分类器\n\n以下在 `run.sh` 中定义的变量可根据需要进行修改：\n* `NUM_PROCESSES`: 预处理过程中使用的进程数（`src\u002Fcropping\u002Fcrop_mammogram.py` 和 `src\u002Foptimal_centers\u002Fget_optimal_centers.py`）。默认值：10。\n* `DEVICE_TYPE`: 用于生成热力图和运行分类器的设备类型，可为 ‘cpu’ 或 ‘gpu’。默认值：‘gpu’。\n* `NUM_EPOCHS`: 分类器输出结果中取平均的轮次数。默认值：10。\n* `HEATMAP_BATCH_SIZE`: 生成热力图时使用的批次大小。默认值：100。\n* `GPU_NUMBER`: 当有多块GPU可用时，指定使用哪一块GPU。默认值：0。\n\n* `DATA_FOLDER`: 存放乳腺X线片的目录。\n* `INITIAL_EXAM_LIST_PATH`: 存放不含任何元数据的初始检查列表的路径。\n* `PATCH_MODEL_PATH`: 保存补丁分类器权重的路径。\n* `IMAGE_MODEL_PATH`: 保存仅基于图像的模型权重的路径。\n* `IMAGEHEATMAPS_MODEL_PATH`: 保存结合图像与热力图的模型权重的路径。\n\n* `CROPPED_IMAGE_PATH`: 保存裁剪后乳腺X线片的目录。\n* `CROPPED_EXAM_LIST_PATH`: 保存包含裁剪元数据的新检查列表的路径。\n* `EXAM_LIST_PATH`: 保存包含最佳中心点元数据的新检查列表的路径。\n* `HEATMAPS_PATH`: 保存热力图的目录。\n* `IMAGE_PREDICTIONS_PATH`: 保存仅基于图像的模型预测结果的路径。\n* `IMAGEHEATMAPS_PREDICTIONS_PATH`: 保存结合图像与热力图的模型预测结果的路径。\n\n### 预处理\n\n运行以下命令以裁剪乳腺X光片并计算增强窗口的相关信息。\n\n#### 裁剪乳腺X光片\n```bash\npython3 src\u002Fcropping\u002Fcrop_mammogram.py \\\n    --input-data-folder $DATA_FOLDER \\\n    --output-data-folder $CROPPED_IMAGE_PATH \\\n    --exam-list-path $INITIAL_EXAM_LIST_PATH  \\\n    --cropped-exam-list-path $CROPPED_EXAM_LIST_PATH  \\\n    --num-processes $NUM_PROCESSES\n```\n`src\u002Fimport_data\u002Fcrop_mammogram.py` 会围绕乳房区域裁剪乳腺X光片，并去除背景，以提高图像加载速度和分割算法的运行效率。裁剪后的每张图像将使用 h5py 保存到 `$PATH_TO_SAVE_CROPPED_IMAGES\u002Fshort_file_path.png`。此外，该脚本还会为每张图像添加额外信息，并创建一个新的图像列表保存到 `$CROPPED_IMAGE_LIST_PATH`，同时丢弃无法成功裁剪的图像。可选的 `--verbose` 参数会打印每张图像的相关信息。附加信息包括：\n- `window_location`: 裁剪窗口相对于原始 DICOM 图像的位置，以便在训练时能够以相同的方式裁剪分割图。\n- `rightmost_points`: 正确翻转后最右侧的非零像素位置。\n- `bottommost_points`: 正确翻转后最下方的非零像素位置。\n- `distance_from_starting_side`: 记录在乳房开始出现的一侧是否出现了零值间隙，而实际上此处不应存在间隙。根据数据集的不同，此值可用于判断 `horizontal_flip` 的取值是否正确。\n\n\n#### 计算最佳中心点\n```bash\npython3 src\u002Foptimal_centers\u002Fget_optimal_centers.py \\\n    --cropped-exam-list-path $CROPPED_EXAM_LIST_PATH \\\n    --data-prefix $CROPPED_IMAGE_PATH \\\n    --output-exam-list-path $EXAM_LIST_PATH \\\n    --num-processes $NUM_PROCESSES\n```\n`src\u002Foptimal_centers\u002Fget_optimal_centers.py` 会输出包含额外元数据的新检查列表到 `$EXAM_LIST_PATH`。附加信息包括：\n- `best_center`: 每张图像的最佳窗口中心点。以 `best_center` 作为精确中心绘制的增强窗口可能会超出图像边界。这种情况通常发生在裁剪后的图像尺寸小于窗口尺寸时。在这种情况下，我们会在增强过程中对图像进行填充，并将窗口移至填充后的图像内部。更多细节请参阅 [数据报告](https:\u002F\u002Fcs.nyu.edu\u002F~kgeras\u002Freports\u002Fdatav1.0.pdf)。\n\n\n### 热力图生成\n```bash\npython3 src\u002Fheatmaps\u002Frun_producer.py \\\n    --model-path $PATCH_MODEL_PATH \\\n    --data-path $EXAM_LIST_PATH \\\n    --image-path $CROPPED_IMAGE_PATH \\\n    --batch-size $HEATMAP_BATCH_SIZE \\\n    --output-heatmap-path $HEATMAPS_PATH \\\n    --device-type $DEVICE_TYPE \\\n    --gpu-number $GPU_NUMBER\n```\n\n`src\u002Fheatmaps\u002Frun_producer.py` 通过组合图像补丁的预测结果生成热力图，并使用 `$DEVICE_TYPE` 设备以 HDF5 格式保存到 `$HEATMAPS_PATH`。`$DEVICE_TYPE` 可以是 `'gpu'` 或 `'cpu'`。`$HEATMAP_BATCH_SIZE` 应根据可用内存大小进行调整。可选参数 `--gpu-number` 可用于指定使用的 GPU 编号。\n\n### 运行模型\n\n`src\u002Fmodeling\u002Frun_model.py` 可以使用裁剪后的图像，无论是否结合热力图，来提供预测结果。当使用热力图时，请使用 `--use-heatmaps` 标志，并提供相应的 `--model-path` 和 `--heatmaps-path` 参数。根据可用内存情况，还可以提供可选参数 `--batch-size`。另一个可选参数 `--gpu-number` 可用于指定使用的 GPU 编号。\n\n#### 仅使用图像的模型运行\n```bash\npython3 src\u002Fmodeling\u002Frun_model.py \\\n    --model-path $IMAGE_MODEL_PATH \\\n    --data-path $EXAM_LIST_PATH \\\n    --image-path $CROPPED_IMAGE_PATH \\\n    --output-path $IMAGE_PREDICTIONS_PATH \\\n    --use-augmentation \\\n    --num-epochs $NUM_EPOCHS \\\n    --device-type $DEVICE_TYPE \\\n    --gpu-number $GPU_NUMBER\n```\n\n此命令仅使用图像进行预测，执行 `$NUM_EPOCHS` 个周期的随机增强操作，并将每份检查的平均预测结果输出到 `$IMAGE_PREDICTIONS_PATH`。\n\n#### 使用图像和热力图的模型运行\n```bash\npython3 src\u002Fmodeling\u002Frun_model.py \\\n    --model-path $IMAGEHEATMAPS_MODEL_PATH \\\n    --data-path $EXAM_LIST_PATH \\\n    --image-path $CROPPED_IMAGE_PATH \\\n    --output-path $IMAGEHEATMAPS_PREDICTIONS_PATH \\\n    --use-heatmaps \\\n    --heatmaps-path $HEATMAPS_PATH \\\n    --use-augmentation \\\n    --num-epochs $NUM_EPOCHS \\\n    --device-type $DEVICE_TYPE \\\n    --gpu-number $GPU_NUMBER\n```\n\n此命令使用图像和热力图进行预测，执行 `$NUM_EPOCHS` 个周期的随机增强操作，并将每份检查的平均预测结果输出到 `$IMAGEHEATMAPS_PREDICTIONS_PATH`。\n\n## 从 DICOM 文件中提取图像并保存为 16 位 PNG 文件\n\n可以使用以下函数将 DICOM 文件转换为 PNG 文件，随后这些文件即可被本仓库中的代码所使用（需安装 pypng 0.0.19 和 pydicom 1.2.2 库）。\n\n```python3\nimport png\nimport pydicom\n\ndef save_dicom_image_as_png(dicom_filename, png_filename, bitdepth=12):\n    \"\"\"\n    将 12 位乳腺 X 光片从 DICOM 文件中保存为重新缩放后的 16 位 PNG 文件。\n    :param dicom_filename: 输入 DICOM 文件的路径。\n    :param png_filename: 输出 PNG 文件的路径。\n    :param bitdepth: 输入图像的位深度。对于 12 位乳腺 X 光片，设置为 12。\n    \"\"\"\n    image = pydicom.read_file(dicom_filename).pixel_array\n    with open(png_filename, 'wb') as f:\n        writer = png.Writer(height=image.shape[0], width=image.shape[1], bitdepth=bitdepth, greyscale=True)\n        writer.write(f, image.tolist())\n```\n\n## 参考文献\n\n如果您觉得这段代码有用，请引用我们的论文：\n\n**深度神经网络提升放射科医师乳腺癌筛查性能**  \n吴楠、杰森·庞、朴正奎、沈一秋、黄哲、玛莎·佐林、斯坦尼斯瓦夫·雅斯特任布斯基、蒂博·费夫里、乔·卡茨内尔森、埃里克·金、斯泰西·沃尔夫森、乌贾斯·帕里克、苏什玛·加达姆、玲玲·杨琳、卡拉·霍、乔舒亚·D·韦因斯坦、贝阿特丽乌·雷伊格、仰明高、希尔德加德·托斯、克里斯汀·皮萨连科、阿拉娜·刘温、李智媛、克里斯塔尔·艾罗拉、埃拉尔达·梅马、斯蒂芬妮·钟、埃丝特·黄、纳齐娅·萨姆林、S. 金、劳拉·希科克、琳达·莫伊、曹庆贤、克日什托夫·J·格拉斯  \nIEEE 医学成像汇刊  \n2019年\n\n    @article{wu2019breastcancer, \n        title = {Deep Neural Networks Improve Radiologists' Performance in Breast Cancer Screening},\n        author = {Nan Wu and Jason Phang and Jungkyu Park and Yiqiu Shen and Zhe Huang and Masha Zorin and Stanis\\l{}aw Jastrz\\k{e}bski and Thibault F\\'{e}vry and Joe Katsnelson and Eric Kim and Stacey Wolfson and Ujas Parikh and Sushma Gaddam and Leng Leng Young Lin and Kara Ho and Joshua D. Weinstein and Beatriu Reig and Yiming Gao and Hildegard Toth and Kristine Pysarenko and Alana Lewin and Jiyon Lee and Krystal Airola and Eralda Mema and Stephanie Chung and Esther Hwang and Naziya Samreen and S. Gene Kim and Laura Heacock and Linda Moy and Kyunghyun Cho and Krzysztof J. Geras}, \n        journal = {IEEE Transactions on Medical Imaging},\n        year = {2019}\n    }","# breast_cancer_classifier 快速上手指南\n\n**重要免责声明**：本模型仅供研究参考，**不可用于临床诊断**。该模型发布于 2019 年，其准确率已低于后续训练的更先进模型。如需讨论最新模型，请联系作者 Krzysztof J. Geras。\n\n本项目实现了基于深度神经网络的乳腺癌筛查分类模型，支持两种输入模式：\n1. **仅图像 (image-only)**：输入乳腺 X 光摄影图像。\n2. **图像 + 热力图 (image-and-heatmaps)**：输入图像及对应的良性\u002F恶性热力图。\n\n## 1. 环境准备\n\n### 系统要求\n- **操作系统**: Linux \u002F macOS (Windows 需自行配置兼容环境)\n- **Python 版本**: 3.6\n- **硬件建议**: 推荐使用 NVIDIA GPU 以加速推理（默认配置），也可使用 CPU。\n\n### 前置依赖\n请确保安装以下特定版本的 Python 库：\n- PyTorch 0.4.1\n- torchvision 0.2.0\n- NumPy 1.14.3\n- SciPy 1.0.0\n- h5py 2.7.1\n- imageio 2.4.1\n- pandas 0.22.0\n- tqdm 4.19.8\n- opencv-python 3.4.2\n\n> **国内加速提示**：建议使用清华或阿里镜像源安装依赖，以提升下载速度。\n\n## 2. 安装步骤\n\n### 第一步：克隆项目\n```bash\ngit clone \u003Crepository_url>\ncd breast_cancer_classifier\n```\n\n### 第二步：创建虚拟环境并安装依赖\n推荐使用 `conda` 或 `venv` 隔离环境。以下是使用 `pip` 配合国内镜像源的安装命令：\n\n```bash\npython3 -m venv venv\nsource venv\u002Fbin\u002Factivate  # Windows 用户请使用: venv\\Scripts\\activate\n\n# 使用清华镜像源安装指定版本的依赖\npip install -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple \\\n    torch==0.4.1 \\\n    torchvision==0.2.0 \\\n    numpy==1.14.3 \\\n    scipy==1.0.0 \\\n    h5py==2.7.1 \\\n    imageio==2.4.1 \\\n    pandas==0.22.0 \\\n    tqdm==4.19.8 \\\n    opencv-python==3.4.2\n```\n\n### 第三步：配置环境变量\n如果单独运行 Python 脚本，需将项目根目录添加到 `PYTHONPATH`：\n```bash\nexport PYTHONPATH=$(pwd):$PYTHONPATH\n```\n\n## 3. 基本使用\n\n本项目提供两种主要的使用场景：**完整检查级别预测**（推荐，性能最佳）和 **单张图像预测**。\n\n### 场景一：完整检查级别预测 (Exam-level)\n此模式使用表现最佳的 *view-wise* 模型，需要输入包含四个标准视角（L-CC, R-CC, L-MLO, R-MLO）的完整检查数据。\n\n1. **准备数据**：\n   确保你的数据目录结构符合 `sample_data` 中的格式，并准备好包含检查信息的 `.pkl` 文件。\n\n2. **运行预测**：\n   执行主脚本自动完成预处理、热力图生成及分类预测全流程。\n   ```bash\n   bash run.sh\n   ```\n   *注：默认使用 GPU。若仅使用 CPU，请编辑 `run.sh` 将 `DEVICE_TYPE` 改为 `'cpu'`。*\n\n3. **查看结果**：\n   预测结果将保存为 CSV 文件：\n   - 仅图像模型结果：`sample_output\u002Fimage_predictions.csv`\n   - 图像 + 热力图模型结果：`sample_output\u002Fimageheatmap_predictions.csv`\n   \n   输出包含每侧乳房的良性与恶性概率：`left_benign`, `right_benign`, `left_malignant`, `right_malignant`。\n\n### 场景二：单张图像预测 (Single Image)\n此模式使用 *image-wise* 模型，适用于单张乳腺 X 光片的快速测试或迁移学习，但性能略低于完整检查模型。\n\n运行以下命令（以示例数据为例）：\n```bash\nbash run_single.sh \"sample_data\u002Fimages\u002F0_L_CC.png\" \"L-CC\"\n```\n- 第一个参数：图像文件路径。\n- 第二个参数：对应的视角标识（如 \"L-CC\", \"R-MLO\" 等）。\n\n**预期输出示例**：\n```text\nStage 1: Crop Mammograms\nStage 2: Extract Centers\nStage 3: Generate Heatmaps\nStage 4a: Run Classifier (Image)\n{\"benign\": 0.040191903710365295, \"malignant\": 0.008045293390750885}\nStage 4b: Run Classifier (Image+Heatmaps)\n{\"benign\": 0.052365876734256744, \"malignant\": 0.005510155577212572}\n```\n\n### 进阶配置 (可选)\n如需调整并行进程数、批次大小或模型路径，可编辑 `run.sh` 中的以下变量：\n- `NUM_PROCESSES`: 预处理并行进程数 (默认 10)\n- `HEATMAP_BATCH_SIZE`: 热力图生成批次大小 (默认 100)\n- `DATA_FOLDER`: 原始影像存储目录\n- `IMAGE_MODEL_PATH` \u002F `IMAGEHEATMAPS_MODEL_PATH`: 预训练权重路径","某三甲医院放射科在引入 AI 辅助筛查系统时，利用 breast_cancer_classifier 对历史乳腺 X 光影像数据进行回溯性分析，以验证深度学习模型辅助医生诊断的可行性。\n\n### 没有 breast_cancer_classifier 时\n- 放射科医生需完全依赖肉眼逐帧判读四视角（CC\u002FMLO）高清影像，长时间工作易导致视觉疲劳，增加微小病灶漏诊风险。\n- 面对海量历史数据，人工复核耗时极长，难以快速量化评估不同年资医生的诊断一致性，缺乏客观的基准参考。\n- 仅凭经验判断良恶性概率，缺乏像素级的热图（Heatmap）可视化支持，难以向患者或初级医师直观解释可疑区域的具体依据。\n- 无法高效处理标准化的 16 位 PNG 影像数据，人工预处理流程繁琐且容易引入人为误差，影响后续科研数据的准确性。\n\n### 使用 breast_cancer_classifier 后\n- 模型自动输出左右乳房的良恶性概率预测（如 `left_malignant`），为医生提供“第二意见”，显著降低因疲劳导致的漏诊率。\n- 批量运行脚本即可快速完成全量数据的推理，生成包含详细概率值的 CSV 报告，帮助科室快速建立诊断性能评估基线。\n- 结合输入的热图数据，模型能高亮显示疑似恶性区域，让诊断依据从“直觉”转变为可视化的数据支撑，提升医患沟通效率。\n- 内置的标准化预处理流程自动适配不同视角的影像尺寸，确保输入数据的一致性，大幅缩短科研数据准备周期。\n\nbreast_cancer_classifier 通过提供客观的概率预测与可视化热图，将放射科医生从繁重的初筛工作中解放出来，使其能更专注于复杂病例的决策与患者关怀。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fnyukat_breast_cancer_classifier_0917b0d9.png","nyukat","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fnyukat_96e80a34.png","",null,"https:\u002F\u002Fcs.nyu.edu\u002F~kgeras\u002F","https:\u002F\u002Fgithub.com\u002Fnyukat",[79,83,87],{"name":80,"color":81,"percentage":82},"Jupyter Notebook","#DA5B0B",51.2,{"name":84,"color":85,"percentage":86},"Python","#3572A5",46.5,{"name":88,"color":89,"percentage":90},"Shell","#89e051",2.3,890,277,"2026-04-15T00:12:20","AGPL-3.0",4,"未说明","非必需（支持 CPU 模式），需修改配置将 DEVICE_TYPE 设为 'cpu'；若使用 GPU，需指定 GPU 编号，具体型号和显存未说明",{"notes":99,"python":100,"dependencies":101},"该模型基于 2019 年研究，不再用于临床。运行脚本默认使用 GPU，若仅使用 CPU 需手动修改 run.sh 中的 DEVICE_TYPE 参数。输入图像需为特定的 16 位 PNG 格式乳腺 X 光照片（CC 和 MLO 视图）。代码包含预处理步骤（裁剪、生成热力图），需确保输入数据符合规定的字典格式。许可证为 GNU AGPLv3。","3.6",[102,103,104,105,106,107,108,109,110],"PyTorch==0.4.1","torchvision==0.2.0","NumPy==1.14.3","SciPy==1.0.0","H5py==2.7.1","imageio==2.4.1","pandas==0.22.0","tqdm==4.19.8","opencv-python==3.4.2",[15,14],[113,114,115,116,117,118,119,120,121,122],"pytorch","breast-cancer","classification","pretrained-models","deep-learning","neural-network","breast-cancer-diagnosis","medical-imaging","medical-image-analysis","tensorflow","2026-03-27T02:49:30.150509","2026-04-16T02:09:03.669863",[126,131,136,141,145,150,154],{"id":127,"question_zh":128,"answer_zh":129,"source_url":130},35089,"如何查看原始图像上的热力图预测结果？","热力图的分辨率通常低于原始图像，因为分类器应用的步长（stride）远大于 1。生成的热力图是值在 0-1 之间的 numpy 数组。你可以使用 'scipy.misc.imsave' 将其保存为 PNG 文件。但在加载这些 PNG 文件作为后续模型输入时需小心，因为数值可能会被转换以适应典型的 PNG 图像比例（0-255）。","https:\u002F\u002Fgithub.com\u002Fnyukat\u002Fbreast_cancer_classifier\u002Fissues\u002F2",{"id":132,"question_zh":133,"answer_zh":134,"source_url":135},35090,"如何只预测单个病例（4 张乳腺 X 光照片）而不是默认的 16 张？","你需要创建一个新的检查列表文件（exam list file），其中仅包含你想要预测的单个病例数据。可以使用以下 Python 代码示例：\n\nimport src.utilities.pickling as pickling\nexam_list = pickling.unpickle_from_file('sample_data\u002Fexam_list_before_cropping.pkl')\ncustom_exam_list = [exam_list[0]]  # 选取第一个病例\npickling.pickle_to_file('custom_exam_list_before_cropping.pkl', custom_exam_list)\n\n这样生成的 'custom_exam_list_before_cropping.pkl' 文件即可用于单病例预测。","https:\u002F\u002Fgithub.com\u002Fnyukat\u002Fbreast_cancer_classifier\u002Fissues\u002F3",{"id":137,"question_zh":138,"answer_zh":139,"source_url":140},35091,"在使用自定义管道处理图像时，为什么会出现图像无法工作或结果异常的问题？","常见错误包括：\n1. 直接修改图像数组（如 `img[img\u003C150]=0`）可能错误地将乳房内部区域视为背景抹去，阈值设置需根据具体图像调整，且应在裁剪算法生成掩码时使用。\n2. `standard_normalize_single_image` 函数是原地修改（in-place）数组并不返回任何值。如果你写成 `img = standard_normalize_single_image(img)`，变量 `img` 会被赋值为 None。请确保不要改变该函数的原始行为，直接调用即可。\n3. 不要随意更改热力图生成参数（如 `stride_fixed` 和 `patch_size`），分类模型期望使用预定义参数生成的热力图。","https:\u002F\u002Fgithub.com\u002Fnyukat\u002Fbreast_cancer_classifier\u002Fissues\u002F42",{"id":142,"question_zh":143,"answer_zh":144,"source_url":140},35092,"在计算 AUC 指标时，是否需要根据模型的预测结果调整标注标签？","绝对不可以。计算 AUC（曲线下面积）时，必须使用真实的标注标签，不能根据模型结果进行修改。AUC 衡量的是模型在所有可能的阈值下区分恶性和非恶性病例的能力。之前讨论中提到的调整阈值是为了设定决策边界，这与 AUC 的计算无关。",{"id":146,"question_zh":147,"answer_zh":148,"source_url":149},35093,"将模型应用于其他数据集（如 DDSM）时，为什么预测结果总是良性（BENIGN）或概率极低？","这通常是因为不同数据集之间存在分布差异，或者预处理流程不一致。请确保：\n1. 严格遵循项目提供的预处理步骤（参考 dataset report）。\n2. 输入图像的尺寸不需要完全精确匹配样本，但预处理逻辑必须一致。\n3. 如果进行迁移学习，需要正确实现损失函数并能够执行反向传播（.backward()），建议参考官方更新的源代码或请求分享训练代码以了解损失计算方式。维护者曾提到已更新源代码，建议重新运行分类器测试。","https:\u002F\u002Fgithub.com\u002Fnyukat\u002Fbreast_cancer_classifier\u002Fissues\u002F9",{"id":151,"question_zh":152,"answer_zh":153,"source_url":135},35094,"在哪里可以找到更多可用于该代码的样本图像或公共数据集？","推荐使用公共数据集，例如 CBIS-DDSM 或 DDSM。这些数据集包含了标准的乳腺 X 光图像，适合用于测试和验证模型效果。",{"id":155,"question_zh":156,"answer_zh":157,"source_url":149},35095,"如何在自己的数据集上进行迁移学习，特别是关于损失函数的计算？","如果你在迁移学习中遇到无法使用 PyTorch 损失函数或无法对自定义交叉熵损失执行 .backward() 的问题，通常是因为预测结果和真实值被转换成了 numpy 数组，脱离了计算图。建议直接使用 PyTorch Tensor 进行计算，或者参考官方的训练代码来了解正确的损失计算和反向传播流程。维护者曾建议用户查看其如何计算损失，并在代码更新后重新尝试。",[]]