[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-mahmoodlab--CLAM":3,"tool-mahmoodlab--CLAM":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 真正成长为懂上",158594,2,"2026-04-16T23:34:05",[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":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":76,"owner_email":77,"owner_twitter":78,"owner_website":79,"owner_url":80,"languages":81,"stars":86,"forks":87,"last_commit_at":88,"license":89,"difficulty_score":90,"env_os":91,"env_gpu":92,"env_ram":93,"env_deps":94,"category_tags":105,"github_topics":106,"view_count":32,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":121,"updated_at":122,"faqs":123,"releases":152},8367,"mahmoodlab\u002FCLAM","CLAM","Open source tools for computational pathology - Nature BME","CLAM 是一款专为计算病理学设计的开源深度学习工具，旨在高效处理全切片图像（WSI）的分类任务。它主要解决了传统方法依赖繁琐的区域标注痛点：无需人工提取感兴趣区域或进行像素级标注，仅需使用整张切片的诊断标签，即可通过弱监督学习自动识别具有高诊断价值的子区域，实现精准分类与多亚型区分。\n\n该工具特别适合病理学研究人员、生物医学工程师及 AI 开发者使用，帮助他们从海量病理数据中挖掘价值，甚至能适配手机显微摄影图像的分析场景。CLAM 的核心技术亮点在于其“聚类约束注意力多实例学习”机制：利用注意力机制自动定位关键病灶区域，并结合实例级聚类优化特征空间，显著提升了模型的可解释性与数据效率。此外，CLAM 支持集成 UNI、CONCH 等前沿预训练编码器，并具备快速生成可视化热力图的功能，让复杂的模型决策过程一目了然。作为由 Mahmood 实验室研发并在《自然·生物医学工程》发表的成果，CLAM 为病理图像的智能化分析提供了一套高效、透明且易于部署的解决方案。","CLAM \u003Cimg src=\"clam-logo.png\" width=\"280px\" align=\"right\" \u002F>\n===========\nData Efficient and Weakly Supervised Computational Pathology on Whole Slide Images.\n*Nature Biomedical Engineering*\n\n[ArXiv](https:\u002F\u002Farxiv.org\u002Fabs\u002F2004.09666) | [Journal Link](https:\u002F\u002Fwww.nature.com\u002Farticles\u002Fs41551-020-00682-w) | [Interactive Demo](http:\u002F\u002Fclam.mahmoodlab.org) | [Cite](#reference) \n\n***TL;DR:** CLAM is a high-throughput and interpretable method for data efficient whole slide image (WSI) classification using slide-level labels without any ROI extraction or patch-level annotations, and is capable of handling multi-class subtyping problems. Tested on three different WSI datasets, trained models adapt to independent test cohorts of WSI resections and biopsies as well as smartphone microscopy images (photomicrographs).*\n\n[\u003Cimg src=\"ani.gif\" width=\"470px\" align=\"left\" \u002F>](http:\u002F\u002Fclam.mahmoodlab.org)\n## CLAM: A Deep-Learning-based Pipeline for Data Efficient and Weakly Supervised Whole-Slide-level Analysis \n[Pre-requisites](#pre-requisites) • [Installation](INSTALLATION.md) • [Segmentation and Patching](#wsi-segmentation-and-patching) • [Feature Extraction](#weakly-supervised-learning-using-slide-level-labels-with-clam) • [Weakly Supervised Training](#Training-Splits) • [Testing](#Testing-and-Evaluation-Script) • [Trained Models](#Trained-Model-Checkpoints) • [Heatmap Visualization](#Heatmap-Visualization) • [Examples](#examples) • [Pre-print](https:\u002F\u002Farxiv.org\u002Fabs\u002F2004.09666) • [Demo](http:\u002F\u002Fclam.mahmoodlab.org) • [Cite](#reference)\n\n***How does CLAM work?** Clustering-constrained Attention Multiple Instance Learning (CLAM) is a deep-learning-based weakly-supervised method that uses attention-based learning to automatically identify sub-regions of high diagnostic value in order to accurately classify the whole slide, while also utilizing instance-level clustering over the representative regions identified to constrain and refine the feature space.*\n\n© [Mahmood Lab](http:\u002F\u002Fwww.mahmoodlab.org) - This code is made available under the GPLv3 License and is available for non-commercial academic purposes. \n\n## Updates:\n* **04\u002F15\u002F2025**: Checkout our new repository [Trident](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FTRIDENT) for whole-slide image processing with support for 25+ foundation models, including [UNIv2](https:\u002F\u002Fhuggingface.co\u002FMahmoodLab\u002FUNI2-h), [CONCH](https:\u002F\u002Fhuggingface.co\u002FMahmoodLab\u002FCONCH), [TITAN](https:\u002F\u002Fhuggingface.co\u002FMahmoodLab\u002FTITAN), and many more!\n* **04\u002F06\u002F2024**: [UNI](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FUNI) and [CONCH](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FCONCH) are now available to select as pretrained encoders. See [Using CONCH \u002F UNI as Pretrained Encoders](#using-conch--uni-as-pretrained-encoders) for more details. Please make sure all dependencies are installed correctly by installing the latest **env.yml** file (see [Installation guide](INSTALLATION.md) for details), and using the corresponding **clam_latest** conda environment.\n* 03\u002F19\u002F2024: We are releasing [UNI](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FUNI) and [CONCH](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FCONCH), a pair of SOTA pretrained encoders that produce strong representations for histopathology images and enhance performance on various computational pathology workflows, including the MIL-based CLAM workflow. \n* 05\u002F24\u002F2021: Script for heatmap visualization now available via **create_heatmaps.py**, with the configuration template located in **heatmaps\u002Fconfigs**. See [Heatmap visualization for demo and instructions.](#Heatmap-Visualization)\n* 03\u002F01\u002F2021: New, fast patching\u002Ffeature extraction pipeline is now available. **TL;DR:** since CLAM only requires image features for training, it is not necessary to save the actual image patches, the new pipeline rids of this overhead and instead only saves the coordinates of image patches during \"patching\" and loads these regions on the fly from WSIs during feature extraction. This is significantly faster than the old pipeline and usually only takes 1-2s for \"patching\" and a couple minutes to featurize a WSI. To use the new pipeline, make sure you are calling **create_patches_fp.py** and **extract_features_fp.py** instead of the old **create_patches.py** and **extract_features.py** scripts.\n\n**Note**: while we hope that the newest update will require minimal changes to the user's workflow, if needed, you may reference the old version of the code base [here](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FCLAM\u002Ftree\u002Fdeprecated). Please report any issues in the public forum. \n\n**Warning**: the latest update will by default resize image patches to 224 x 224 before extracting features using the pretrained encoder. This change serves to make it more consistent with the evaluation protocol used in UNI, CONCH and other studies. If you wish to preserve the original size of the image patches generated during patching or use a different image size for feature extraction, you can do so by specifying `--target_patch_size` in **extract_features_fp.py**.\n\n**RE update 03\u002F01\u002F21**: note that the README has been updated to use the new, faster pipeline by default. If you still wish to use the old pipeline, refer to: [Guide for Old Pipeline](README_old.md). It saves tissue patches, which is signficantly slower and takes up a lot of storage space but can still be useful if you need to work with original image patches instead of feature embeddings.\n\n## Installation:\nPlease refer to our [Installation guide](INSTALLATION.md) for detailed instructions on how to get started.\n\n## WSI Segmentation and Patching \n\n\u003Cimg src=\"CLAM1.jpg\" width=\"1000px\" align=\"center\" \u002F>\nThe first step focuses on segmenting the tissue and excluding any holes. The segmentation of specific slides can be adjusted by tuning the individual parameters (e.g. dilated vessels appearing as holes may be important for certain sarcomas.) \nThe following example assumes that digitized whole slide image data in well known standard formats (.svs, .ndpi, .tiff etc.) are stored under a folder named DATA_DIRECTORY\n\n```bash\nDATA_DIRECTORY\u002F\n\t├── slide_1.svs\n\t├── slide_2.svs\n\t└── ...\n```\n\n### Basic, Fully Automated Run\n``` shell\npython create_patches_fp.py --source DATA_DIRECTORY --save_dir RESULTS_DIRECTORY --patch_size 256 --seg --patch --stitch \n```\n\nThe above command will segment every slide in DATA_DIRECTORY using default parameters, extract all patches within the segemnted tissue regions, create a stitched reconstruction for each slide using its extracted patches (optional) and generate the following folder structure at the specified RESULTS_DIRECTORY:\n\n```bash\nRESULTS_DIRECTORY\u002F\n\t├── masks\n    \t\t├── slide_1.png\n    \t\t├── slide_2.png\n    \t\t└── ...\n\t├── patches\n    \t\t├── slide_1.h5\n    \t\t├── slide_2.h5\n    \t\t└── ...\n\t├── stitches\n    \t\t├── slide_1.png\n    \t\t├── slide_2.png\n    \t\t└── ...\n\t└── process_list_autogen.csv\n```\n\nThe **masks** folder contains the segmentation results (one image per slide).\nThe **patches** folder contains arrays of extracted tissue patches from each slide (one .h5 file per slide, where each entry corresponds to the coordinates of the top-left corner of a patch)\nThe **stitches** folder contains downsampled visualizations of stitched tissue patches (one image per slide) (Optional, not used for downstream tasks)\nThe auto-generated csv file **process_list_autogen.csv** contains a list of all slides processed, along with their segmentation\u002Fpatching parameters used.\n\nAdditional flags that can be passed include:\n* `--custom_downsample`: factor for custom downscale (not recommended, ideally should first check if native downsamples exist)\n* `--patch_level`: which downsample pyramid level to extract patches from (default is 0, the highest available resolution)\n* `--no_auto_skip`: by default, the script will skip over files for which patched .h5 files already exist in the desination folder, this toggle can be used to override this behavior\n\nSome parameter templates are also availble and can be readily deployed as good choices for default parameters:\n* `bwh_biopsy.csv`: used for segmenting biopsy slides scanned at BWH (Scanned using Hamamatsu S210 and Aperio GT450) \n* `bwh_resection.csv`: used for segmenting resection slides scanned at BWH\n* `tcga.csv`: used for segmenting TCGA slides\n\nSimply pass the name of the template file to the --preset argument, for example, to use the biopsy template:\n``` shell\npython create_patches_fp.py --source DATA_DIRECTORY --save_dir RESULTS_DIRECTORY --patch_size 256 --preset bwh_biopsy.csv --seg --patch --stitch\n```\n### Custom Default Segmentation Parameters\nFor advanced usage, in addition to using the default, single set of parameters defined in the script **create_patches_fp.py**, the user can define custom templates of parameters depending on the dataset. These templates are expected to be stored under **presets**, and contain values for each of the parameters used during segmentation and patching. \n\nThe list of segmentation parameters is as follows:\n* `seg_level`: downsample level on which to segment the WSI (default: -1, which uses the downsample in the WSI closest to 64x downsample)\n* `sthresh`: segmentation threshold (positive integer, default: 8, using a higher threshold leads to less foreground and more background detection)\n* `mthresh`: median filter size (positive, odd integer, default: 7)\n* `use_otsu`: use otsu's method instead of simple binary thresholding (default: False) \n* `close`: additional morphological closing to apply following initial thresholding (positive integer or -1, default: 4)\n\nThe list of contour filtering parameters is as follows:\n* `a_t`: area filter threshold for tissue (positive integer, the minimum size of detected foreground contours to consider, relative to a reference patch size of 512 x 512 at level 0, e.g. a value 10 means only detected foreground contours of size greater than 10 512 x 512 sized patches at level 0 will be processed, default: 100)\n* `a_h`: area filter threshold for holes (positive integer, the minimum size of detected holes\u002Fcavities in foreground contours to avoid, once again relative to 512 x 512 sized patches at level 0, default: 16)\n* `max_n_holes`: maximum of holes to consider per detected foreground contours (positive integer, default: 10, higher maximum leads to more accurate patching but increases computational cost)\n\nThe list of segmentation visualization parameters is as follows:\n* `vis_level`: downsample level to visualize the segmentation results (default: -1, which uses the downsample in the WSI closest to 64x downsample)\n* `line_thickness`: line thickness to draw visualize the segmentation results (positive integer, in terms of number of pixels occupied by drawn line at level 0, default: 250)\n\nThe list of patching parameters is as follows:\n* `use_padding`: whether to pad the border of the slide (default: True)\n* `contour_fn`: contour checking function to decide whether a patch should be considered foreground or background (choices between 'four_pt' - checks if all four points in a small, grid around the center of the patch are inside the contour, 'center' - checks if the center of the patch is inside the contour, 'basic' - checks if the top-left corner of the patch is inside the contour, default: 'four_pt')\n\n\n### Two-Step Run (Mannually Adjust Parameters For Specific Slides)\nTo ensure that high quality segmentation and extraction of relevant tissue patches, user has the option of first performing segmentation (typically around 1s per slide), inspecting the segmentation results and tweaking the parameters for select slides if necessary and then extracting patches using the tweaked parameters. i.e., first run:\n\n``` shell\npython create_patches_fp.py --source DATA_DIRECTORY --save_dir RESULTS_DIRECTORY --patch_size 256 --seg  \n```\nThe above command will segment every slide in DATA_DIRECTORY using default parameters and generate the csv file, but will NOT patch just yet (**patches** and **stitches** folders will be empty)\n\nThe csv file can be tweaked for specific slides, and be passed to the script via the --process_list CSV_FILE_NAME such that the script will use the user-updated specifications. Before tweaking the segmentation parameters, the user should make a copy of the csv file and give it a new name (e.g. process_list_edited.csv) because otherwise this file with the default name is overwritten the next time the command is run. Then the user has the option to tweak the parameters for specific slides by changing their corresponding fields in the csv file. The **process** column stores a binary variable (0 or 1) for whether the script should process a specific slide. This allows the user to toggle on just the select few slides to quickly confirm whether the tweaked parameters produce satisfactory results. For example, to re-segment just slide_1.svs again using user-updated parameters, make the appropriate changes to its fields, update its **process** cell to 1, save the csv file, and pass its name to the same command as above:\n\n``` shell\npython create_patches_fp.py --source DATA_DIRECTORY --save_dir RESULTS_DIRECTORY --patch_size 256 --seg --process_list process_list_edited.csv\n```\n\nWhen satisfied with the segmentation results, the user should make the **process** cell for all slides that need to be processed to 1, save the csv file, and run patching with the saved csv file (just like in the fully-automated run use case, with the additional csv file argument):\n\n``` shell\npython create_patches_fp.py --source DATA_DIRECTORY --save_dir RESULTS_DIRECTORY --patch_size 256 --seg --process_list CSV_FILE_NAME --patch --stitch\n```\n## Weakly-Supervised Learning using Slide-Level Labels with CLAM\n\n\u003Cimg src=\"CLAM2.jpg\" width=\"1000px\" align=\"center\" \u002F>\n\n### Feature Extraction (GPU Example)\n```bash\nCUDA_VISIBLE_DEVICES=0 python extract_features_fp.py --data_h5_dir DIR_TO_COORDS --data_slide_dir DATA_DIRECTORY --csv_path CSV_FILE_NAME --feat_dir FEATURES_DIRECTORY --batch_size 512 --slide_ext .svs\n```\nThe above command expects the coordinates .h5 files to be stored under DIR_TO_COORDS and a batch size of 512 to extract 1024-dim features from each tissue patch for each slide and produce the following folder structure:\n```bash\nFEATURES_DIRECTORY\u002F\n    ├── h5_files\n            ├── slide_1.h5\n            ├── slide_2.h5\n            └── ...\n    └── pt_files\n            ├── slide_1.pt\n            ├── slide_2.pt\n            └── ...\n```\nwhere each .h5 file contains an array of extracted features along with their patch coordinates (note for faster training, a .pt file for each slide is also created for each slide, containing just the patch features). The csv file is expected to contain a list of slide filenames (without the filename extensions) to process (the easiest option is to take the csv file auto generated by the previous segmentation\u002Fpatching step, and delete the filename extensions)\n\n### Using CONCH \u002F UNI as Pretrained Encoders\nIf using UNI or CONCH, first refer to their respective HF page below to request and download the model weights (pytorch_model.bin). \n\nUNI: https:\u002F\u002Fhuggingface.co\u002FMahmoodLab\u002FUNI\n\nCONCH: https:\u002F\u002Fhuggingface.co\u002FMahmoodLab\u002FCONCH\n\nAfter successfully downloading the model checkpoints, you need to set the `CONCH_CKPT_PATH` and `UNI_CKPT_PATH` environment variable to the path of the pretrained encoder checkpoints, before running the feature extraction script. For example, if you have downloaded the pretrained UNI and CONCH checkpoints and placed them in the **checkpoints\u002Fconch** and **checkpoints\u002Funi** folders respectively, you can set the environment variables as follows:\n```bash\nexport CONCH_CKPT_PATH=checkpoints\u002Fconch\u002Fpytorch_model.bin\nexport UNI_CKPT_PATH=checkpoints\u002Funi\u002Fpytorch_model.bin\n```\nWhen running the **extract_features_fp.py** also set `--model_name` to either 'uni_v1' or 'conch_v1' to use the respective encoder.\n\nNote that these encoder models (especially UNI, which uses ViT-L) are more computationally expensive and require more GPU memory than the default ResNet50 encoder, so expect longer runtimes and reduced batch sizes accordingly if you run out of GPU memory. UNI will produce 1024-dim features, while CONCH will produce 512-dim features.\n\n### Datasets\nThe data used for training and testing are expected to be organized as follows:\n```bash\nDATA_ROOT_DIR\u002F\n    ├──DATASET_1_DATA_DIR\u002F\n        ├── h5_files\n                ├── slide_1.h5\n                ├── slide_2.h5\n                └── ...\n        └── pt_files\n                ├── slide_1.pt\n                ├── slide_2.pt\n                └── ...\n    ├──DATASET_2_DATA_DIR\u002F\n        ├── h5_files\n                ├── slide_a.h5\n                ├── slide_b.h5\n                └── ...\n        └── pt_files\n                ├── slide_a.pt\n                ├── slide_b.pt\n                └── ...\n    └──DATASET_3_DATA_DIR\u002F\n        ├── h5_files\n                ├── slide_i.h5\n                ├── slide_ii.h5\n                └── ...\n        └── pt_files\n                ├── slide_i.pt\n                ├── slide_ii.pt\n                └── ...\n    └── ...\n```\nNamely, each dataset is expected to be a subfolder (e.g. DATASET_1_DATA_DIR) under DATA_ROOT_DIR, and the features extracted for each slide in the dataset is stored as a .pt file sitting under the **pt_files** folder of this subfolder.\nDatasets are also expected to be prepared in a csv format containing at least 3 columns: **case_id**, **slide_id**, and 1 or more labels columns for the slide-level labels. Each **case_id** is a unique identifier for a patient, while the **slide_id** is a unique identifier for a slide that correspond to the name of an extracted feature .pt file. This is necessary because often one patient has multiple slides, which might also have different labels. When train\u002Fval\u002Ftest splits are created, we also make sure that slides from the same patient do not go to different splits. The slide ids should be consistent with what was used during the feature extraction step. We provide 2 dummy examples of such dataset csv files in the **dataset_csv** folder: one for binary tumor vs. normal classification (task 1) and one for multi-class tumor_subtyping (task 2). \n\nDataset objects used for actual training\u002Fvalidation\u002Ftesting can be constructed using the **Generic_MIL_Dataset** Class (defined in **datasets\u002Fdataset_generic.py**). Examples of such dataset objects passed to the models can be found in both **main.py** and **eval.py**. \n\nFor training, look under main.py:\n```python \nif args.task == 'task_1_tumor_vs_normal':\n    args.n_classes=2\n    dataset = Generic_MIL_Dataset(csv_path = 'dataset_csv\u002Ftumor_vs_normal_dummy_clean.csv',\n                            data_dir= os.path.join(args.data_root_dir, 'tumor_vs_normal_feat_resnet'),\n                            shuffle = False, \n                            seed = args.seed, \n                            print_info = True,\n                            label_dict = {'normal_tissue':0, 'tumor_tissue':1},\n                            label_col = 'label',\n                            ignore=[])\n```\nThe user would need to pass:\n* csv_path: the path to the dataset csv file\n* data_dir: the path to saved .pt features\n* label_dict: a dictionary that maps labels in the label column to numerical values\n* label_col: name of the label column (optional, by default it's 'label')\n* ignore: labels to ignore (optional, by default it's an empty list)\n\nFinally, the user should add this specific 'task' specified by this dataset object in the --task arguments as shown below:\n\n```python\nparser.add_argument('--task', type=str, choices=['task_1_tumor_vs_normal',  'task_2_tumor_subtyping'])\n```\n\n### Training Splits\nFor evaluating the algorithm's performance, multiple folds (e.g. 10-fold) of train\u002Fval\u002Ftest splits can be used. Example 10-fold 80\u002F10\u002F10 splits for the two dummy datasets can be found under the **splits** folder. These splits can be automatically generated using the create_splits_seq.py script with minimal modification just like with **main.py**. For example, tumor_vs_normal splits can be created by calling:\n \n``` shell\npython create_splits_seq.py --task task_1_tumor_vs_normal --seed 1 --k 10\n```\nThe script uses the **Generic_WSI_Classification_Dataset** Class for which the constructor expects the same arguments as \n**Generic_MIL_Dataset** (without the data_dir argument). For details, please refer to the dataset definition in **datasets\u002Fdataset_generic.py**\n\n### GPU Training Example for Binary Positive vs. Negative Classification (e.g. Lymph Node Status)\nNote: --embed_dim should be set to 512 for CONCH, and 1024 for UNI and resnet50_trunc.\n\n``` shell\nCUDA_VISIBLE_DEVICES=0 python main.py --drop_out 0.25 --early_stopping --lr 2e-4 --k 10 --exp_code task_1_tumor_vs_normal_CLAM_50 --weighted_sample --bag_loss ce --inst_loss svm --task task_1_tumor_vs_normal --model_type clam_sb --log_data --data_root_dir DATA_ROOT_DIR --embed_dim 1024\n```\n\n### GPU Training Example for Subtyping Problems (e.g. 3-class RCC Subtyping)\n``` shell\nCUDA_VISIBLE_DEVICES=0 python main.py --drop_out 0.25 --early_stopping --lr 2e-4 --k 10 --exp_code task_2_tumor_subtyping_CLAM_50 --weighted_sample --bag_loss ce --inst_loss svm --task task_2_tumor_subtyping --model_type clam_sb --log_data --subtyping --data_root_dir DATA_ROOT_DIR --embed_dim 1024\n``` \nNote: We have included the option to use a single-attention-branch CLAM model, which performs favoribly in most experiments and can be set via --model_type clam_sb (single branch) or clam_mb (multi branch). clam_sb is the default choice. Additionally, the user can adjust the number of patches used for clustering via --B.\n\nBy default results will be saved to **results\u002Fexp_code** corresponding to the exp_code input argument from the user. If tensorboard logging is enabled (with the arugment toggle --log_data), the user can go into the results folder for the particular experiment, run:\n``` shell\ntensorboard --logdir=.\n```\nThis should open a browser window and show the logged training\u002Fvalidation statistics in real time. \nFor information on each argument, see:\n``` shell\npython main.py -h\n```\n\n### Testing and Evaluation Script\nUser also has the option of using the evluation script to test the performances of trained models. Examples corresponding to the models trained above are provided below:\n``` shell\nCUDA_VISIBLE_DEVICES=0 python eval.py --k 10 --models_exp_code task_1_tumor_vs_normal_CLAM_50_s1 --save_exp_code task_1_tumor_vs_normal_CLAM_50_s1_cv --task task_1_tumor_vs_normal --model_type clam_sb --results_dir results --data_root_dir DATA_ROOT_DIR --embed_dim 1024\n```\n\n``` shell\nCUDA_VISIBLE_DEVICES=0 python eval.py --k 10 --models_exp_code task_2_tumor_subtyping_CLAM_50_s1 --save_exp_code task_2_tumor_subtyping_CLAM_50_s1_cv --task task_2_tumor_subtyping --model_type clam_sb --results_dir results --data_root_dir DATA_ROOT_DIR --embed_dim 1024\n```\n\n\nOnce again, for information on each commandline argument, see:\n``` shell\npython eval.py -h\n```\n\nBy adding your own custom datasets into **eval.py** the same way as you do for **main.py**, you can also easily test trained models on independent test sets. \n\n### Heatmap Visualization\nHeatmap visualization can be computed in bulk via **create_heatmaps.py** by filling out the config file and storing it in **\u002Fheatmaps\u002Fconfigs** and then running **create_heatmaps.py** with the --config NAME_OF_CONFIG_FILE flag. A demo template is included (**config_template.yaml**) for lung subtyping on two WSIs from the CPTAC. \nTo run the demo (raw results are saved in **heatmaps\u002Fheatmap_raw_results** and final results are saved in **heatmaps\u002Fheatmap_production_results**):\n``` shell\nCUDA_VISIBLE_DEVICES=0 python create_heatmaps.py --config config_template.yaml\n```\nSee **\u002Fheatmaps\u002Fconfigs\u002Fconfig_template.yaml** for explanations for each configurable option.\n\nSimilar to feature extraction, if using UNI \u002F CONCH, set the environment variables before running the script. See [Using CONCH \u002F UNI as Pretrained Encoders](#using-conch--uni-as-pretrained-encoders) for more details.\n\n\n### Trained Model Checkpoints\nFor reproducability, all trained models used can be accessed [here](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1NZ82z0U_cexP6zkx1mRk-QeJyKWk4Q7z?usp=sharing).\nThe 3 main folders (**tcga_kidney_cv**, **tcga_cptac_lung_cv** and **camelyon_40x_cv**) correspond to models for RCC subtyping trained on the TCGA, for NSCLC subtyping trained on TCGA and CPTAC and for Lymph Node Metastasis (Breast) detection trained on Camelyon16+17 respectively. In each main folder, each subfolder corresponds to one set of 10-fold cross-validation experiments. For example, the subfolder tcga_kidney_cv_CLAM_50_s1 contains the 10 checkpoints corresponding to the 10 cross-validation folds for TCGA RCC subtyping, trained using CLAM with multi-attention branches using 50% of cases in the full training set. \n\nFor reproducability, these models can be evaluated on data prepared by following the same pipeline described in the sections above by calling **eval.py** with the appropriate arguments that specify the model options (either --model_type clam_mb or --model_type mil should be set, for evaluation only, --subtyping flag does not make a difference) as well as where the model checkpoints (--results_dir and --models_exp_code) and data (--data_root_dir and --task) are stored.\n\n### Examples\n\nPlease refer to our pre-print and [interactive demo](http:\u002F\u002Fclam.mahmoodlab.org) for detailed results on three different problems and adaptability across data sources, imaging devices and tissue content. \n\n\u003Cimg src=\"fig-git-hm.jpg\" width=\"1000px\" align=\"center\" \u002F>  \n\nVisulize additional examples here: http:\u002F\u002Fclam.mahmoodlab.org\n\n## Issues\n- Please report all issues on the public forum.\n\n## License\n© [Mahmood Lab](http:\u002F\u002Fwww.mahmoodlab.org) - This code is made available under the GPLv3 License and is available for non-commercial academic purposes.\n\n## Funding\nThis work was funded by NIH NIGMS [R35GM138216](https:\u002F\u002Freporter.nih.gov\u002Fsearch\u002FsWDcU5IfAUCabqoThQ26GQ\u002Fproject-details\u002F10029418).\n\n## Reference\nIf you find our work useful in your research or if you use parts of this code please consider citing our [paper](https:\u002F\u002Fwww.nature.com\u002Farticles\u002Fs41551-020-00682-w):\n\nLu, M.Y., Williamson, D.F.K., Chen, T.Y. et al. Data-efficient and weakly supervised computational pathology on whole-slide images. Nat Biomed Eng 5, 555–570 (2021). https:\u002F\u002Fdoi.org\u002F10.1038\u002Fs41551-020-00682-w\n\n```\n@article{lu2021data,\n  title={Data-efficient and weakly supervised computational pathology on whole-slide images},\n  author={Lu, Ming Y and Williamson, Drew FK and Chen, Tiffany Y and Chen, Richard J and Barbieri, Matteo and Mahmood, Faisal},\n  journal={Nature Biomedical Engineering},\n  volume={5},\n  number={6},\n  pages={555--570},\n  year={2021},\n  publisher={Nature Publishing Group}\n}\n```\n","CLAM \u003Cimg src=\"clam-logo.png\" width=\"280px\" align=\"right\" \u002F>\n===========\n全切片图像上的数据高效、弱监督计算病理学。\n*自然生物医学工程*\n\n[ArXiv](https:\u002F\u002Farxiv.org\u002Fabs\u002F2004.09666) | [期刊链接](https:\u002F\u002Fwww.nature.com\u002Farticles\u002Fs41551-020-00682-w) | [交互式演示](http:\u002F\u002Fclam.mahmoodlab.org) | [引用](#reference) \n\n***简而言之：** CLAM 是一种高通量且可解释的方法，用于在不进行 ROI 提取或补丁级标注的情况下，仅使用切片级标签实现数据高效的全切片图像（WSI）分类，并且能够处理多类别亚型问题。该方法已在三个不同的 WSI 数据集上进行了测试，训练好的模型可以适应独立的 WSI 切除和活检测试队列，以及智能手机显微镜图像（显微照片）。*\n\n[\u003Cimg src=\"ani.gif\" width=\"470px\" align=\"left\" \u002F>](http:\u002F\u002Fclam.mahmoodlab.org)\n## CLAM：基于深度学习的数据高效、弱监督全切片级分析流程 \n[先决条件](#pre-requisites) • [安装](INSTALLATION.md) • [分割与补丁生成](#wsi-segmentation-and-patching) • [特征提取](#weakly-supervised-learning-using-slide-level-labels-with-clam) • [弱监督训练](#Training-Splits) • [测试](#Testing-and-Evaluation-Script) • [训练好的模型](#Trained-Model-Checkpoints) • [热图可视化](#Heatmap-Visualization) • [示例](#examples) • [预印本](https:\u002F\u002Farxiv.org\u002Fabs\u002F2004.09666) • [演示](http:\u002F\u002Fclam.mahmoodlab.org) • [引用](#reference)\n\n***CLAM 是如何工作的？** 聚类约束注意力多实例学习（CLAM）是一种基于深度学习的弱监督方法，它利用注意力机制自动识别具有高诊断价值的子区域，从而准确地对整张切片进行分类；同时，它还对所识别的代表性区域进行实例级聚类，以约束和优化特征空间。*\n\n© [Mahmood 实验室](http:\u002F\u002Fwww.mahmoodlab.org) - 本代码根据 GPLv3 许可证发布，仅供非商业性学术用途。\n\n## 更新：\n* **2025年4月15日**：请查看我们的新仓库 [Trident](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FTRIDENT)，该仓库支持 25 多种基础模型的全切片图像处理，包括 [UNIv2](https:\u002F\u002Fhuggingface.co\u002FMahmoodLab\u002FUNI2-h)、[CONCH](https:\u002F\u002Fhuggingface.co\u002FMahmoodLab\u002FCONCH)、[TITAN](https:\u002F\u002Fhuggingface.co\u002FMahmoodLab\u002FTITAN) 等！\n* **2024年4月6日**：现在可以选择 [UNI](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FUNI) 和 [CONCH](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FCONCH) 作为预训练编码器。更多详情请参阅 [将 CONCH \u002F UNI 用作预训练编码器](#using-conch--uni-as-pretrained-encoders)。请确保已正确安装所有依赖项，方法是安装最新的 **env.yml** 文件（详情请参阅 [安装指南](INSTALLATION.md)），并使用相应的 **clam_latest** conda 环境。\n* 2024年3月19日：我们发布了 [UNI](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FUNI) 和 [CONCH](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FCONCH)，这对 SOTA 预训练编码器能够为组织病理学图像生成强大的表示，并提升各种计算病理工作流的表现，包括基于 MIL 的 CLAM 工作流。\n* 2021年5月24日：热图可视化脚本现已通过 **create_heatmaps.py** 提供，配置模板位于 **heatmaps\u002Fconfigs** 中。详情请参阅 [热图可视化演示及说明](#Heatmap-Visualization)。\n* 2021年3月1日：新的快速补丁生成\u002F特征提取流程现已上线。**简而言之：** 由于 CLAM 训练仅需图像特征，因此无需保存实际的图像补丁。新流程去除了这一开销，而是在“补丁生成”过程中仅保存图像补丁的坐标，并在特征提取时从 WSI 上按需加载这些区域。相比旧流程，这一新流程显著更快，通常只需 1–2 秒完成“补丁生成”，几分钟即可完成一张 WSI 的特征提取。要使用新流程，请确保调用 **create_patches_fp.py** 和 **extract_features_fp.py**，而非旧版的 **create_patches.py** 和 **extract_features.py** 脚本。\n\n**注意**：虽然我们希望最新更新不会对用户的流程造成太大改变，但如有需要，您仍可参考旧版本的代码库 [这里](https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FCLAM\u002Ftree\u002Fdeprecated)。如有任何问题，请在公开论坛中报告。\n\n**警告**：最新更新默认会在使用预训练编码器提取特征之前，将图像补丁调整为 224 x 224 像素大小。此更改旨在使其与 UNI、CONCH 及其他研究中使用的评估协议保持一致。如果您希望保留补丁生成过程中产生的原始图像尺寸，或使用不同尺寸的图像进行特征提取，则可在 **extract_features_fp.py** 中指定 `--target_patch_size` 参数。\n\n**2021年3月1日更新**：请注意，README 已更新为默认使用新的快速流程。如果您仍希望使用旧流程，请参阅：[旧流程指南](README_old.md)。该流程会保存组织补丁，速度明显较慢且占用大量存储空间，但如果需要处理原始图像补丁而非特征嵌入，则仍然有用。\n\n## 安装：\n有关如何开始使用的详细说明，请参阅我们的 [安装指南](INSTALLATION.md)。\n\n## WSI 分割与补丁生成 \n\n\u003Cimg src=\"CLAM1.jpg\" width=\"1000px\" align=\"center\" \u002F>\n第一步重点在于分割组织并排除任何空洞。特定切片的分割可以通过调整各个参数来进行（例如，扩张的血管可能表现为空洞，这对于某些肉瘤来说很重要）。 \n以下示例假设以常见标准格式（.svs、.ndpi、.tiff 等）数字化的全切片图像数据已存储在名为 DATA_DIRECTORY 的文件夹中：\n\n```bash\nDATA_DIRECTORY\u002F\n\t├── slide_1.svs\n\t├── slide_2.svs\n\t└── ...\n```\n\n### 基本的全自动运行\n``` shell\npython create_patches_fp.py --source DATA_DIRECTORY --save_dir RESULTS_DIRECTORY --patch_size 256 --seg --patch --stitch \n```\n\n上述命令将使用默认参数对 `DATA_DIRECTORY` 中的每张切片进行分割，提取分割后组织区域内的所有补丁，并为每张切片利用提取的补丁创建拼接重建图像（可选），同时在指定的 `RESULTS_DIRECTORY` 中生成以下文件夹结构：\n\n```bash\nRESULTS_DIRECTORY\u002F\n\t├── masks\n    \t\t├── slide_1.png\n    \t\t├── slide_2.png\n    \t\t└── ...\n\t├── patches\n    \t\t├── slide_1.h5\n    \t\t├── slide_2.h5\n    \t\t└── ...\n\t├── stitches\n    \t\t├── slide_1.png\n    \t\t├── slide_2.png\n    \t\t└── ...\n\t└── process_list_autogen.csv\n```\n\n其中，`masks` 文件夹包含分割结果（每张切片一张图像）。  \n`patches` 文件夹包含从每张切片中提取的组织补丁数组（每张切片一个 `.h5` 文件，每个条目对应补丁左上角的坐标）。  \n`stitches` 文件夹包含拼接后的组织补丁的下采样可视化图像（每张切片一张图像）（可选，不用于下游任务）。  \n自动生成的 `process_list_autogen.csv` 文件则列出了所有已处理的切片及其使用的分割和补丁参数。\n\n此外，还可以传递以下额外参数：\n* `--custom_downsample`：自定义下采样因子（不推荐，建议先检查是否存在原生下采样）。\n* `--patch_level`：从哪个金字塔层级提取补丁（默认为 0，即最高可用分辨率）。\n* `--no_auto_skip`：默认情况下，脚本会跳过目标文件夹中已存在补丁 `.h5` 文件的文件；此选项可用于覆盖该行为。\n\n此外，还提供了一些参数模板，可作为默认参数的良好选择：\n* `bwh_biopsy.csv`：用于分割在 BWH 扫描的活检切片（使用 Hamamatsu S210 和 Aperio GT450 扫描）。\n* `bwh_resection.csv`：用于分割在 BWH 扫描的切除标本切片。\n* `tcga.csv`：用于分割 TCGA 数据集中的切片。\n\n只需将模板文件名传递给 `--preset` 参数即可，例如使用活检模板：\n``` shell\npython create_patches_fp.py --source DATA_DIRECTORY --save_dir RESULTS_DIRECTORY --patch_size 256 --preset bwh_biopsy.csv --seg --patch --stitch\n```\n\n### 自定义默认分割参数\n对于高级用法，除了使用脚本 `create_patches_fp.py` 中定义的默认单一参数集外，用户还可以根据数据集定义自定义参数模板。这些模板应存储在 `presets` 目录下，包含分割和补丁过程中所用各参数的值。\n\n分割参数列表如下：\n* `seg_level`：在哪个下采样层级上进行全切片图像分割（默认为 -1，即使用最接近 64 倍下采样的层级）。\n* `sthresh`：分割阈值（正整数，默认为 8；阈值越高，检测到的前景越少，背景越多）。\n* `mthresh`：中值滤波器大小（正奇数，默认为 7）。\n* `use_otsu`：是否使用 Otsu 方法代替简单二值化阈值法（默认为 False）。\n* `close`：在初始阈值处理后应用的额外形态学闭运算（正整数或 -1，默认为 4）。\n\n轮廓过滤参数列表如下：\n* `a_t`：组织区域面积过滤阈值（正整数，表示检测到的前景轮廓最小尺寸，相对于 0 级别下 512×512 大小的参考补丁而言；例如，值为 10 表示只有大于 10 个 512×512 大小补丁的前景轮廓才会被处理，默认为 100）。\n* `a_h`：空洞面积过滤阈值（正整数，表示要避免的前景轮廓中最小空洞\u002F腔体尺寸，同样相对于 0 级别下 512×512 大小的补丁而言；默认为 16）。\n* `max_n_holes`：每个检测到的前景轮廓最多允许的空洞数量（正整数，默认为 10；最大值越高，补丁提取越准确，但计算成本也会增加）。\n\n分割可视化参数列表如下：\n* `vis_level`：用于可视化分割结果的下采样层级（默认为 -1，即使用最接近 64 倍下采样的层级）。\n* `line_thickness`：绘制分割结果时的线条粗细（正整数，以 0 级别下线条占用的像素数表示，默认为 250）。\n\n补丁提取参数列表如下：\n* `use_padding`：是否对切片边缘进行填充（默认为 True）。\n* `contour_fn`：用于判断补丁属于前景还是背景的轮廓检查函数（可选“four_pt”——检查补丁中心周围小网格中的四个点是否全部位于轮廓内；“center”——检查补丁中心是否位于轮廓内；“basic”——检查补丁左上角是否位于轮廓内；默认为“four_pt”）。\n\n### 两步运行（手动调整特定切片的参数）\n为确保高质量的分割和相关组织patch的提取，用户可以选择先进行分割（通常每个切片约1秒），检查分割结果，并在必要时针对选定的切片微调参数，然后再使用调整后的参数提取patch。即第一步运行：\n\n``` shell\npython create_patches_fp.py --source DATA_DIRECTORY --save_dir RESULTS_DIRECTORY --patch_size 256 --seg  \n```\n上述命令将使用默认参数对DATA_DIRECTORY中的每个切片进行分割，并生成csv文件，但此时不会立即提取patch（**patches**和**stitches**文件夹将为空）。\n\n可以针对特定切片对csv文件进行调整，并通过--process_list CSV_FILE_NAME参数将其传递给脚本，以便脚本使用用户更新后的设置。在调整分割参数之前，用户应先复制一份csv文件并重命名（例如：process_list_edited.csv），否则下次运行该命令时会覆盖原文件。随后，用户可以通过修改csv文件中相应切片的字段来微调参数。其中，**process**列存储一个二进制变量（0或1），用于指示是否对该切片进行处理。这使得用户只需开启少数几个切片，即可快速确认调整后的参数是否达到满意效果。例如，若要使用用户更新后的参数重新分割slide_1.svs，只需对其相关字段做出相应更改，将**process**单元格更新为1，保存csv文件，并将其名称传递给上述相同命令：\n\n``` shell\npython create_patches_fp.py --source DATA_DIRECTORY --save_dir RESULTS_DIRECTORY --patch_size 256 --seg --process_list process_list_edited.csv\n```\n\n当对分割结果满意时，用户应将所有需要处理的切片的**process**单元格设置为1，保存csv文件，然后使用保存的csv文件执行patch提取操作（与完全自动化运行用例相同，只是增加了csv文件参数）：\n\n``` shell\npython create_patches_fp.py --source DATA_DIRECTORY --save_dir RESULTS_DIRECTORY --patch_size 256 --seg --process_list CSV_FILE_NAME --patch --stitch\n```\n\n## 使用CLAM进行基于切片级标签的弱监督学习\n\n\u003Cimg src=\"CLAM2.jpg\" width=\"1000px\" align=\"center\" \u002F>\n\n### 特征提取（GPU示例）\n```bash\nCUDA_VISIBLE_DEVICES=0 python extract_features_fp.py --data_h5_dir DIR_TO_COORDS --data_slide_dir DATA_DIRECTORY --csv_path CSV_FILE_NAME --feat_dir FEATURES_DIRECTORY --batch_size 512 --slide_ext .svs\n```\n上述命令要求将坐标.h5文件存储在DIR_TO_COORDS目录下，并以512的批量大小从每个切片的每个组织patch中提取1024维特征，最终生成如下文件结构：\n```bash\nFEATURES_DIRECTORY\u002F\n    ├── h5_files\n            ├── slide_1.h5\n            ├── slide_2.h5\n            └── ...\n    └── pt_files\n            ├── slide_1.pt\n            ├── slide_2.pt\n            └── ...\n```\n其中，每个.h5文件包含提取的特征数组及其对应的patch坐标（注意，为了加快训练速度，还会为每个切片创建一个仅包含patch特征的.pt文件）。csv文件应包含待处理切片的文件名列表（不带文件扩展名）。最简单的方法是直接使用前一步分割\u002Fpatch提取自动生成的csv文件，并删除文件扩展名。\n\n### 使用CONCH \u002F UNI作为预训练编码器\n如果使用UNI或CONCH，首先请参考它们各自的HF页面，申请并下载模型权重（pytorch_model.bin）。\n\nUNI：https:\u002F\u002Fhuggingface.co\u002FMahmoodLab\u002FUNI\n\nCONCH：https:\u002F\u002Fhuggingface.co\u002FMahmoodLab\u002FCONCH\n\n成功下载模型检查点后，在运行特征提取脚本之前，需将`CONCH_CKPT_PATH`和`UNI_CKPT_PATH`环境变量设置为预训练编码器检查点的路径。例如，若已将UNI和CONCH的预训练检查点分别放置在**checkpoints\u002Fconch**和**checkpoints\u002Funi**文件夹中，则可按如下方式设置环境变量：\n```bash\nexport CONCH_CKPT_PATH=checkpoints\u002Fconch\u002Fpytorch_model.bin\nexport UNI_CKPT_PATH=checkpoints\u002Funi\u002Fpytorch_model.bin\n```\n在运行**extract_features_fp.py**时，还需将`--model_name`设置为‘uni_v1’或‘conch_v1’，以使用相应的编码器。\n\n需要注意的是，这些编码器模型（尤其是采用ViT-L的UNI）比默认的ResNet50编码器计算成本更高、所需显存也更多，因此如果显存不足，预计运行时间会更长且批大小会相应减小。UNI将输出1024维特征，而CONCH则输出512维特征。\n\n### 数据集\n用于训练和测试的数据应按以下方式组织：\n```bash\nDATA_ROOT_DIR\u002F\n    ├──DATASET_1_DATA_DIR\u002F\n        ├── h5_files\n                ├── slide_1.h5\n                ├── slide_2.h5\n                └── ...\n        └── pt_files\n                ├── slide_1.pt\n                ├── slide_2.pt\n                └── ...\n    ├──DATASET_2_DATA_DIR\u002F\n        ├── h5_files\n                ├── slide_a.h5\n                ├── slide_b.h5\n                └── ...\n        └── pt_files\n                ├── slide_a.pt\n                ├── slide_b.pt\n                └── ...\n    └──DATASET_3_DATA_DIR\u002F\n        ├── h5_files\n                ├── slide_i.h5\n                ├── slide_ii.h5\n                └── ...\n        └── pt_files\n                ├── slide_i.pt\n                ├── slide_ii.pt\n                └── ...\n    └── ...\n```\n即，每个数据集应作为 DATA_ROOT_DIR 下的一个子文件夹（例如 DATASET_1_DATA_DIR），而该数据集中每张切片提取的特征则以 .pt 文件的形式存储在该子文件夹的 **pt_files** 文件夹下。\n此外，数据集还应以 CSV 格式准备，至少包含 3 列：**case_id**、**slide_id**，以及 1 列或多列用于表示切片级别标签的列。每个 **case_id** 是患者的唯一标识符，而 **slide_id** 是与提取的特征 .pt 文件名相对应的切片唯一标识符。这一点非常重要，因为通常一位患者会有多个切片，且这些切片可能具有不同的标签。在创建训练\u002F验证\u002F测试划分时，我们还会确保来自同一患者的切片不会被分配到不同的划分中。切片 ID 应与特征提取步骤中使用的 ID 保持一致。我们在 **dataset_csv** 文件夹中提供了两个此类数据集 CSV 文件的示例：一个用于二分类肿瘤与正常组织（任务 1），另一个用于多分类肿瘤亚型分类（任务 2）。\n\n用于实际训练\u002F验证\u002F测试的数据集对象可以使用 **Generic_MIL_Dataset** 类（定义在 **datasets\u002Fdataset_generic.py** 中）来构建。此类数据集对象传递给模型的示例可在 **main.py** 和 **eval.py** 中找到。\n\n对于训练，请查看 main.py：\n```python \nif args.task == 'task_1_tumor_vs_normal':\n    args.n_classes=2\n    dataset = Generic_MIL_Dataset(csv_path = 'dataset_csv\u002Ftumor_vs_normal_dummy_clean.csv',\n                            data_dir= os.path.join(args.data_root_dir, 'tumor_vs_normal_feat_resnet'),\n                            shuffle = False, \n                            seed = args.seed, \n                            print_info = True,\n                            label_dict = {'normal_tissue':0, 'tumor_tissue':1},\n                            label_col = 'label',\n                            ignore=[])\n```\n用户需要传入：\n* csv_path：数据集 CSV 文件的路径\n* data_dir：保存的 .pt 特征文件的路径\n* label_dict：将标签列中的标签映射为数值的字典\n* label_col：标签列的名称（可选，默认为 'label'）\n* ignore：要忽略的标签（可选，默认为空列表）\n\n最后，用户应在 --task 参数中添加由该数据集对象指定的具体“任务”，如下所示：\n\n```python\nparser.add_argument('--task', type=str, choices=['task_1_tumor_vs_normal',  'task_2_tumor_subtyping'])\n```\n\n### 训练划分\n为了评估算法性能，可以使用多折（例如 10 折）的训练\u002F验证\u002F测试划分。两个示例数据集的 10 折 80\u002F10\u002F10 划分可在 **splits** 文件夹中找到。这些划分可以使用 create_splits_seq.py 脚本自动生成，只需进行少量修改，就像处理 **main.py** 一样。例如，肿瘤与正常组织的划分可以通过以下命令创建：\n \n``` shell\npython create_splits_seq.py --task task_1_tumor_vs_normal --seed 1 --k 10\n```\n该脚本使用 **Generic_WSI_Classification_Dataset** 类，其构造函数所需的参数与 **Generic_MIL_Dataset** 相同（但不包括 data_dir 参数）。有关详细信息，请参阅 **datasets\u002Fdataset_generic.py** 中的数据集定义。\n\n### GPU 训练示例：二分类阳性 vs. 阴性（例如淋巴结状态）\n注意：对于 CONCH，--embed_dim 应设置为 512；对于 UNI 和 resnet50_trunc，则应设置为 1024。\n\n``` shell\nCUDA_VISIBLE_DEVICES=0 python main.py --drop_out 0.25 --early_stopping --lr 2e-4 --k 10 --exp_code task_1_tumor_vs_normal_CLAM_50 --weighted_sample --bag_loss ce --inst_loss svm --task task_1_tumor_vs_normal --model_type clam_sb --log_data --data_root_dir DATA_ROOT_DIR --embed_dim 1024\n```\n\n### GPU 训练示例：亚型分类问题（例如 3 类肾细胞癌亚型分类）\n``` shell\nCUDA_VISIBLE_DEVICES=0 python main.py --drop_out 0.25 --early_stopping --lr 2e-4 --k 10 --exp_code task_2_tumor_subtyping_CLAM_50 --weighted_sample --bag_loss ce --inst_loss svm --task task_2_tumor_subtyping --model_type clam_sb --log_data --subtyping --data_root_dir DATA_ROOT_DIR --embed_dim 1024\n```\n\n注意：我们已提供使用单注意力分支 CLAM 模型的选项，在大多数实验中表现良好，可通过 --model_type clam_sb（单分支）或 clam_mb（多分支）进行设置。默认选择是 clam_sb。此外，用户还可以通过 --B 调整用于聚类的补丁数量。\n\n默认情况下，结果将保存到与用户输入的 exp_code 参数对应的 **results\u002Fexp_code** 文件夹中。如果启用了 TensorBoard 日志记录（通过 --log_data 参数开启），用户可以进入特定实验的结果文件夹，运行：\n``` shell\ntensorboard --logdir=.\n```\n这将打开浏览器窗口，并实时显示记录的训练\u002F验证统计数据。有关每个参数的信息，请参阅：\n``` shell\npython main.py -h\n```\n\n### 测试与评估脚本\n用户也可以使用评估脚本来测试已训练模型的性能。以下是对应于上述训练模型的示例：\n``` shell\nCUDA_VISIBLE_DEVICES=0 python eval.py --k 10 --models_exp_code task_1_tumor_vs_normal_CLAM_50_s1 --save_exp_code task_1_tumor_vs_normal_CLAM_50_s1_cv --task task_1_tumor_vs_normal --model_type clam_sb --results_dir results --data_root_dir DATA_ROOT_DIR --embed_dim 1024\n```\n\n``` shell\nCUDA_VISIBLE_DEVICES=0 python eval.py --k 10 --models_exp_code task_2_tumor_subtyping_CLAM_50_s1 --save_exp_code task_2_tumor_subtyping_CLAM_50_s1_cv --task task_2_tumor_subtyping --model_type clam_sb --results_dir results --data_root_dir DATA_ROOT_DIR --embed_dim 1024\n```\n\n再次强调，有关每个命令行参数的信息，请参阅：\n``` shell\npython eval.py -h\n```\n\n通过以与处理 **main.py** 相同的方式将您自己的自定义数据集添加到 **eval.py** 中，您也可以轻松地在独立测试集上测试已训练的模型。\n\n### 热图可视化\n热图可视化可以通过 **create_heatmaps.py** 脚本批量计算。只需填写配置文件并将其存储在 **\u002Fheatmaps\u002Fconfigs** 目录下，然后使用 --config NAME_OF_CONFIG_FILE 标志运行 **create_heatmaps.py** 即可。我们提供了一个演示模板（**config_template.yaml**），用于对来自 CPTAC 的两张全切片图像进行肺部亚型分类。\n\n要运行演示（原始结果保存在 **heatmaps\u002Fheatmap_raw_results**，最终结果保存在 **heatmaps\u002Fheatmap_production_results**）：\n``` shell\nCUDA_VISIBLE_DEVICES=0 python create_heatmaps.py --config config_template.yaml\n```\n有关每个可配置选项的说明，请参阅 **\u002Fheatmaps\u002Fconfigs\u002Fconfig_template.yaml** 文件。\n\n与特征提取类似，如果使用 UNI 或 CONCH 作为预训练编码器，在运行脚本之前需要设置相应的环境变量。更多详细信息请参阅 [将 CONCH \u002F UNI 用作预训练编码器](#using-conch--uni-as-pretrained-encoders) 部分。\n\n### 训练好的模型检查点\n为确保实验的可重复性，所有使用的训练模型均可在此处获取：[Google Drive](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1NZ82z0U_cexP6zkx1mRk-QeJyKWk4Q7z?usp=sharing)。\n\n三个主要文件夹（**tcga_kidney_cv**、**tcga_cptac_lung_cv** 和 **camelyon_40x_cv**）分别对应于以下任务的模型：基于 TCGA 数据训练的肾癌亚型分类模型、基于 TCGA 和 CPTAC 数据训练的非小细胞肺癌亚型分类模型，以及基于 Camelyon16+17 数据训练的乳腺淋巴结转移检测模型。在每个主文件夹中，每个子文件夹对应一组 10 折交叉验证实验。例如，子文件夹 tcga_kidney_cv_CLAM_50_s1 包含针对 TCGA 肾癌亚型分类的 10 个交叉验证折次的检查点，这些模型使用 CLAM 方法，并采用多注意力分支架构，仅利用完整训练集中 50% 的病例进行训练。\n\n为了实现可重复性，可以按照上述章节中描述的相同流程准备数据，然后通过调用 **eval.py** 脚本评估这些模型。评估时需指定适当的参数，包括模型类型（应设置为 --model_type clam_mb 或 --model_type mil；对于仅评估而言，--subtyping 标志并无影响），以及模型检查点和数据的存储路径（--results_dir、--models_exp_code、--data_root_dir 和 --task）。\n\n### 示例\n有关三种不同问题的详细结果以及跨数据源、成像设备和组织内容的适应性，请参阅我们的预印本和[交互式演示](http:\u002F\u002Fclam.mahmoodlab.org)。\n\n\u003Cimg src=\"fig-git-hm.jpg\" width=\"1000px\" align=\"center\" \u002F>  \n\n更多示例请访问：http:\u002F\u002Fclam.mahmoodlab.org\n\n## 问题\n- 请在公共论坛上报告所有问题。\n\n## 许可证\n© [Mahmood 实验室](http:\u002F\u002Fwww.mahmoodlab.org) - 本代码根据 GPLv3 许可证发布，仅供非商业性的学术用途。\n\n## 资助\n本研究由美国国立卫生研究院 NIGMS [R35GM138216](https:\u002F\u002Freporter.nih.gov\u002Fsearch\u002FsWDcU5IfAUCabqoThQ26GQ\u002Fproject-details\u002F10029418) 资助。\n\n## 参考文献\n如果您在研究中使用了我们的工作成果，或引用了本代码的部分内容，请考虑引用我们的论文：\n\nLu, M.Y., Williamson, D.F.K., Chen, T.Y. 等. 基于全切片图像的数据高效且弱监督的计算病理学. Nature Biomedical Engineering 5, 555–570 (2021). https:\u002F\u002Fdoi.org\u002F10.1038\u002Fs41551-020-00682-w\n\n```\n@article{lu2021data,\n  title={Data-efficient and weakly supervised computational pathology on whole-slide images},\n  author={Lu, Ming Y and Williamson, Drew FK and Chen, Tiffany Y and Chen, Richard J and Barbieri, Matteo and Mahmood, Faisal},\n  journal={Nature Biomedical Engineering},\n  volume={5},\n  number={6},\n  pages={555--570},\n  year={2021},\n  publisher={Nature Publishing Group}\n}\n```","# CLAM 快速上手指南\n\nCLAM (Clustering-constrained Attention Multiple Instance Learning) 是一个基于深度学习的弱监督学习框架，专为全切片病理图像（WSI）分类设计。它无需手动标注感兴趣区域（ROI）或补丁级标签，仅利用幻灯片级别的标签即可高效训练模型，并自动识别高诊断价值的子区域。\n\n## 1. 环境准备\n\n在开始之前，请确保您的系统满足以下要求：\n\n*   **操作系统**: Linux (推荐 Ubuntu 18.04\u002F20.04) 或 macOS。Windows 用户建议使用 WSL2。\n*   **Python**: 3.8 或更高版本。\n*   **GPU**: 推荐使用 NVIDIA GPU 以加速特征提取和模型训练（需安装对应的 CUDA 驱动）。\n*   **存储**: 确保有足够的磁盘空间存放原始 WSI 数据及生成的中间文件（掩码、坐标文件等）。\n*   **依赖库**: 需要安装 `openslide-python` 及其底层库 `libopenslide` 以读取常见的病理图像格式（.svs, .ndpi, .tiff 等）。\n\n> **提示**: 对于国内开发者，建议在配置 Python 环境时使用清华源或阿里源加速包下载。\n\n## 2. 安装步骤\n\nCLAM 推荐使用 Conda 进行环境管理。请按照以下步骤操作：\n\n### 第一步：克隆仓库\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FCLAM.git\ncd CLAM\n```\n\n### 第二步：创建并激活 Conda 环境\n使用项目提供的最新配置文件 `env.yml` 创建环境。该文件已包含所有必要的依赖（包括 PyTorch, OpenSlide, Scikit-learn 等）。\n\n```bash\nconda env create -f env.yml\nconda activate clam_latest\n```\n\n> **注意**: 如果下载 `env.yml` 中的包速度较慢，可以在创建环境后，手动使用 pip 国内源更新关键包，或者在运行 `conda create` 时添加 `-c https:\u002F\u002Fmirrors.tuna.tsinghua.edu.cn\u002Fanaconda\u002Fpkgs\u002Fmain\u002F` 等镜像源参数（具体取决于 conda 配置）。\n\n### 第三步：验证安装\n确保 `openslide` 能够正常加载。您可以尝试运行一个简单的帮助命令来检查脚本是否可执行：\n```bash\npython create_patches_fp.py --help\n```\n\n## 3. 基本使用\n\nCLAM 的核心工作流程分为三个阶段：**分割与分块 (Segmentation & Patching)** -> **特征提取 (Feature Extraction)** -> **弱监督训练 (Training)**。\n\n假设您的原始 WSI 数据存放在 `DATA_DIRECTORY` 文件夹中，结果将保存到 `RESULTS_DIRECTORY`。\n\n### 步骤一：组织数据\n将您的全切片图像（.svs, .tiff 等）放入一个文件夹：\n```text\nDATA_DIRECTORY\u002F\n    ├── slide_1.svs\n    ├── slide_2.svs\n    └── ...\n```\n\n### 步骤二：组织分割与分块 (Segmentation and Patching)\n此步骤会自动分割组织区域，排除背景，并提取组织内的补丁坐标。这是最快且最常用的自动化流程。\n\n```bash\npython create_patches_fp.py --source DATA_DIRECTORY --save_dir RESULTS_DIRECTORY --patch_size 256 --seg --patch --stitch\n```\n\n**参数说明：**\n*   `--source`: 输入 WSI 文件夹路径。\n*   `--save_dir`: 输出结果文件夹路径。\n*   `--patch_size`: 补丁大小（像素），默认为 256。\n*   `--seg`: 执行组织分割。\n*   `--patch`: 执行分块（仅保存坐标，不保存图像本身，节省空间）。\n*   `--stitch`: 生成拼接后的可视化预览图（可选）。\n\n**输出结构：**\n执行完成后，`RESULTS_DIRECTORY` 将包含：\n*   `masks\u002F`: 分割掩码图像。\n*   `patches\u002F`: 包含每个幻灯片补丁坐标的 `.h5` 文件。\n*   `process_list_autogen.csv`: 处理列表，后续步骤需用到此文件。\n\n> **进阶提示**: 如果针对特定数据集（如 TCGA 或 BWH 活检），可使用预设参数模板加速调整：\n> `--preset tcga.csv` 或 `--preset bwh_biopsy.csv`\n\n### 步骤三：特征提取 (Feature Extraction)\n利用预训练编码器（如 ResNet, UNI, CONCH 等）将上一步生成的补丁坐标转换为特征向量。\n\n```bash\npython extract_features_fp.py --data_h5_dir RESULTS_DIRECTORY\u002Fpatches --save_dir RESULTS_DIRECTORY\u002Ffeatures --csv_path RESULTS_DIRECTORY\u002Fprocess_list_autogen.csv --batch_size 256\n```\n\n**关键点：**\n*   该脚本会按需从原始 WSI 中加载区域并提取特征，无需预先保存大量图像补丁。\n*   若要使用最新的 SOTA 编码器（如 **UNI** 或 **CONCH**），请确保在命令中指定相应的模型参数（参考官方文档中 \"Using CONCH \u002F UNI as Pretrained Encoders\" 部分）。\n\n### 步骤四：弱监督训练 (Training)\n准备好特征文件和对应的幻灯片级别标签（需整理为 CSV 格式，包含 `slide_id` 和 `label`），即可开始训练。\n\n```bash\npython main.py --drop_out --early_stopping --lr 2e-4 --k 10 --subtyping --bag_loss ce --model clam_sb --weighted_sample --inst_loss svm --max_epochs 30 --results_dir results_directory_name --data_root_dir RESULTS_DIRECTORY\u002Ffeatures --csv_path your_labels.csv\n```\n\n**常用参数简述：**\n*   `--subtyping`: 开启多分类亚型分析。\n*   `--model clam_sb`: 使用单分支 CLAM 模型（也可选 `clam_mb` 多分支）。\n*   `--csv_path`: 指向包含标签的 CSV 文件。\n*   `--data_root_dir`: 指向步骤三生成的特征目录。\n\n训练完成后，模型权重将保存在 `results_directory_name` 中，您可以使用提供的脚本生成注意力热力图（Heatmap）以解释模型决策。","某三甲医院病理科团队正试图利用深度学习对数千张全切片图像（WSI）进行癌症亚型自动分类，以辅助医生快速筛查高危病例。\n\n### 没有 CLAM 时\n- **标注成本极高**：病理学家必须在每张巨大的切片上手动勾画具体的肿瘤区域（ROI），耗时数周且人力难以负荷。\n- **数据利用率低**：由于缺乏细粒度标注，大量仅有“幻灯片级”诊断报告的历史数据无法用于训练模型。\n- **模型可解释性差**：传统黑盒模型只能给出分类结果，医生无法得知模型是依据哪部分组织做出的判断，导致临床信任度低。\n- **泛化能力弱**：在不同医院或不同扫描设备采集的切片数据上，模型性能大幅下降，难以适应真实多样的临床环境。\n\n### 使用 CLAM 后\n- **实现弱监督学习**：仅需利用现有的幻灯片级诊断标签即可训练，完全省去了繁琐的像素级或区域级人工标注过程。\n- **激活历史数据价值**：能够直接消化医院积累的海量未标注细节的历史存档数据，显著降低数据准备门槛。\n- **提供直观热力图**：CLAM 自动生成注意力热力图，高亮显示对诊断贡献最大的细胞区域，让医生能清晰验证模型的决策依据。\n- **跨域适应性强**：得益于聚类约束的注意力机制，模型在未见过的独立测试队列甚至手机显微摄影图像上均表现出稳定的分类精度。\n\nCLAM 通过弱监督学习范式，将病理 AI 的开发周期从“月级”标注缩短至“天级”训练，同时赋予了模型医生可信赖的临床可解释性。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmahmoodlab_CLAM_77d5244d.png","mahmoodlab","Mahmood Lab @ Harvard\u002FMGB","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fmahmoodlab_ca9d31b7.png","AI for Pathology Image Analysis Lab @ HMS \u002F BWH",null,"fmahmood@fas.harvard.edu","AI4Pathology","www.mahmoodlab.org","https:\u002F\u002Fgithub.com\u002Fmahmoodlab",[82],{"name":83,"color":84,"percentage":85},"Python","#3572A5",100,1656,497,"2026-04-16T05:05:43","GPL-3.0",4,"未说明","需要 NVIDIA GPU（用于运行深度学习模型及特征提取），具体型号和显存大小未在片段中明确说明，但建议使用支持 CUDA 的显卡以加速处理","未说明（建议 16GB+ 以处理全切片图像）",{"notes":95,"python":96,"dependencies":97},"必须使用 Conda 管理环境并安装提供的 env.yml 文件。该工具主要用于全切片图像（WSI）分析，依赖 OpenSlide 读取多种格式的病理图像（.svs, .ndpi 等）。最新流程默认将图像块调整为 224x224 进行特征提取，若需保留原始尺寸需指定参数。支持使用 UNI 和 CONCH 等预训练编码器。代码仅适用于非商业学术目的（GPLv3 许可）。","未说明（需通过 conda 环境安装，参考 env.yml）",[98,99,100,101,102,103,104],"torch","openslide-python","h5py","numpy","pandas","scikit-learn","matplotlib",[14,16,15],[107,108,109,110,111,112,72,113,114,115,116,117,118,119,120],"histopathology","pathology","weakly-supervised-learning","whole-slide-imaging","data-efficient","computational-pathology","bioimage-informatics","deep-learning","tcga-data","camelyon16","camelyon17","clam","digital-pathology","quantitative-pathology","2026-03-27T02:49:30.150509","2026-04-17T10:19:44.373293",[124,129,134,139,144,148],{"id":125,"question_zh":126,"answer_zh":127,"source_url":128},37453,"如何正确设置参数以从 40x 全玻片图像中提取 20x 或 10x 的补丁（Patch）？","如果您的原始图像在 Level 0 是 40x 放大倍率，而您需要 20x 的图像：\n1. 使用参数 `--level 0`。\n2. 设置 `--patch_size 512` 和 `--step_size 512`。\n3. 在提取特征时运行 `--custom_downsample 2`。\n\n如果您需要 10x 的图像，有两种等效方法：\n方法 A：使用 `--level 0`，设置 `--patch_size 1024`，`--step_size 1024`，并运行 `--custom_downsample 4`。\n方法 B：直接使用 `--level 1`（假设 Level 1 对应 10x），设置 `--patch_size 256`，且不需要自定义下采样。\n注意：虽然生成的补丁像素尺寸和特征维度可能相同，但由于插值算法不同，直接读取不同 Level 与通过 downsample 处理得到的特征数值可能会有细微差异。","https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FCLAM\u002Fissues\u002F115",{"id":130,"question_zh":131,"answer_zh":132,"source_url":133},37454,"遇到 RuntimeError: mat1 and mat2 shapes cannot be multiplied (维度不匹配) 错误如何解决？","该错误通常发生在模型的全连接层（FC layer）输入维度与权重矩阵不匹配时。这通常是因为预训练的特征提取器输出的特征维度（例如 1024）与 CLAM 模型默认设置的输入维度（例如 512）不一致。\n解决方案是修改模型配置中的 `size_dict` 参数，使其第一维（输入维度）与您实际使用的特征维度相匹配。例如，如果您使用的特征是 1024 维，可以将 `size_dict` 设置为 `[1024, 512, 256]` 或 `[1024, 1024, 512]`。确保层级间的维度能够顺利传递即可，不一定非要严格递减，但需保证矩阵乘法合法。","https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FCLAM\u002Fissues\u002F111",{"id":135,"question_zh":136,"answer_zh":137,"source_url":138},37455,"运行 create_patches.py 时出现 \"OSError: Unable to open file ... No such file or directory\" 错误怎么办？","此错误通常表示脚本试图保存补丁文件时，目标目录不存在。请检查您的 `--save_dir` 参数指定的路径是否已创建。如果目录不存在，脚本可能无法自动创建嵌套的子目录（如 `new\u002Fpatches\u002F`）。\n解决方法：\n1. 手动创建完整的输出目录结构。\n2. 或者检查代码逻辑，确保在写入 h5 文件前已经创建了相应的父目录。\n此外，如果某些切片（Slide）生成的补丁数量极少，也可能导致后续聚类任务出错，此时可以在训练时添加 `--no_inst_cluster` 参数跳过实例级聚类，但建议先检查生成的 \"masks\" 和 \"stitches\" 图像以确保分割过程正常。","https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FCLAM\u002Fissues\u002F28",{"id":140,"question_zh":141,"answer_zh":142,"source_url":143},37456,"运行 create_patches.py 时出现 \"Division by zero\" 错误，且生成的掩膜（Mask）不是二值图像而是原图，如何解决？","出现 \"Division by zero\" 错误通常是因为没有检测到任何有效的组织区域，导致处理总数为 0。同时，如果生成的 Mask 与原图一样而非二值分割图，说明组织分割算法未能正确识别组织。\n原因通常是默认的分割算法假设组织区域面积较大，而您的图像中组织区域较小或被误判为背景。\n解决方案：\n在使用预设的 .csv 配置文件或运行命令时，将组织面积阈值参数（tissue area parameter）设置为 0。这将允许算法保留较小的组织区域，从而正常生成二值掩膜并避免除以零的错误。","https:\u002F\u002Fgithub.com\u002Fmahmoodlab\u002FCLAM\u002Fissues\u002F20",{"id":145,"question_zh":146,"answer_zh":147,"source_url":128},37457,"CLAM 结果总结表中的 \"Slide-LVL\" 和 \"Patient-LVL\" 有什么区别？","在病理数据分析中：\n- **Slide-LVL (切片级别)**：统计的是物理玻片切片的数量。一个病人可能有多张切片，每张切片都被视为一个独立样本。\n- **Patient-LVL (病人级别)**：统计的是唯一病人的数量。如果一个病人有多张切片，在病人级别统计中只计为 1 个样本。\n在数据划分和评估时，Slide-LVL 反映了模型对单张切片图像的 classification 能力，而 Patient-LVL 则反映了模型对病人整体诊断的准确性（通常通过投票机制或多示例聚合得出）。在 RCC 亚型分类等任务中，区分这两者对于理解数据集分布和模型泛化能力至关重要。",{"id":149,"question_zh":150,"answer_zh":151,"source_url":138},37458,"训练过程中遇到 \"too few patches in some slides\" 导致实例级聚类失败，该如何处理？","如果某些切片提取的补丁（Patch）数量过少，无法满足实例级聚类（instance-level clustering）的最小样本要求，会导致训练报错。\n临时解决方案：\n在训练命令中添加 `--no_inst_cluster` 参数，这将禁用实例级聚类任务，允许模型继续训练。\n根本解决方案：\n1. 检查数据预处理步骤，确认 \"masks\"（组织掩膜）和 \"stitches\"（拼接图）是否正确生成。如果掩膜覆盖区域太小，可能导致提取的补丁过少。\n2. 调整组织分割的参数（如减小面积阈值），以便从切片中提取更多的有效组织补丁。\n3. 检查数据集中每个切片的补丁数量分布（bag sizes），排除异常值。",[]]