[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-deepmedic--deepmedic":3,"tool-deepmedic--deepmedic":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 真正成长为懂上",155373,2,"2026-04-14T11:34:08",[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":64,"owner_name":72,"owner_avatar_url":73,"owner_bio":74,"owner_company":75,"owner_location":75,"owner_email":75,"owner_twitter":75,"owner_website":75,"owner_url":76,"languages":77,"stars":82,"forks":83,"last_commit_at":84,"license":85,"difficulty_score":86,"env_os":87,"env_gpu":88,"env_ram":89,"env_deps":90,"category_tags":98,"github_topics":99,"view_count":32,"oss_zip_url":75,"oss_zip_packed_at":75,"status":17,"created_at":105,"updated_at":106,"faqs":107,"releases":136},7488,"deepmedic\u002Fdeepmedic","deepmedic","Efficient Multi-Scale 3D Convolutional Neural Network for Segmentation of 3D Medical Scans","DeepMedic 是一款专为生物医学领域设计的高效开源工具，旨在利用深度学习技术对三维医疗扫描图像（如 MRI）进行精准的病灶分割。它主要解决了传统方法在处理复杂、多尺度的三维医学影像时精度不足或效率低下的难题，能够帮助研究人员快速构建并训练三维卷积神经网络，自动识别并勾勒出感兴趣的结构区域。\n\n这款工具特别适合医学影像领域的研究人员、算法工程师以及需要处理 NIFTI 格式数据的开发者使用。其核心亮点在于独特的“多尺度”网络架构，通过并行的卷积通路同时捕捉图像的局部细节与全局上下文信息，从而显著提升了对脑部病变等微小结构的分割准确率。此外，DeepMedic 支持数据增强、在线标准化以及与 TensorFlow 的无缝集成，并允许用户通过配置文件灵活调整模型参数。作为曾在多项权威研究中验证过的成熟框架，DeepMedic 降低了高性能三维分割网络的使用门槛，是探索医学图像分析的理想起点。","DeepMedic\n=====================================\n\n### News\n\nJan 2021 (v0.8.4):\n* Backend capable of receiving input files (images, labels, roi masks) via csv dataframe. (not yet used though)\n* Refactored front end modules for easier readability.\n\n29 May 2020 (v0.8.3):\n* Reverted back to old algorithm (pre-v0.8.2) for getting down-sampled context, to preserve exact behaviour. \n* Models trained with v0.8.3 should now be fully compatible with versions v0.8.1 and before.\n\n26 Apr 2020 (v0.8.2):\n* Major codebase changes for compatibility with Tensorflow 2.0.0 (and TF1.15.0) (not Eager yet).\n* Redesign\u002Frefactor of .\u002Fdeepmedic\u002Fneuralnet modules.\n* Improved sampling (faster when multiclass) and logging.\n* Changes to configs: ModelConfig: kernelDimFor1stFcLayer -> kernelDimPerLayerFC, new padTypePerLayerFC.\n\n14 Nov 2019 (v0.8.0):\n* Logging metrics to Tensorboard.\n* Capability to normalize input on-the-fly (Disabled by default). Only z-score norm for now.\n* Refactoring & aesthetics in training, testing and sampling.\n\n11 June 2019 (v0.7.4):\n* Added augmentation via affine transforms, rotation & scaling. Off by default (slows down training).\n* Redistribute samples of non-existent class & code refactoring in sampling.\n* Added a wider DM model config, seems to work better in a few studies.\n\n19 Mar 2019 (v0.7.3):\n* Default sampling for training now done on a per-class basis. Better now that DM is applied for arbitrary tasks.\n\n16 Mar 2019 (v0.7.2):\n* Batch size now in trainConfig and testConfig, not model.\n* Improved handling of hunging parallel processes.\n* Modularized augmentation, for further extensions.\n\n11 Feb 2019 (v0.7.1):\n* Multiprocessing changed from pp to python's builtin module.\n* Default suggested python switched to python3.\n* Updated default config with non normalized momentum.\n* Code for sampling partial cleanup.\n\n27 June 2018 (v0.7.0):\n* Back end changed to TensorFlow.\n* API\u002Fcommand line options changed slightly. Documentation updated accordingly.\n* Updated the default config in .\u002Fexamples\u002Fconfig\u002Fdeepmedic with three pathways.\n* Refactored\u002Freorganized the code.\n\n\n### Introduction\n\nThis project aims to offer easy access to Deep Learning for segmentation of structures of interest in biomedical 3D scans. It is a system that allows the easy creation of a 3D Convolutional Neural Network, which can be trained to detect and segment structures if corresponding ground truth labels are provided for training. The system processes NIFTI images, making its use straightforward for many biomedical tasks.\n\nThis document describes how to install and run the software. Accompanying data are provided to run the preset examples and make sure that the system is functioning on your system. This document also describes the main functionality, in order for the user to understand the main processing cycle. For greater details please consult [1]. We hope this project will serve well in making the state-of-the-art Convolutional Networks more accessible in the field of medical imaging.\n\n#### Citations\n\nThe system was initially developed for the segmentation of brain lesions in MRI scans. It was employed for our research presented in [1],[2], where a 3D network architecture with two convolutional pathways was presented for the efficient multi-scale processing of multi-modal MRI volumes. If the use of the software positively influences your endeavours, please cite [1].\n\n[1] **Konstantinos Kamnitsas**, Christian Ledig, Virginia F.J. Newcombe, Joanna P. Simpson, Andrew D. Kane, David K. Menon, Daniel Rueckert, and Ben Glocker, “[Efficient Multi-Scale 3D CNN with Fully Connected CRF for Accurate Brain Lesion Segmentation][paper1]”, *Medical Image Analysis, 2016*.\n\n[2] **Konstantinos Kamnitsas**, Liang Chen, Christian Ledig, Daniel Rueckert, and Ben Glocker, “[Multi-Scale 3D CNNs for segmentation of brain Lesions in multi-modal MRI][paper2]”, *in proceeding of ISLES challenge, MICCAI 2015*.\n\n\n### Table of Contents\n* [1. Installation and Requirements](#1-installation-and-requirements)\n  * [1.1. Required Libraries](#11-required-libraries)\n  * [1.2. Installation](#12-installation)\n  * [1.3. GPU Processing](#14-gpu-processing)\n  * [1.4. Required Data Pre-Processing](#13-required-data-pre-processing)\n* [2. Running the Software](#2-running-the-software)\n  * [2.1 Training a tiny CNN - Making sure it works](#21-training-a-tiny-cnn---making-sure-it-works)\n  * [2.2 Running it on a GPU](#22-running-it-on-a-gpu)\n* [3. How it works](#3-how-it-works)\n  * [3.1 Architecture](#31-specifying-model-architecture)\n  * [3.2 Training](#32-training)\n  * [3.3 Testing](#33-testing)\n* [4. How to run DeepMedic on your data](#4-how-to-run-deepmedic-on-your-data)\n* [5. Concluding](#5-concluding)\n* [6. Licenses](#6-licenses)\n\n### 1. Installation and Requirements\n\n#### 1.1. Required Libraries\n\nThe system requires the following:\n- [Python](https:\u002F\u002Fwww.python.org\u002Fdownloads\u002F): Python 3 by default (works for python 2, but no future guarantees).\n- [TensorFlow](https:\u002F\u002Fwww.tensorflow.org\u002F): The Deep Learning library for back end.\n- [NiBabel](http:\u002F\u002Fnipy.org\u002Fnibabel\u002F): The library used for loading NIFTI files.\n- [numpy](http:\u002F\u002Fwww.numpy.org\u002F) : General purpose array-processing package.\n- [scipy](http:\u002F\u002Fwww.scipy.org\u002F) : Scientific packages. Used for image operations e.g. augmentation.\n\n#### Latest versions tested:  \nAs of Jan 2021, v0.8.4 was tested using Python 3.6.5, Tensorflow 2.0.0 and Tensorflow 1.15.0, nibabel 3.0.2, numpy 1.18.2.  \n\n#### 1.2. Installation\n(The below are for unix systems, but similar steps should be sufficient for Windows.)\n\nThe software cloned with:\n```\ngit clone https:\u002F\u002Fgithub.com\u002FKamnitsask\u002Fdeepmedic\u002F\n```\nAfter cloning it, all dependencies can be installed as described below.\n\n#### Install using a Conda Environment\n\nIf you do not have sudo\u002Froot privileges on a system, we suggest you install using Conda.\nFrom a **bash shell**, create a conda environment in a folder that you wish.\n\n```bash\nconda create -p FOLDER_FOR_ENVS\u002Fve_dm_tf python=3.6.5 -y\nsource activate FOLDER_FOR_ENVS\u002Fve_dm_tf\n```\n\n\n#### Install TensorFlow and DeepMedic\n\n**Install TensorFlow** (TF): Please follow instructions on (https:\u002F\u002Fwww.tensorflow.org\u002Finstall\u002F).\nBy consulting the previous link, ensure that your system has **CUDA** version and **cuDNN** versions compatible with the tensorflow version you are installing.\n```cshell\n$ pip install tensorflow-gpu==2.6.2\n$ pip install cudnn==8.2.1\n```\n\n**Install DeepMedic** and rest of its dependencies:\n```cshell\n$ cd DEEPMEDIC_ROOT_FOLDER\n$ pip install .\n```\nThis will grab rest of dependencies described in Sec.1.\n\n**Note:** The most common installation issue is when users do not install compatible versions of **Python**, **TF**, and **cudnn**.\nYou need versions that are compatible with each other:\nEach Python version has specific pre-compiled TF versions. We need TF version 2.0+, and each TF versionis compatible with \nspecific cudnn versions (see TF docs). We need Cudnn that is compatible with TF and your system's Nvidia drivers.\nWe have tested DeepMedic for **Python=3.6.5**, **TF=2.6.2**, and **cudnn=8.2.1**, which should work in **2024**.\n\n#### 1.3. GPU Processing\n\n#### Install CUDA: (Deprecated)\n\n**Note:** This step may not be required anymore, because recent cudnn versions (installed via conda above) install rest\n of the required libraries. As long as you have installed GPU drivers, cudnn tends to install the rest. \n But in case this is not true, have a look at the following.\n\nSmall networks can be run on the cpu. But 3D CNNs of considerable size require processing on the GPU. For this, an installation of [Nvidia’s CUDA](https:\u002F\u002Fdeveloper.nvidia.com\u002Fcuda-toolkit) is\n needed. Make sure to acquire a version compatible with your GPU drivers. TensorFlow needs to be able to find CUDA’s compiler, the **nvcc**, in the environment’s path. It also dynamically links to **cublas.so** libraries, which need to be visible in the environment’s.\n\nPrior to running DeepMedic on the GPU, you must manually add the paths to the folders containing these files in your environment's variables. As an example in a *bash* shell:\n\n```cshell\n$ export CUDA_HOME=\u002Fpath\u002Fto\u002Fcuda                   # If using cshell instead of bash: setenv CUDA_HOME \u002Fpath\u002Fto\u002Fcuda\n$ export LD_LIBRARY_PATH=\u002Fpath\u002Fto\u002Fcuda\u002Flib64\n$ export PATH=\u002Fpath\u002Fto\u002Fcuda\u002Fbin:$PATH\n```\n\n\n#### 1.4. Required Data Pre-Processing\n\n* DeepMedic processes **NIFTI files** only. All data should be in the *.nii* format.\n\n* The input modalities, ground-truth labels, ROI masks and other **images of each subject need to be co-registered** (per-subject, no need for inter-subject registration). \n\n* The images of each subject should **have the same dimensions** (per subject, no need for whole database). This is, the number of voxels per dimension must be the same for all images of a subject. \n\n* **Resample all images in the database to the same voxel size**. The latter is needed because the kernels (filters) of the DeepMedic need to correspond to the same real-size patterns (structures) **for all subjects**.\n\n* Make sure that the **ground-truth labels** for training and evaluation represent the background with zero. The system also assumes that the task’s classes are indexed increasing by one (not 0,10,20 but 0,1,2).\n\n* **You are strongly advised to normalize the intensity of the data within the ROI to a zero-mean, unit-variance space**. Our default configuration significantly underperforms if intensities are in another range of values.\n\n**Note for large images**: Large 3D CNNs are computationally expensive. Consider downsampling the images or reducing the size of the network if you encounter computational difficulties. The default configuration of DeepMedic was applied on scans of size around 200x200x200. \n\n\n### 2. Running the Software\n\nThe source code of the DeepMedic is provided in the folder [deepmedic](deepmedic\u002F). Users should not need to touch this folder. The software comes with a command line interface, [deepMedicRun](deepMedicRun). Running it with the help option:\n```cshell\n.\u002FdeepMedicRun -h\n```\nbrings up the available actions for the creation, training and testing of CNN models. All actions require a large number of configuration parameters, which are read from configuration files. \n\nIn the [examples\u002FconfigFiles](examples\u002FconfigFiles\u002F) folder we provide two sets of configuration files. Firstly, the configuration of a very small network is given in [examples\u002FconfigFiles\u002FtinyCnn\u002F](examples\u002FconfigFiles\u002FtinyCnn\u002F). This network can be trained within minutes on a CPU. It's a simple example [to make sure everything works](#21-training-a-tiny-cnn---making-sure-it-works). We also provide the full configuration of the DeepMedic model, as employed in [[1](#citations)], in the folder [examples\u002FconfigFiles\u002FdeepMedic\u002F](examples\u002FconfigFiles\u002FdeepMedic\u002F).\n\nThe above configuration files are pre-set to point to accompanying .nii files, provided in [examples\u002FdataForExamples\u002F](examples\u002FdataForExamples\u002F). Those NIFTIs serve as input to the networks in our examples. This data are modified versions of images from the Brain Tumor Segmentation challenge ([BRATS 2015](http:\u002F\u002Fbraintumorsegmentation.org\u002F)).\n\n\n#### 2.1 Training a tiny CNN - Making sure it works\n\nWe will here train a tiny CNN model and make sure everything works as expected. Further explanations on the use of the software are provided in the next section.\n\nNOTE: First see [Section 1.2](#12-installation) for installation of the required packages. \n\nLets **train** a model:\n```cshell\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FtinyCnn\u002Fmodel\u002FmodelConfig.cfg \\\n               -train examples\u002FconfigFiles\u002FtinyCnn\u002Ftrain\u002FtrainConfigWithValidation.cfg\n```\n\nThis command parses the given model-configuration file that defines the architecture and creates the corresponding CNN model. It then parses the training-config that specifies metaparameters for the training scheme. The folder `.\u002Fexamples\u002Foutput\u002F` should have been created by the process, where all output is saved. The model will then be trained for two epochs. All output of the process is logged for later reference. This should be found at `examples\u002Foutput\u002Flogs\u002FtrainSessionWithValidTiny.txt`. After each epoch the trained model is saved at `examples\u002Foutput\u002Fsaved_models\u002FtrainSessionWithValidTiny`. Tensorflow saves the model in form of **checkpoint** files. You should find `.\u002Fexamples\u002Foutput\u002FcnnModels\u002FtinyCnn.initial.DATE+TIME.model.ckpt.[data..., index]` created after each epoch. Each **set** of `DATE+TIMEmodel.ckpt[data,index]` is refered to as one checkpoint, i.e. a saved model. Finally, after each epoch, the model performs segmentation of the validation images and the segmentation results (.nii files) should appear in `examples\u002Foutput\u002Fpredictions\u002FtrainSessionWithValidTiny\u002Fpredictions\u002F`. If the training finishes normally (should take 5 mins) and you can see the mentioned files in the corresponding folders, beautiful. Briefly rejoice and continue... \n\nYou can **plot the training progress** using an accompanying script, which parses the training logs:\n```\npython plotTrainingProgress.py examples\u002Foutput\u002Flogs\u002FtrainSessionWithValidTiny.txt -d\n```\nMoreover, by default (variable `tensorboard_log=True` in train-config) the training & validation metrics are also logged for visualisation via **TensorBoard**. Required log-files found at `examples\u002Foutput\u002Ftensorboard\u002FtrainSessionWithValidTiny` (non-human readable). See [Tensorboard documentation](https:\u002F\u002Fwww.tensorflow.org\u002Ftensorboard\u002Fget_started) for its use. TensorBoard can be activated via the following command:\n```\ntensorboard --logdir=.\u002Fexamples\u002Foutput\u002Ftensorboard\u002FtrainSessionWithValidTiny\n```\n\nNow lets **test** with the trained model (replace *DATE+TIME*):\n```cshell\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FtinyCnn\u002Fmodel\u002FmodelConfig.cfg \\\n               -test .\u002Fexamples\u002FconfigFiles\u002FtinyCnn\u002Ftest\u002FtestConfig.cfg \\\n               -load .\u002Fexamples\u002Foutput\u002Fsaved_models\u002FtrainSessionWithValidTiny\u002FtinyCnn.trainSessionWithValidTiny.final.DATE+TIME.model.ckpt\n```\nOf course replace `DATE+TIME` accordingly.\n\nNote that we specify which previously-trained model\u002Fcheckpoint to load parameters from with the `-load` option. **But please note**, the path given does NOT correspond neither to the `data` nor `index` file. It rather needs to refer to the checkpoint set (i.e., **should end with** `.model.ckpt`). Tensorflow's loader peculiarity. This process should perform segmentation of the testing images and the results should appear in `examples\u002Foutput\u002Fpredictions\u002FtestSessionTiny\u002F` in the `predictions` folder. In the `features` folder you should also find some files, which are feature maps from the second layer. DeepMedic gives you this functionality (see testConfig.cfg). If the testing process finishes normally and all output files seem to be there, **everything seems to be working!** *On the CPU*... \n\n#### 2.2 Running it on a GPU\n\nNow lets check the important part... If using the **DeepMedic on the GPU** is alright on your system. First, delete the `examples\u002Foutput\u002F` folder for a clean start. Now, most importantly, place the path to **CUDA**'s *nvcc* into your *PATH* and to the *cublas.so* in your *LD_LIBRARY_PATH* (see [section 1.3](#13-gpu-processing))\n\nYou need to perform the steps we did before for training and testing with a model, but on the GPU. To do this, repeat the previous commands and pass the additional option `-dev cuda`. For example: \n\n```cshell\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FtinyCnn\u002Fmodel\u002FmodelConfig.cfg \\\n               -train .\u002Fexamples\u002FconfigFiles\u002FtinyCnn\u002Ftrain\u002FtrainConfigWithValidation.cfg \\\n               -dev cuda0\n```\n\nYou can replace 0 to specify another device number, if your machine has multiple GPUs. The processes should result in similar outputs as before. **Make sure the process runs on the GPU**, by running the command `nvidia-smi`. You should see your python process assigned to the specified GPU. If all processes finish as normal and you get no errors, amazing. **Now it seems that really everything works :)** Continue to the next section and find more details about the DeepMedic and how to use the large version of our network!\n\n**Possible problems with the GPU**: If TensorFlow does not find correct versions for **CUDA** and **cuDNN** (depends on TensorFlow version), it will fall back to the CPU version by default. If this happens, right after the model creation and before the main training process starts, some warnings will be thrown by TensorFlow, along the lines below:\n```\n2018-06-06 14:39:34.036373: I tensorflow\u002Fcore\u002Fplatform\u002Fcpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA\n2018-06-06 14:39:35.676554: E tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_driver.cc:406] failed call to cuInit: CUDA_ERROR_NO_DEVICE\n2018-06-06 14:39:35.676616: I tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_diagnostics.cc:158] retrieving CUDA diagnostic information for host: neuralmedic.doc.ic.ac.uk\n2018-06-06 14:39:35.676626: I tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_diagnostics.cc:165] hostname: neuralmedic.doc.ic.ac.uk\n2018-06-06 14:39:35.676664: I tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_diagnostics.cc:189] libcuda reported version is: 384.111.0\n2018-06-06 14:39:35.676699: I tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_diagnostics.cc:193] kernel reported version is: 384.111.0\n2018-06-06 14:39:35.676708: I tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_diagnostics.cc:300] kernel version seems to match DSO: 384.111.0\n```\n\nIf the process does not start on the GPU as required, please ensure you have *CUDA* and *cuDNN* versions that are compatible with the TF version you have (https:\u002F\u002Fwww.tensorflow.org\u002Finstall), and that you environment variables are correctly setup. See Section 1.4 about some pointers, and the *CUDA* website.\n\n\n### 3. How it works\n\nPreviously we briefly discussed how to quickly run a pre-set example with a tiny CNN, just so you can check whether everything works on your system. In this section we will go through the process in a bit more detail. We also explain the main parameters that should be specified in the configuration files, in order for you to tailor the network and process to your needs. \n\nThe **.cfg configuration files** in `examples\u002FconfigFiles\u002FdeepMedic\u002F` holds the parameters for creating and training DeepMedic. In an attempt to support a broader range of applications and users, the config files in `examples\u002FconfigFiles\u002FdeepMedic\u002F` are gradually updated with components that seem to improve the overall performance of the system. (Note: These parameters are similar but not same as what was used in our work in [[1](#citations)]. Original config as used in the paper can be found in archived github-branch 'dm_theano_v0.6.1_depr')\n\n**_Note:_** The config files are parsed as python scripts, thus follow **python syntax**. Any commented-out configuration variables are internally given **default values**.\n\n#### 3.1. Specifying Model Architecture\n\nWhen performing training or testing, we need to define the architecture of the network. For this, we point to a model-config file, using the option `-model` :\n```\n-model .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Fmodel\u002FmodelConfig.cfg\n```\n\nAfter reading the parameters given in modelConfig.cfg, the graph of a network is created internally. The session prints all parameters that are used for the model-creation on the screen and to the log.txt file. \n\n**Parameters for defining Network Architecture**\n\n![alt text](documentation\u002FdeepMedic.png \"Double pathway CNN for multi-scale processing\")\nFigure 1: An example of a double-pathway architecture for multi-scale processing. At each layer, the number and size of feature maps (FMs) is depicted in the format (*Number-Of-FMs x Dimensions*). Actual DeepMedic has 11 layers by default.\n\nThe main parameters to specify the CNN model are the following.\n\n*Generic:*\n\n- modelName: This is used for **naming the checkpoints when saving** every epoch of training. Change it to distinguish between architectures.\n- folderForOutput: The main output folder. Saved model and logs will be placed here.\n\n*Task Specific:*\n\n- numberOfOutputClasses: DeepMedic is multiclass system. This number should **include the background**, and defines the number of FMs in the last, classification layer (=2 in Fig.1)\n- numberOfInputChannels: Specify the number of modalities\u002Fsequences\u002Fchannels of the scans.\n\n*Architecture:*\n\n- numberFMsPerLayerNormal: A list which needs to have as many entries as the number of layers in the normal pathway that  we want to create. Each entry is a number, which defines the number of feature-maps in the corresponding layer ([30, 40, 40, 50] in fig1)\n- kernelDimPerLayerNormal: The dimensions of the kernels per layer. ([[5,5,5], [5,5,5], [5,5,5], [5,5,5]] in Fig.1.) \n- useSubsampledPathway: Setting this to “True” creates a subsampled-pathway, with the same architecture as the normal one. “False” for single-scale processing with the normal pathway only. Additional parameters allow tailoring this pathway further.\n- numberFMsPerLayerFC: The final layers of the high and low resolution pathways are contatenated. The concatenated feature maps are then processed by a Final Classification (FC) pathway. This parameter allows the addition of hidden layers in the FC path before the classification layer. The number of entries specifies how many hidden layers. The number of each entry specifies the number of FMs in each layer. Final classification layer is not included ([[150], [150]] in Fig.1).\n\n*Image Segments and Batch Sizes:*\n\n- segmentsDim(Train\u002FVal\u002FInference): The dimensions of the input-segment. Different sizes can be used for training, validation, inference (testing). Bigger sizes require more memory and computation. Training segment size greatly influences distribution of training samples ([25,25,25] in Fig.1). Validation segments are by default as large as the receptive field (one patch). Size of testing-segments only influences speed.\n- Batch Size : The number of segments to process simultaneously on GPU. In training, bigger batch sizes achieve better convergence and results, but require more computation and memory. Batch sizes for Validation and Inference are less important, greater once just speedup the process.\n\nMore variables are available, but are of less importance (regularization, optimizer, etc). They are described in the config files of the provided examples. \n\n\n#### 3.2. Training\n\nYou train a model using your manually segmented, ground-truth annotations. For this, you need to point to a configuration file with the parameters of the training session. We use the `-model` option, that defines a network architecture, together with the `-train` option, that points to a training-config files, that specifies parameters about the training scheme and the optimization:\n```\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Fmodel\u002FmodelConfig.cfg \\\n               -train .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Ftrain\u002FtrainConfig.cfg \\\n               -dev cuda0\n```\nNote that you can change 0 with another number of a GPU device, if your machine has **multiple GPUs**.\n\n\n**The Training Session**\n\nDuring a training session, the following cycle is followed:\n```\nFor each epoch {\n\tFor each subepoch {\n\t\tLoad Validation Cases\n\t\tExtract Validation Segments\n\t\tPerform Validation-On-Samples (in batches)\n\n\t\tLoad Training Cases\n\t\tExtract Training Segments\n\t\tPerform Training (in batches)\n\n\t\tReport Accuracy over subepoch’s samples (Val\u002FTrain).\n\t}\n\tReport Accuracy over whole epoch (Val\u002FTrain)\n\tLower Learning Rate if required.\n\tSave the model’s state\n\n\tPerform Full-Inference on Validation Cases (every few epochs)\n\tReport DSC of full inference\n\tSave predictions from Full-Inference (segm.\u002Fprob.maps\u002Ffeatures)\n}\n```\nThe validation on samples and the full segmention of the scans of validation subjects are optional.\n\n\n**Plotting Training Progress via MatPlotLib**\n\nThe progress of training can be plotted by using the accompanying `plotTrainingProgress.py` script, which parses the training logs for the reported validation and training accuracy metrics. A common usage example is:\n```\npython plotTrainingProgress.py examples\u002Foutput\u002Flogs\u002FtrainSession\\_1.txt examples\u002Foutput\u002Flogs\u002FtrainSession\\_2.txt \\\n       -d -m 20 -c 1\n```\nTry option `-h` for help. Here, two logs\u002Fexperiments are specified, to plot metrics for both to compare. Any number is allowed. `-d` requests a *detailed* plot with more metrics. `-m 20` runs a moving average over 20 subepochs for smoothing the curves. `-c 1` requests plotting class with label=1. Note that in case of multiple labels, `-c 0` actually reports the metrics NOT for the background class (as we did not find this useful in most applications), but rather for the *whole-foreground* class, which can be imagined as if all labels except 0 (assumed background) are fused into one.\n\nMetrics logged are both from training and validation. Most are computed on *samples* (which are *sub-volumes*, aka patches). Exception is the *DSC-on-whole-scans* (aka *full-segm*), that is computed by segmenting the whole validation volumes every few epochs (if specified).\n\n\n**Plotting Training Progress via TensorBoard**\n\nMoreover, if the train-config file specifies this functionality enabled (variable `tensorboard_log=True` in the train-config-files), training metrics are also logged such that they can be visualised using Tensorflow's **TensorBoard**. See [Tensorboard documentation](https:\u002F\u002Fwww.tensorflow.org\u002Ftensorboard\u002Fget_started) for use. The files that keep logged metrics in the required format for TensorBoard are at `examples\u002Foutput\u002Ftensorboard\u002Fname-of-training-session\u002F`. It can be activated via the command:\n```\ntensorboard --logdir=.\u002Fexamples\u002Foutput\u002Ftensorboard\u002Fname-of-training-session\n```\nMetrics logged for tensorboard are the same as those logged in the main log .txt file and visualised via the above described script. \n\n\n**Resuming an Interrupted Training Session**\n\nA training session can be interrupted for various reasons. Because of this, the **state of the model is saved in the end of each epoch** and can be found in the output folder. Except for its trainable kernels, we also save the state of the optimizer and parameters of the training session (eg number of epochs trained, current learning rate) in order to be able to seamlessly continue it. **An interrupted training session can be continued** similarly to how it was started, but by additionally specifying the saved model checkpoint where to load trained parameters and continue from:\n\n```\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Fmodel\u002FmodelConfig.cfg \\\n               -train .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Ftrain\u002FtrainConfig.cfg \\\n               -load .\u002Fexamples\u002Foutput\u002Fsaved_models\u002FtrainSessionDm\u002FdeepMedic.trainSessionDm.DATE+TIME.model.ckpt \\\n               -dev cuda0\n```\nAlternatively, the checkpoint can be defined in the trainConfig file. Importantly, the path must NOT point to the .index or .data files. **It must be ending with the .model.ckpt**, so that the loader can then find the matching .index and .data files.\n\n**Pre-Trained Models, fine-tuning**\n\nCommon practice with neural networks is to take a network pre-trained on one task\u002Fdatabase, and fine-tune it for a new task by training on a second database. This can be naturally done pointing to the pretrained network's checkcpoint (`-load`) and its architecture (`-model`) when starting to train. Very importantly though, one may need to *reset the state of the trainer* at the beginning of the fine-tuning, secondary session. Without this, the trainer will still have a saved state (number of epochs trained, velocities of momentum, learning rate etc) from the first training session. All these parameters can be reset, so that they are reinitialized by the new training-session configuration simply with the `-resetopt` option, as follows:\n```\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Fmodel\u002FmodelConfig.cfg \\\n               -train .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Ftrain\u002FtrainConfigForRefinement.cfg \\\n               -load .\u002Fpath\u002Fto\u002Fpretrained\u002Fnetwork\u002Ffilename.DATE+TIME.model.ckpt \\\n               -resetopt \\\n               -dev cuda0\n```\n\n**Training Parameters**\n\n*Generic Parameters:*\n\n- sessionName: The name of the session. Used to save the trained models, logs and results.\n- folderForOutput: The main output folder.\n- cnnModelFilePath: path to a saved CNN model (in case one wants to resume training. Disregarded if -load is used.).\n- tensorboard_log: Specifies (True\u002FFalse) whether to log metrics for visualisation (See Section 3.2) via Tensorboard (takes space on disk).\n\n*Input for Training:*\n\n- channelsTraining: For each of the input channels, this list should hold one entry. Each entry should be a path to a file. These files should list the paths to the corresponding channels for each of the training subjects. See the pre-set files given in the examples and all these should easily become clear.\n- gtLabelsTraining: the path to a file. That file should list the paths to the ground-truth labels for all training subjects.\n- roiMasksTraining: In many tasks we can easily define a Region Of Interest and get a mask of it. For instance by excluding the air in a body scan, or take the brain-mask in a brain scan. In this case, this parameter allows pointing to the roi-masks for each training subject. Sampling or inference will not be performed outside this area, focusing the learning capacity of the network inside it. If this is not available, detete or comment this variable out and sampling will be performed on whole volumes.\n\n*Training Cycle:*\n\n- numberOfEpochs: Total number of epochs until the training finishes.\n- numberOfSubepochs: Number of subepochs to run per epoch\n- numOfCasesLoadedPerSubepoch: At each subepoch, the images from maximum that many cases are loaded to extract training samples. This is done to allow training on databases that may have hundreds or thousands of images, and loading them all for sample-extraction would be just too expensive.\n- numberTrainingSegmentsLoadedOnGpuPerSubep: At every subepoch, we extract in total this many segments, which are loaded on the GPU in order to perform the optimization steps. Number of optimization steps per subepoch is this number divided by the batch-size-training (see model-config). The more segments, the more GPU memory and computation required.\n- batchsize_train: Size of a training batch. The bigger, the more gpu-memory is required.\n- num_processes_sampling: Samples needed for next validation\u002Ftrain can be extracted in parallel while performing current train\u002Fvalidation on GPU. Specify number of parallel sampling processes.\n\n\n*Learning Rate Schedule:*\n\n- typeOfLearningRateSchedule : Schedules to lower the Learning Rate with. 'stable' keeps LR constant. 'predef' lowers it at predefined epochs, requiring the user to specify at which epochs to lower LR. Auto lowers LR when validation accuracy plateaus (unstable).  'poly' slowly lowers LR over time. We advice to use constant LR, observe progress of training by plotting it (see above), and lower LR manually when improvement plateaus by creating your own 'predef' schedule. Otherwise, use 'poly', but make sure that training is long enough for convergence, by experimenting a bit with the total number of training epochs.\n\n*Data Augmentation:*\n\n- reflectImagesPerAxis: Specify whether you d like the images to be randomly reflected in respect to each axis, for augmentation during training.\n- performIntAugm: Randomly apply a change to segments’ intensities: I' = (I + shift) * multi\n\n*Validation:*\n\n- performValidationOnSamplesThroughoutTraining, performFullInferenceOnValidationImagesEveryFewEpochs: Booleans to specify whether we want to perform validation, since it is actually time consuming.\n- channelsValidation, gtLabelsValidation, roiMasksValidation: Similar to the corresponding training entries. If default settings for validation-sampling are enabled, sampling for validation is done in a uniform way over the whole volume, to achieve correct distribution of the classes.\n- numberValidationSegmentsLoadedOnGpuPerSubep: on how many validation segments (samples) to perform the validation.\n- numberOfEpochsBetweenFullInferenceOnValImages: Every how many epochs to perform full-inference validation. It might be slow to process all validation cases often.\n- namesForPredictionsPerCaseVal: If full inference is performed, we may as well save the results to visually check progress. Here you need to specify the path to a file. That file should contain a list of names, one for each case, with which to save the results. Simply the names, not paths. Results will be saved in the output folder.\n\n#### 3.3. Testing\n\nWhen a training epoch is finished, the model’s state is saved. These models can be used for segmenting previously unseen scans. A testing configuration file has to be specified. Testing can be started in two ways.\n\na) A model is specified straight from the command line.\n```\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Fmodel\u002FmodelConfig.cfg \\\n               -test .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Ftest\u002FtestConfig.cfg \\\n               -load .\u002Fpath-to-saved-model\u002Ffilename.model.ckpt \\\n               -dev cuda0\n```\n\nb) The path to a saved model can be instead specified in the testing config file, and then the `-load` option can be ommited. **Note:** A file specified by `-load` option overrides any specified in the config-file.\n\nAfter the model is loaded, inference will be performed on the testing subjects. Predicted segmentation masks, posterior probability maps for each class,  as well as the feature maps of any layer can be saved. If ground-truth is provided, DeepMedic will also report DSC metrics for its predictions.\n\nNote that this testing procedure is similar to the full-inference procedure performed on validation subjects every few training epochs.\n\n**Testing Parameters**\n\n*Main Parameters:*\n\n- sessionName: The name for the session, to use for saving the logs and inference results.\n- folderForOutput: The output folder to save logs and results.\n- cnnModelFilePath: The path to the cnn model to use. Disregarded if specified from command line.\n- channels: List of paths to the files that list the files of channels per testing case. Similar to the corresponding parameter for training.\n- namesForPredictionsPerCase: Path to a file that lists the names to use for saving the prediction for each subject.\n- roiMasks: If masks for a restricted Region-Of-Interest can be made, inference will only be performed within it. If this parameter is omitted in the config file, whole volume is scanned.\n- gtLabels: Path to a file that lists the file-paths to Ground Truth labels per case. Not required for testing, but if given, DSC accuracy metric is reported.\n\n*Saving Predictions:*\n\n- saveSegmentation, saveProbMapsForEachClass : Specify whether you would like the segmentation masks and the probability maps of a class saved.\n\n*Saving Feature Maps:*\n\n- saveIndividualFms, saveAllFmsIn4DimImage : Specify whether you would like the feature maps saved. Possible to save each FM in a separate files, or create a 4D file with all of them. Note that FMs are many and the 4D file can be several hundreds of MBs, or GBs.\n- minMaxIndicesOfFmsToSaveFromEachLayerOfABCPathway : Because the number of FMs is large, it is possible to specify particular FMs to save. Provide the minimum (inclusive) and maximum (exclusive) index of the FMs of the layers that you would like to save (indexing starts from 0).\n\n\n### 4. How to run DeepMedic on your data\n\nThe **.cfg configuration files** in `examples\u002FconfigFiles\u002FdeepMedic\u002F` provides parameters for creating and training DeepMedic. These parameters are similar (but not same) as what was used in our work in [[1](#citations)] and our winning contribution for the ISLES 2015 challenge [2]. In order to support a broader range of applications and users, the config files in `examples\u002FconfigFiles\u002FdeepMedic\u002F` are gradually updated with components that seem to improve the overall performance of the system. (Note: Original config as used in the mentioned papers can be found in archived github-branch 'dm_theano_v0.6.1_depr')\n\nTo run the DeepMedic on your data, the following are the minimum steps you need to follow:\n\n**a)** **Pre-process your data** as described in Sec. [1.4](#14-required-data-pre-processing). Do not forget to normalise them to a zero-mean, unit-variance space. Produce ROI masks (for instance brain masks) if possible for the task.\n\n**b)** In the **modelConfig.cfg** file, change the variable `numberOfOutputClasses = 5` to the number of classes in your task (eg 2 if binary), and `numberOfInputChannels = 2` to the number of input modalities. Now you are ready to create the model via the `-newModel` option.\n\n**c)** (optional) If you want to train a bigger or smaller network, the easiest way is to increase\u002Fdecrease the number of Feature Maps per layer. This is done by changing the number of FMs in the variable `numberFMsPerLayerNormal = [30, 30, 40, 40, 40, 40, 50, 50]`.\n\n**d)** Before you train a network you need to alter the **trainConfig.cfg** file, in order to let the software know where your input images are. The variable `channelsTraining = [\".\u002FtrainChannels_flair.cfg\", \".\u002FtrainChannels_t1c.cfg\"]` is pre-set to point to two files, one for each of the input variables. Adjust this for your task. \n\n**e)** Create your files that correspond to the above `.\u002FtrainChannels_flair.cfg, trainChannels_t1c.cfg` files for your task. Each of these files is essentially a list. Every file has an entry for each of the training subjects. The entry is the path to the .nii file with the corresponding modality image for the subject. A brief look to the provided exemplary files should make things clear.\n\n**f)** Do the same process in order to point to the ground-truth labels for training via the variable `gtLabelsTraining = \".\u002FtrainGtLabels.cfg\"` and to ROI masks (if available) via `roiMasksTraining = \".\u002FtrainRoiMasks.cfg\"`.\n\n**g)** If you wish to periodically perform **validation** throughout training, similar to the above, point to the files of validation subjects via the variables `channelsValidation`, `gtLabelsValidation` and `roiMasksValidation`. If you do not wish to perform validation (it is time consuming), set to `False` the variables `performValidationOnSamplesThroughoutTraining`\nand `performFullInferenceOnValidationImagesEveryFewEpochs`.\n\n**h)** (optional) If you need to adjust the length of the training session, eg for a smaller network, easiest way is to lower the total number of epochs `numberOfEpochs=35`. You should also then adjust the pre-defined schedule via `predefinedSchedule`. Another option is to use a decreasing schedule for the learning rate, by setting `typeOfLearningRateSchedule = 'poly'`.\n\n**i)** **To test** a trained network, you need to point to the images of the testing subjects, similar to point d) for the training. Adjust the variable `channels = [\".\u002FtestChannels_flair.cfg\", \".\u002FtestChannels_t1c.cfg\"]` to point to the modalities of the test subjects. If ROI masks are available, point to them via `roiMasks` and inference will only be performed within the ROI. Else comment this variable out. Similarly, if you provide the ground-truth labels for the testing subjects via `gtLabels`, accuracy of the prediction will be calculated and the DSC metric will be reported. Otherwise just comment this variable out.\n\n**j)** Finally, you need to create a file, which will list names to give to the predictions for each of the testing subject. See entry `namesForPredictionsPerCase = \".\u002FtestNamesOfPredictionsSimple.cfg\"` and the corresponding pre-set file. After that, you are ready to test with a model.\n\nThe provided configuration of the DeepMedic takes roughly 2 days to get trained on an NVIDIA GTX Titan X. Inference on a standard size brain scan should take 2-3 minutes. Adjust configuration of training and testing or consider downsampling your data if it takes much longer for your task.\n\n### 5. Concluding\n\nWe hope that making this software publically available can accelerate adoption of Deep Learning in the field of Biomedical Image Processing and Analysis. It is still actively developed, so do take into account that it is far from modular and fully generic. In its current state, we believe it can serve as a helpful **baseline method** for the benchmarking of further learners, as well as a segmentation system for various pipelines. If you find our work has positively influenced yours, please cite our paper [1].\n\nI am well aware that much of the functionality is not fully modular and the API far from perfect. I hope to make DeepMedic a helpful tool for the community. So feel free to email me with your feedback or any issues at: **konstantinos.kamnitsas12@ic.ac.uk**\n\nBest wishes,\n\nKonstantinos Kamnitsas\n\n### 6. Licenses\n\nLicense for the DeepMedic software: BSD 3-Clause License. A copy of this license is present in the root directory.\n\nLicense for the data provided for the examples: Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Switzerland License. http:\u002F\u002Fcreativecommons.org\u002Flicenses\u002Fby-nc-sa\u002F3.0\u002Fch\u002Fdeed.en\n\n\n[\u002F\u002F]: # (reference links)\n\n   [paper1]: \u003Chttp:\u002F\u002Fwww.sciencedirect.com\u002Fscience\u002Farticle\u002Fpii\u002FS1361841516301839>\n\n   [paper2]: \u003Chttp:\u002F\u002Fwww.isles-challenge.org\u002FISLES2015\u002Farticles\u002Fkamnk1.pdf>\n","DeepMedic\n=====================================\n\n### 新闻\n\n2021年1月（v0.8.4）：\n* 后端现已支持通过CSV数据框接收输入文件（图像、标签、ROI掩膜），但目前尚未实际使用。\n* 重构了前端模块，以提高代码可读性。\n\n2020年5月29日（v0.8.3）：\n* 恢复使用旧算法（v0.8.2之前版本）来获取下采样上下文，以保持原有行为一致。\n* 使用v0.8.3训练的模型现在应与v0.8.1及更早版本完全兼容。\n\n2020年4月26日（v0.8.2）：\n* 对代码库进行了重大更改，以兼容TensorFlow 2.0.0（以及TF1.15.0）（尚未启用Eager模式）。\n* 重新设计\u002F重构了.\u002Fdeepmedic\u002Fneuralnet模块。\n* 改进了采样方式（多分类时速度更快）和日志记录。\n* 配置文件变更：ModelConfig中将kernelDimFor1stFcLayer改为kernelDimPerLayerFC，并新增padTypePerLayerFC。\n\n2019年11月14日（v0.8.0）：\n* 将指标记录到TensorBoard。\n* 具备实时归一化输入的功能（默认关闭）。目前仅支持z-score归一化。\n* 对训练、测试和采样流程进行了重构和优化。\n\n2019年6月11日（v0.7.4）：\n* 增加了基于仿射变换、旋转和缩放的数据增强功能，默认关闭（会降低训练速度）。\n* 重新分配不存在类别的样本，并对采样代码进行了重构。\n* 添加了更广泛的DM模型配置，在一些研究中表现更好。\n\n2019年3月19日（v0.7.3）：\n* 训练时的默认采样方式改为按类别进行。这使得在处理任意任务时，DM的应用效果更好。\n\n2019年3月16日（v0.7.2）：\n* 批量大小现位于trainConfig和testConfig中，而非model配置中。\n* 改进了对卡死并行进程的处理。\n* 数据增强模块化，便于后续扩展。\n\n2019年2月11日（v0.7.1）：\n* 多进程从pp切换为Python内置模块。\n* 默认推荐使用的Python版本改为Python3。\n* 更新了默认配置，去除了未归一化的动量项。\n* 对采样代码进行了部分清理。\n\n2018年6月27日（v0.7.0）：\n* 后端切换至TensorFlow。\n* API和命令行选项略有变化，文档相应更新。\n* 更新了.\u002Fexamples\u002Fconfig\u002Fdeepmedic中的默认配置，增加了三条路径。\n* 对代码进行了重构和重新组织。\n\n\n### 简介\n\n本项目旨在为生物医学3D扫描中感兴趣结构的分割提供便捷的深度学习工具。它是一个允许用户轻松构建3D卷积神经网络的系统，只要提供相应的真值标签用于训练，该网络即可被训练用来检测和分割目标结构。系统能够处理NIFTI格式的图像，因此在许多生物医学任务中使用起来非常直观。\n\n本文档将介绍如何安装和运行该软件，并附带示例数据，以便用户运行预设示例并验证系统是否能在其环境中正常工作。此外，本文档还描述了系统的主要功能，帮助用户理解整个处理流程。如需更多详细信息，请参阅[1]。我们希望该项目能有效提升医学影像领域中先进卷积网络的可及性。\n\n#### 引用文献\n\n该系统最初是为MRI扫描中脑部病变的分割而开发的。它被应用于我们的研究[1]、[2]中，其中提出了一种具有两条卷积路径的3D网络架构，用于高效地处理多模态MRI数据的多尺度特征。如果您在工作中使用了本软件并取得了积极成果，请引用[1]。\n\n[1] **Konstantinos Kamnitsas**, Christian Ledig, Virginia F.J. Newcombe, Joanna P. Simpson, Andrew D. Kane, David K. Menon, Daniel Rueckert, and Ben Glocker, “[高效多尺度3D CNN结合全连接CRF实现精确的脑部病变分割][paper1]”, *Medical Image Analysis, 2016*。\n\n[2] **Konstantinos Kamnitsas**, Liang Chen, Christian Ledig, Daniel Rueckert, and Ben Glocker, “[多尺度3D CNN用于多模态MRI中的脑部病变分割][paper2]”, *ISLES挑战赛论文集，MICCAI 2015*。\n\n\n### 目录\n* [1. 安装与要求](#1-installation-and-requirements)\n  * [1.1. 必要的库](#11-required-libraries)\n  * [1.2. 安装](#12-installation)\n  * [1.3. GPU加速](#14-gpu-processing)\n  * [1.4. 必要的数据预处理](#13-required-data-pre-processing)\n* [2. 运行软件](#2-running-the-software)\n  * [2.1 训练一个小型CNN——确保其正常工作](#21-training-a-tiny-cnn---making-sure-it-works)\n  * [2.2 在GPU上运行](#22-running-it-on-a-gpu)\n* [3. 工作原理](#3-how-it-works)\n  * [3.1 架构](#31-specifying-model-architecture)\n  * [3.2 训练](#32-training)\n  * [3.3 测试](#33-testing)\n* [4. 如何在您的数据上运行DeepMedic](#4-how-to-run-deepmedic-on-your-data)\n* [5. 总结](#5-concluding)\n* [6. 许可证](#6-licenses)\n\n### 1. 安装与要求\n\n#### 1.1. 必需库\n\n系统需要以下依赖：\n- [Python](https:\u002F\u002Fwww.python.org\u002Fdownloads\u002F)：默认使用 Python 3（虽然也支持 Python 2，但未来不再保证兼容性）。\n- [TensorFlow](https:\u002F\u002Fwww.tensorflow.org\u002F)：用于后端的深度学习框架。\n- [NiBabel](http:\u002F\u002Fnipy.org\u002Fnibabel\u002F)：用于加载 NIFTI 文件的库。\n- [numpy](http:\u002F\u002Fwww.numpy.org\u002F)：通用数组处理工具包。\n- [scipy](http:\u002F\u002Fwww.scipy.org\u002F)：科学计算库，用于图像操作，例如数据增强。\n\n#### 已测试的最新版本：\n截至 2021 年 1 月，v0.8.4 已在 Python 3.6.5、TensorFlow 2.0.0 和 TensorFlow 1.15.0、nibabel 3.0.2、numpy 1.18.2 环境下进行了测试。\n\n#### 1.2. 安装\n（以下步骤适用于 Unix 系统，Windows 用户也可参考类似流程。）\n\n软件可通过以下命令克隆：\n```\ngit clone https:\u002F\u002Fgithub.com\u002FKamnitsask\u002Fdeepmedic\u002F\n```\n克隆完成后，可按照如下说明安装所有依赖项。\n\n#### 使用 Conda 环境安装\n\n若您没有系统的 sudo\u002Froot 权限，建议使用 Conda 进行安装。在 **bash shell** 中，在您希望创建环境的文件夹下执行以下命令：\n\n```bash\nconda create -p FOLDER_FOR_ENVS\u002Fve_dm_tf python=3.6.5 -y\nsource activate FOLDER_FOR_ENVS\u002Fve_dm_tf\n```\n\n\n#### 安装 TensorFlow 和 DeepMedic\n\n**安装 TensorFlow**（TF）：请按照 (https:\u002F\u002Fwww.tensorflow.org\u002Finstall\u002F) 上的说明进行操作。\n参考上述链接，确保您的系统中安装的 **CUDA** 和 **cuDNN** 版本与您所安装的 TensorFlow 版本兼容。\n```cshell\n$ pip install tensorflow-gpu==2.6.2\n$ pip install cudnn==8.2.1\n```\n\n**安装 DeepMedic** 及其剩余依赖：\n```cshell\n$ cd DEEPMEDIC_ROOT_FOLDER\n$ pip install .\n```\n这将自动安装第 1 节中提到的所有依赖。\n\n**注意**：最常见的安装问题在于用户未安装兼容的 **Python**、**TF** 和 **cudnn** 版本。这些版本必须相互匹配：\n每个 Python 版本都有特定的预编译 TensorFlow 版本。我们需要 TensorFlow 2.0 及以上版本，而每个 TensorFlow 版本又与特定的 cuDNN 版本兼容（详见 TensorFlow 文档）。此外，cuDNN 还需与 TensorFlow 以及您系统的 Nvidia 驱动程序兼容。我们已在 **Python=3.6.5**、**TF=2.6.2** 和 **cudnn=8.2.1** 的环境下测试过 DeepMedic，这些配置应在 **2024** 年继续有效。\n\n#### 1.3. GPU 处理\n\n#### 安装 CUDA：（已弃用）\n\n**注意**：此步骤可能已不再必要，因为通过上述 Conda 安装的最新 cuDNN 版本会自动安装其余所需库。只要您已安装 GPU 驱动程序，cuDNN 通常会一并完成其他组件的安装。但如果未成功，请参考以下内容。\n\n小型网络可在 CPU 上运行。然而，较大规模的 3D CNN 则需要 GPU 处理。为此，需安装 [Nvidia 的 CUDA](https:\u002F\u002Fdeveloper.nvidia.com\u002Fcuda-toolkit)。请确保获取与您的 GPU 驱动程序兼容的版本。TensorFlow 需要在环境的路径中找到 CUDA 的编译器 **nvcc**，并动态链接到 **cublas.so** 库，这些库也需要在环境变量中可见。\n\n在使用 GPU 运行 DeepMedic 之前，您必须手动将包含这些文件的目录路径添加到环境变量中。以 *bash* shell 为例：\n\n```cshell\n$ export CUDA_HOME=\u002Fpath\u002Fto\u002Fcuda                   # 如果使用 cshell 而不是 bash：setenv CUDA_HOME \u002Fpath\u002Fto\u002Fcuda\n$ export LD_LIBRARY_PATH=\u002Fpath\u002Fto\u002Fcuda\u002Flib64\n$ export PATH=\u002Fpath\u002Fto\u002Fcuda\u002Fbin:$PATH\n```\n\n\n#### 1.4. 数据预处理要求\n\n* DeepMedic 仅处理 **NIFTI 文件**。所有数据应为 *.nii* 格式。\n\n* 每个受试者的输入模态、真值标签、ROI 掩码及其他图像需进行 **配准**（按受试者级别，无需跨受试者配准）。\n\n* 每个受试者的图像应具有 **相同的尺寸**（按受试者级别，无需对整个数据库统一）。即，同一受试者的所有图像在每个维度上的体素数必须一致。\n\n* 将数据库中的所有图像 **重采样至相同的体素大小**。这是必要的，因为 DeepMedic 的卷积核需要对应于相同的实际尺度模式（结构），以确保对所有受试者的一致性。\n\n* 确保用于训练和评估的 **真值标签** 以零表示背景。系统还假设任务的类别索引按递增顺序排列（例如 0,1,2，而非 0,10,20）。\n\n* **强烈建议将 ROI 内的数据强度归一化至均值为零、方差为 1 的空间**。如果数据强度处于其他范围，我们的默认配置性能将显著下降。\n\n**大型图像注意事项**：大型 3D CNN 计算开销较高。如遇到计算困难，可考虑对图像进行下采样或减小网络规模。DeepMedic 的默认配置是在约 200x200x200 大小的扫描上运行的。\n\n\n### 2. 软件运行\n\nDeepMedic 的源代码位于 [deepmedic](deepmedic\u002F) 文件夹中。用户通常无需直接修改该文件夹。软件提供了一个命令行界面 [deepMedicRun](deepMedicRun)，通过帮助选项运行：\n```cshell\n.\u002FdeepMedicRun -h\n```\n即可查看用于创建、训练和测试 CNN 模型的可用操作。所有操作都需要大量的配置参数，这些参数从配置文件中读取。\n\n在 [examples\u002FconfigFiles](examples\u002FconfigFiles\u002F) 文件夹中，我们提供了两组配置文件。首先，[examples\u002FconfigFiles\u002FtinyCnn\u002F](examples\u002FconfigFiles\u002FtinyCnn\u002F) 文件夹中包含一个非常小型网络的配置。该网络可在 CPU 上几分钟内完成训练，是一个简单的示例，用于验证系统是否正常工作。此外，我们还在 [examples\u002FconfigFiles\u002FdeepMedic\u002F](examples\u002FconfigFiles\u002FdeepMedic\u002F) 文件夹中提供了完整版 DeepMedic 模型的配置，该配置曾应用于 [[1](#citations)]。\n\n上述配置文件已预先设置好指向配套的 .nii 文件，这些文件位于 [examples\u002FdataForExamples\u002F](examples\u002FdataForExamples\u002F) 文件夹中。这些 NIFTI 文件作为我们示例中网络的输入数据。它们是来自脑肿瘤分割挑战赛（[BRATS 2015](http:\u002F\u002Fbraintumorsegmentation.org\u002F))图像的修改版本。\n\n\n#### 2.1 训练一个小型 CNN——验证系统是否正常工作\n\n我们将在此训练一个小型 CNN 模型，并确认一切按预期运行。关于软件使用的进一步说明将在下一节中提供。\n\n**注意**：请先参阅 [第 1.2 节](#12-installation)，了解必需软件的安装方法。\n\n让我们开始 **训练** 一个模型：\n```cshell\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FtinyCnn\u002Fmodel\u002FmodelConfig.cfg \\\n               -train examples\u002FconfigFiles\u002FtinyCnn\u002Ftrain\u002FtrainConfigWithValidation.cfg\n```\n\n该命令会解析给定的模型配置文件，该文件定义了网络架构并创建相应的卷积神经网络模型。随后，它会解析训练配置文件，该文件指定了训练方案的超参数。程序应已创建 `.\u002Fexamples\u002Foutput\u002F` 文件夹，所有输出都将保存在此处。接下来，模型将被训练两个轮次。整个过程的所有输出都会被记录下来，以便日后参考，这些日志文件位于 `examples\u002Foutput\u002Flogs\u002FtrainSessionWithValidTiny.txt`。每完成一个轮次，训练好的模型会被保存到 `examples\u002Foutput\u002Fsaved_models\u002FtrainSessionWithValidTiny` 目录下。TensorFlow 会以 **checkpoint** 文件的形式保存模型。您应该会在每个轮次结束后看到类似 `.\u002Fexamples\u002Foutput\u002FcnnModels\u002FtinyCnn.initial.DATE+TIME.model.ckpt.[data..., index]` 的文件被创建。每组 `DATE+TIMEmodel.ckpt[data,index]` 被称为一个 checkpoint，即一个保存的模型版本。最后，每完成一个轮次，模型会对验证集图像进行分割，分割结果（.nii 文件）应出现在 `examples\u002Foutput\u002Fpredictions\u002FtrainSessionWithValidTiny\u002Fpredictions\u002F` 文件夹中。如果训练正常结束（通常需要 5 分钟），并且您能在相应文件夹中看到上述文件，那就太好了！您可以稍作庆祝，然后继续……\n\n您还可以使用配套脚本绘制训练进度图，该脚本会解析训练日志：\n```\npython plotTrainingProgress.py examples\u002Foutput\u002Flogs\u002FtrainSessionWithValidTiny.txt -d\n```\n\n此外，默认情况下（在训练配置文件中设置 `tensorboard_log=True`），训练和验证指标也会被记录下来，以便通过 **TensorBoard** 进行可视化。相关的日志文件位于 `examples\u002Foutput\u002Ftensorboard\u002FtrainSessionWithValidTiny` 目录下（非人类可读格式）。有关 TensorBoard 的使用方法，请参阅 [TensorBoard 官方文档](https:\u002F\u002Fwww.tensorflow.org\u002Ftensorboard\u002Fget_started)。您可以通过以下命令启动 TensorBoard：\n```\ntensorboard --logdir=.\u002Fexamples\u002Foutput\u002Ftensorboard\u002FtrainSessionWithValidTiny\n```\n\n现在让我们用训练好的模型进行 **测试**（请替换 *DATE+TIME*）：\n```cshell\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FtinyCnn\u002Fmodel\u002FmodelConfig.cfg \\\n               -test .\u002Fexamples\u002FconfigFiles\u002FtinyCnn\u002Ftest\u002FtestConfig.cfg \\\n               -load .\u002Fexamples\u002Foutput\u002Fsaved_models\u002FtrainSessionWithValidTiny\u002FtinyCnn.trainSessionWithValidTiny.final.DATE+TIME.model.ckpt\n```\n当然，请根据实际情况替换 `DATE+TIME`。\n\n请注意，我们通过 `-load` 参数指定了要加载其参数的先前训练好的模型或 checkpoint。**但请务必注意**，此处提供的路径既不是指向 `data` 文件，也不是指向 `index` 文件，而是必须指向整个 checkpoint 集合（即 **路径应以 `.model.ckpt` 结尾**）。这是 TensorFlow 加载器的一个特殊要求。该过程应对测试集图像进行分割，结果应出现在 `examples\u002Foutput\u002Fpredictions\u002FtestSessionTiny\u002F` 文件夹下的 `predictions` 子文件夹中。此外，在 `features` 子文件夹中，您还应该能找到一些来自第二层的特征图。DeepMedic 提供了这一功能（详见 testConfig.cfg）。如果测试过程正常结束，并且所有输出文件都存在，那么就说明 **一切似乎都在正常工作！** 在 CPU 上是这样……\n\n#### 2.2 在 GPU 上运行\n\n现在让我们来检查关键部分……确认您的系统是否能够顺利地在 GPU 上运行 DeepMedic。首先，为了确保从头开始，请删除 `examples\u002Foutput\u002F` 文件夹。接下来，最重要的是将 **CUDA** 的 *nvcc* 路径添加到您的 *PATH* 环境变量中，并将 *cublas.so* 路径添加到您的 *LD_LIBRARY_PATH* 环境变量中（详见 [第 1.3 节](#13-gpu-processing)）。\n\n您需要按照之前为 CPU 版本执行的步骤来进行训练和测试，只不过这次要在 GPU 上操作。为此，请重复之前的命令，并添加额外的 `-dev cuda` 参数。例如：\n```cshell\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FtinyCnn\u002Fmodel\u002FmodelConfig.cfg \\\n               -train .\u002Fexamples\u002FconfigFiles\u002FtinyCnn\u002Ftrain\u002FtrainConfigWithValidation.cfg \\\n               -dev cuda0\n```\n\n如果您有多块 GPU，可以将 0 替换为其他设备编号以指定不同的 GPU。这些流程的输出应与之前类似。**请务必确认进程正在 GPU 上运行**，可以通过运行 `nvidia-smi` 命令来查看。您应该能看到 Python 进程已被分配到指定的 GPU 上。如果所有流程都能正常完成且没有报错，那就太棒了！**现在看来，一切真的都正常运作了 :)** 请继续阅读下一节，了解更多关于 DeepMedic 的信息以及如何使用我们更大的网络版本！\n\n**可能遇到的 GPU 相关问题**：如果 TensorFlow 找不到与当前版本兼容的 **CUDA** 和 **cuDNN** 版本（具体取决于 TensorFlow 的版本），它将默认回退到 CPU 版本。当这种情况发生时，在模型创建完成后、正式训练开始之前，TensorFlow 会抛出一些警告，内容大致如下：\n```\n2018-06-06 14:39:34.036373: I tensorflow\u002Fcore\u002Fplatform\u002Fcpu_feature_guard.cc:140] 您的 CPU 支持一些本 TensorFlow 二进制未编译启用的指令：AVX2 FMA\n2018-06-06 14:39:35.676554: E tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_driver.cc:406] cuInit 调用失败：CUDA_ERROR_NO_DEVICE\n2018-06-06 14:39:35.676616: I tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_diagnostics.cc:158] 正在检索主机 neuralmedic.doc.ic.ac.uk 的 CUDA 诊断信息\n2018-06-06 14:39:35.676626: I tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_diagnostics.cc:165] 主机名：neuralmedic.doc.ic.ac.uk\n2018-06-06 14:39:35.676664: I tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_diagnostics.cc:189] libcuda 报告的版本是：384.111.0\n2018-06-06 14:39:35.676699: I tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_diagnostics.cc:193] 内核报告的版本也是：384.111.0\n2018-06-06 14:39:35.676708: I tensorflow\u002Fstream_executor\u002Fcuda\u002Fcuda_diagnostics.cc:300] 内核版本似乎与 DSO 版本一致：384.111.0\n```\n\n如果进程未能按要求在 GPU 上启动，请确保您安装的 **CUDA** 和 **cuDNN** 版本与您当前使用的 TensorFlow 版本兼容（详情请参阅 https:\u002F\u002Fwww.tensorflow.org\u002Finstall），并且环境变量已正确设置。有关更多提示，请参阅第 1.4 节以及 CUDA 官方网站。\n\n\n\n\n### 3. 工作原理\n\n此前我们简要介绍了如何快速运行一个预设的小型 CNN 示例，以便您检查系统是否一切正常。在本节中，我们将更详细地介绍整个流程。同时，我们还会解释配置文件中需要指定的主要参数，以便您能够根据自身需求定制网络和处理流程。\n\n`examples\u002FconfigFiles\u002FdeepMedic\u002F` 目录下的 **.cfg 配置文件** 包含了用于创建和训练 DeepMedic 的参数。为了支持更广泛的应用场景和用户群体，该目录中的配置文件正逐步更新，加入一些被认为能够提升系统整体性能的组件。（注意：这些参数与我们在文献 [[1](#citations)] 中使用的一致，但并不完全相同。论文中使用的原始配置可在归档的 GitHub 分支 'dm_theano_v0.6.1_depr' 中找到。）\n\n**_注:_** 配置文件被解析为 Python 脚本，因此需遵循 **Python 语法**。任何被注释掉的配置变量都会在内部赋予 **默认值**。\n\n#### 3.1. 指定模型架构\n\n在进行训练或测试时，我们需要定义网络的架构。为此，我们通过 `-model` 选项指向一个模型配置文件：\n```\n-model .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Fmodel\u002FmodelConfig.cfg\n```\n\n读取 `modelConfig.cfg` 中的参数后，网络的计算图会在内部被构建。程序会将所有用于模型创建的参数打印到屏幕上，并记录到 `log.txt` 文件中。\n\n**用于定义网络架构的参数**\n\n![alt text](documentation\u002FdeepMedic.png \"用于多尺度处理的双路径 CNN\")\n图 1：多尺度处理的双路径架构示例。每一层的特征图数量和尺寸以 (*特征图数量 × 尺寸*) 的格式表示。实际的 DeepMedic 默认有 11 层。\n\n指定 CNN 模型的主要参数如下：\n\n*通用参数:*\n\n- modelName：此参数用于在保存每一轮训练的检查点时为其命名。请根据不同的架构更改名称。\n- folderForOutput：主输出文件夹。保存的模型和日志都将放置于此。\n\n*任务相关参数:*\n\n- numberOfOutputClasses：DeepMedic 是一个多分类系统。该数值应 **包含背景类**，并定义最后一层（即分类层）的特征图数量（如图 1 所示为 2）。\n- numberOfInputChannels：指定扫描数据的模态、序列或通道数。\n\n*架构参数:*\n\n- numberFMsPerLayerNormal：这是一个列表，其长度应等于我们希望创建的正常路径中的层数。每个条目代表对应层的特征图数量（如图 1 中为 [30, 40, 40, 50]）。\n- kernelDimPerLayerNormal：每层卷积核的尺寸。（如图 1 中为 [[5,5,5], [5,5,5], [5,5,5], [5,5,5]]。）\n- useSubsampledPathway：将其设置为 “True” 可创建一个与正常路径结构相同的下采样路径。“False” 则仅使用正常路径进行单尺度处理。此外，还有一些参数可用于进一步调整该下采样路径。\n- numberFMsPerLayerFC：高低分辨率路径的最后一层特征图会被拼接在一起，然后通过最终分类 (FC) 路径进行处理。此参数允许在分类层之前向 FC 路径添加隐藏层。列表中的条目数量决定了隐藏层的数量，而每个条目的数值则表示相应层的特征图数量。最终分类层不包括在内。（如图 1 中为 [[150], [150]]。）\n\n*图像片段与批大小:*\n\n- segmentsDim(Train\u002FVal\u002FInference)：输入片段的尺寸。训练、验证和推理（测试）可以使用不同大小的片段。较大的片段需要更多的内存和计算资源。训练片段的大小会显著影响训练样本的分布（如图 1 中为 [25,25,25]）。验证片段的尺寸默认与感受野大小一致（即一个补丁）。测试片段的尺寸仅影响速度。\n- Batch Size：同时在 GPU 上处理的片段数量。在训练过程中，较大的批大小通常能带来更好的收敛性和结果，但也会消耗更多计算资源和内存。验证和推理阶段的批大小相对不那么重要，较大的批大小只会加快处理速度。\n\n还有其他一些参数可供使用，但它们的重要性较低（如正则化、优化器等）。这些参数已在提供的示例配置文件中详细说明。\n\n\n#### 3.2. 训练\n\n您需要使用手动分割的真实标注数据来训练模型。为此，您需要指向一个包含训练会话参数的配置文件。我们结合 `-model` 选项（用于定义网络架构）和 `-train` 选项（用于指向训练配置文件，其中指定了训练方案和优化相关的参数）来完成这一操作：\n```\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Fmodel\u002FmodelConfig.cfg \\\n               -train .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Ftrain\u002FtrainConfig.cfg \\\n               -dev cuda0\n```\n\n请注意，如果您的机器拥有 **多个 GPU**，您可以将 0 替换为其他 GPU 设备编号。\n\n\n**训练流程**\n\n在一次训练会话中，会按照以下循环进行：\n```\n对于每个 epoch {\n\t对于每个 subepoch {\n\t\t加载验证病例\n\t\t提取验证片段\n\t\t分批进行验证（基于样本）\n\n\t\t加载训练病例\n\t\t提取训练片段\n\t\t分批进行训练\n\n\t\t报告 subepoch 样本上的准确率（验证\u002F训练）。\n\t}\n\t报告整个 epoch 的准确率（验证\u002F训练）\n\t必要时降低学习率。\n\t保存模型状态\n\n\t每隔几个 epoch 对验证病例进行全量推理\n\t报告全量推理的 DSC 值\n\t保存全量推理的预测结果（分割图\u002F概率图\u002F特征图）\n}\n```\n\n基于样本的验证以及对验证受试者扫描的全量分割是可选的。\n\n\n**使用 Matplotlib 绘制训练进度**\n\n可以通过随附的 `plotTrainingProgress.py` 脚本来绘制训练进度，该脚本会解析训练日志中记录的验证和训练准确率指标。常见的使用示例如下：\n```\npython plotTrainingProgress.py examples\u002Foutput\u002Flogs\u002FtrainSession\\_1.txt examples\u002Foutput\u002Flogs\u002FtrainSession\\_2.txt \\\n       -d -m 20 -c 1\n```\n\n尝试使用 `-h` 选项获取帮助。这里指定了两个日志\u002F实验，以便同时绘制两者的指标进行比较。您可以指定任意数量的日志。`-d` 选项会生成一张包含更多指标的 *详细* 图表。`-m 20` 会对 20 个子周期的数据进行移动平均，以平滑曲线。`-c 1` 会单独绘制标签为 1 的类别。需要注意的是，在存在多个类别的情况下，`-c 0` 实际上报告的是 **非背景类** 的指标，而非背景类本身（因为我们发现后者在大多数应用中并无太大意义），而是针对 *整个前景类* 进行统计，相当于将除 0（假设为背景）之外的所有类别合并为一个整体。\n\n日志中记录的指标既包括训练数据，也包括验证数据。大多数指标都是基于 *样本*（即 *子体积*，也就是补丁）计算的。例外的是 *整幅扫描的 DSC*（即 *全量分割*），它是在每隔几个 epoch 对整个验证体积进行分割后计算得出的（如果已指定）。\n\n\n**使用 TensorBoard 绘制训练进度**\n\n此外，如果训练配置文件中启用了此功能（即 `train-config` 文件中的变量 `tensorboard_log=True`），训练指标也会被记录下来，以便使用 TensorFlow 的 **TensorBoard** 进行可视化。有关使用方法，请参阅 [TensorBoard 文档](https:\u002F\u002Fwww.tensorflow.org\u002Ftensorboard\u002Fget_started)。以 TensorBoard 所需格式保存的指标文件位于 `examples\u002Foutput\u002Ftensorboard\u002Fname-of-training-session\u002F` 目录下。可以通过以下命令启动 TensorBoard：\n```\ntensorboard --logdir=.\u002Fexamples\u002Foutput\u002Ftensorboard\u002Fname-of-training-session\n```\n为 TensorBoard 记录的指标与主日志 `.txt` 文件中记录的指标相同，并且可以通过上述脚本进行可视化。\n\n\n**恢复中断的训练会话**\n\n训练会话可能因各种原因而中断。为此，**模型状态会在每个 epoch 结束时保存**，并存储在输出文件夹中。除了可训练的卷积核之外，我们还会保存优化器的状态以及训练会话的相关参数（例如已训练的 epoch 数、当前学习率等），以便能够无缝地继续训练。**中断的训练会话可以继续进行**，方法与初始启动时类似，只需额外指定要加载已保存模型检查点的位置，从中断处继续训练：\n\n```\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Fmodel\u002FmodelConfig.cfg \\\n               -train .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Ftrain\u002FtrainConfig.cfg \\\n               -load .\u002Fexamples\u002Foutput\u002Fsaved_models\u002FtrainSessionDm\u002FdeepMedic.trainSessionDm.DATE+TIME.model.ckpt \\\n               -dev cuda0\n```\n或者，也可以在 `trainConfig` 文件中直接定义检查点路径。需要注意的是，路径绝不能指向 `.index` 或 `.data` 文件，**必须以 `.model.ckpt` 结尾**，这样加载器才能找到对应的 `.index` 和 `.data` 文件。\n\n**预训练模型与微调**\n\n神经网络的常见做法是先使用在一个任务或数据集上预训练好的网络，然后通过在第二个数据集上进行训练来对其进行微调。这可以通过在开始训练时指定预训练网络的检查点路径（`-load`）及其架构文件（`-model`）来实现。然而，非常重要的一点是，在微调阶段开始时，可能需要*重置训练器的状态*。否则，训练器仍会保留第一次训练会话中保存的状态信息（如已训练的 epoch 数、动量速度、学习率等）。这些参数都可以通过 `-resetopt` 选项重置，从而根据新的训练会话配置重新初始化，具体如下：\n```\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Fmodel\u002FmodelConfig.cfg \\\n               -train .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Ftrain\u002FtrainConfigForRefinement.cfg \\\n               -load .\u002Fpath\u002Fto\u002Fpretrained\u002Fnetwork\u002Ffilename.DATE+TIME.model.ckpt \\\n               -resetopt \\\n               -dev cuda0\n```\n\n**训练参数**\n\n*通用参数：*\n\n- sessionName：训练会话的名称，用于保存训练好的模型、日志和结果。\n- folderForOutput：主输出文件夹。\n- cnnModelFilePath：已保存 CNN 模型的路径（用于恢复训练时使用；若使用 `-load` 参数则忽略此设置）。\n- tensorboard_log：指定是否启用指标记录以供 TensorBoard 可视化（见第 3.2 节），这会占用磁盘空间。\n\n*训练输入参数：*\n\n- channelsTraining：对于每个输入通道，该列表应包含一个条目，条目内容为对应通道文件的路径。这些文件列出了所有训练样本中各通道的路径。请参考示例中提供的预设文件，即可轻松理解。\n- gtLabelsTraining：包含所有训练样本真实标签文件的路径。\n- roiMasksTraining：在许多任务中，我们可以轻松定义感兴趣区域并生成其掩码，例如在人体扫描中排除空气部分，或在脑部扫描中提取脑部掩码。此时，该参数允许指定每个训练样本的 ROI 掩码。采样或推理将不会在该区域之外进行，从而使网络的学习能力集中在区域内。若无此参数，则将其删除或注释掉，采样将在整个体积上进行。\n\n*训练周期参数：*\n\n- numberOfEpochs：训练完成所需的总 epoch 数。\n- numberOfSubepochs：每个 epoch 中要运行的子 epoch 数。\n- numOfCasesLoadedPerSubepoch：在每个子 epoch 中，最多会加载指定数量病例的图像以提取训练样本。这样做是为了支持处理包含成百上千张图像的大规模数据集，避免一次性加载所有图像而导致资源消耗过大。\n- numberTrainingSegmentsLoadedOnGpuPerSubep：在每个子 epoch 中，总共会提取指定数量的片段，并将其加载到 GPU 上以执行优化步骤。每个子 epoch 的优化步骤次数等于该数值除以训练批次大小（见模型配置）。片段越多，所需的 GPU 内存和计算量越大。\n- batchsize_train：训练批次的大小。批次越大，所需的 GPU 内存越多。\n- num_processes_sampling：在 GPU 上执行当前训练或验证的同时，可以并行提取用于下次验证或训练的样本。请指定并行采样进程的数量。\n\n*学习率调度：*\n\n- typeOfLearningRateSchedule：用于调整学习率的调度方式。“stable”表示保持学习率恒定；“predef”表示在预设的 epoch 下降学习率，用户需指定何时降低学习率；“auto”表示当验证准确率趋于平稳时自动降低学习率（不稳定）；“poly”表示随时间缓慢降低学习率。建议使用恒定学习率，通过绘制曲线观察训练进展，并在改进停滞时手动创建“predef”调度来降低学习率。否则可选择“poly”，但务必确保训练时间足够长以达到收敛，可通过适当调整总训练 epoch 数来进行试验。\n\n*数据增强：*\n\n- reflectImagesPerAxis：指定是否希望在训练过程中对图像沿各个轴进行随机翻转以实现数据增强。\n- performIntAugm：随机对片段的像素强度进行变换：I' = (I + shift) * multi\n\n*验证：*\n\n- performValidationOnSamplesThroughoutTraining、performFullInferenceOnValidationImagesEveryFewEpochs：布尔值，用于指定是否执行验证，因为验证过程实际上非常耗时。\n- channelsValidation、gtLabelsValidation、roiMasksValidation：与对应的训练参数类似。如果启用了默认的验证采样设置，则会在整个体积范围内均匀地进行验证采样，以确保各类别的分布正确。\n- numberValidationSegmentsLoadedOnGpuPerSubep：每次验证时加载到 GPU 上的验证片段（样本）数量。\n- numberOfEpochsBetweenFullInferenceOnValImages：每隔多少个 epoch 执行一次完整的验证推理。频繁处理所有验证样本可能会比较慢。\n- namesForPredictionsPerCaseVal：如果执行了完整推理验证，可以将结果保存下来以便直观地检查进度。这里需要指定一个文件路径，该文件应包含一个名称列表，每个病例对应一个名称，用于保存结果。只需填写名称，无需路径。结果将被保存在输出文件夹中。\n\n#### 3.3. 测试\n\n当一个训练 epoch 结束时，模型的状态会被保存下来。这些模型可用于对之前未见过的扫描数据进行分割。需要指定一个测试配置文件。测试可以通过两种方式启动。\n\na) 直接在命令行中指定模型：\n```\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Fmodel\u002FmodelConfig.cfg \\\n               -test .\u002Fexamples\u002FconfigFiles\u002FdeepMedic\u002Ftest\u002FtestConfig.cfg \\\n               -load .\u002Fpath-to-saved-model\u002Ffilename.model.ckpt \\\n               -dev cuda0\n```\n\nb) 也可以在测试配置文件中指定已保存模型的路径，然后省略 `-load` 选项。**注意：** 使用 `-load` 选项指定的文件会覆盖配置文件中任何相关设置。\n\n加载模型后，将在测试样本上执行推理。可以保存预测的分割掩码、每个类别的后验概率图以及任意层的特征图。如果提供了真实标签，DeepMedic 还会报告其预测结果的 DSC 指标。\n\n请注意，此测试流程与每几个训练 epoch 就对验证样本执行一次的完整推理流程相似。\n\n**测试参数**\n\n*主要参数：*\n\n- sessionName：会话名称，用于保存日志和推理结果。\n- folderForOutput：用于保存日志和结果的输出文件夹。\n- cnnModelFilePath：要使用的 CNN 模型路径。如果已在命令行中指定，则忽略此参数。\n- channels：测试每个病例的通道文件列表路径。与训练时的相应参数类似。\n- namesForPredictionsPerCase：保存每个病例预测结果所用名称的文件路径。\n- roiMasks：如果可以创建受限感兴趣区域的掩码，则推理仅在该区域内进行。如果配置文件中未指定此参数，则会对整个体积进行扫描。\n- gtLabels：每个病例的真实标签文件路径列表。测试时并非必需，但如果提供，将会报告 DSC 准确率指标。\n\n*保存预测结果：*\n\n- saveSegmentation、saveProbMapsForEachClass：指定是否需要保存分割掩码和各分类别的概率图。\n\n*保存特征图：*\n\n- saveIndividualFms、saveAllFmsIn4DimImage：指定是否需要保存特征图。可以选择将每个特征图单独保存为文件，或者将所有特征图合并成一个四维文件。需要注意的是，特征图数量较多，四维文件可能达到几百 MB 甚至 GB 的大小。\n- minMaxIndicesOfFmsToSaveFromEachLayerOfABCPathway：由于特征图数量庞大，可以指定要保存的具体特征图。需提供希望保存的各层特征图的最小索引（包含）和最大索引（不包含）（索引从 0 开始）。\n\n### 4. 如何在您的数据上运行 DeepMedic\n\n`examples\u002FconfigFiles\u002FdeepMedic\u002F` 中的 **.cfg 配置文件** 提供了用于创建和训练 DeepMedic 的参数。这些参数与我们在文献 [[1](#citations)] 中使用的内容相似（但不完全相同），也与我们在 ISLES 2015 挑战赛中的获奖方案 [2] 所使用的参数一致。为了支持更广泛的应用场景和用户群体，`examples\u002FconfigFiles\u002FdeepMedic\u002F` 中的配置文件正逐步更新，加入一些被认为能够提升系统整体性能的组件。（注：上述论文中所使用的原始配置可在归档的 GitHub 分支 'dm_theano_v0.6.1_depr' 中找到。）\n\n要在您的数据上运行 DeepMedic，您需要按照以下最低步骤操作：\n\n**a)** 按照第 [1.4](#14-required-data-pre-processing) 节所述对您的数据进行预处理。请务必将其归一化到均值为零、方差为 1 的空间。如果任务需要，尽可能生成 ROI 掩膜（例如脑掩膜）。\n\n**b)** 在 `modelConfig.cfg` 文件中，将变量 `numberOfOutputClasses = 5` 修改为您任务中的类别数（例如，如果是二分类则设为 2），并将 `numberOfInputChannels = 2` 修改为输入模态的数量。现在您可以使用 `-newModel` 选项来创建模型。\n\n**c)** （可选）如果您希望训练一个更大或更小的网络，最简单的方法是增加或减少每层的特征图数量。这可以通过修改变量 `numberFMsPerLayerNormal = [30, 30, 40, 40, 40, 40, 50, 50]` 中的特征图数量来实现。\n\n**d)** 在开始训练网络之前，您需要修改 `trainConfig.cfg` 文件，以便让软件知道您的输入图像位于何处。变量 `channelsTraining = [\".\u002FtrainChannels_flair.cfg\", \".\u002FtrainChannels_t1c.cfg\"]` 已预先设置为指向两个文件，每个文件对应一个输入变量。请根据您的任务调整此设置。\n\n**e)** 为您的任务创建与上述 `.\u002FtrainChannels_flair.cfg` 和 `trainChannels_t1c.cfg` 文件相对应的文件。这些文件本质上都是列表，每个文件都包含所有训练样本的条目，条目内容是该样本对应模态图像的 .nii 文件路径。查看提供的示例文件即可明白具体格式。\n\n**f)** 同样地，通过变量 `gtLabelsTraining = \".\u002FtrainGtLabels.cfg\"` 指向用于训练的真值标签文件，并通过 `roiMasksTraining = \".\u002FtrainRoiMasks.cfg\"` 指向 ROI 掩膜文件（如果有）。如果未提供 ROI 掩膜，则推理将覆盖整个图像区域；否则，推理仅在 ROI 内进行。\n\n**g)** 如果您希望在训练过程中定期进行 **验证**，可以参照上述方法，通过变量 `channelsValidation`、`gtLabelsValidation` 和 `roiMasksValidation` 指向验证集样本的文件。如果您不打算进行验证（因为耗时较长），请将 `performValidationOnSamplesThroughoutTraining` 和 `performFullInferenceOnValidationImagesEveryFewEpochs` 设置为 `False`。\n\n**h)** （可选）如果您需要调整训练会话的长度，例如针对较小的网络，最简单的方法是降低总 epoch 数 `numberOfEpochs=35`。同时，您还应相应调整预定义的学习率调度表 `predefinedSchedule`。另一种选择是使用递减的学习率调度方式，将 `typeOfLearningRateSchedule = 'poly'` 设置为多项式调度。\n\n**i)** **测试**已训练好的网络时，您需要像 d) 点所述那样指向测试集样本的图像。调整变量 `channels = [\".\u002FtestChannels_flair.cfg\", \".\u002FtestChannels_t1c.cfg\"]` 来指向测试样本的模态图像。如果存在 ROI 掩膜，请通过 `roiMasks` 指向它们，这样推理将仅在 ROI 区域内进行。否则，请将此变量注释掉。同样，如果您通过 `gtLabels` 提供测试样本的真值标签，系统将计算预测准确率并报告 DSC 指标；否则，请将此变量注释掉。\n\n**j)** 最后，您需要创建一个文件，列出为每个测试样本生成的预测结果所要使用的名称。请参阅 `namesForPredictionsPerCase = \".\u002FtestNamesOfPredictionsSimple.cfg\"` 变量及其对应的预设文件。完成以上步骤后，您就可以使用该模型进行测试了。\n\n所提供的 DeepMedic 配置在 NVIDIA GTX Titan X 上大约需要 2 天时间才能完成训练。对标准大小的脑部扫描进行推理通常需要 2–3 分钟。如果您的任务耗时过长，请调整训练和测试的配置，或考虑对数据进行下采样。\n\n### 5. 结语\n\n我们希望公开发布这款软件能够加速深度学习在生物医学图像处理与分析领域的应用。目前该软件仍在积极开发中，因此请注意它尚未达到模块化和完全通用的程度。在当前状态下，我们认为它可以作为进一步研究的基准方法，也可用作各种工作流中的分割系统。如果您认为我们的工作对您的研究产生了积极影响，请引用我们的论文 [1]。\n\n我深知该软件的许多功能尚未完全模块化，API 也远未完善。我希望 DeepMedic 能够成为社区中有用的工具。如您有任何反馈或问题，欢迎随时通过电子邮件与我联系：**konstantinos.kamnitsas12@ic.ac.uk**\n\n祝好，\n\nKonstantinos Kamnitsas\n\n### 6. 许可证\n\nDeepMedic 软件许可证：BSD 3-Clause 许可证。该许可证副本位于根目录中。\n\n示例数据许可证：知识共享署名-非商业性使用-相同方式共享 3.0 瑞士许可协议。http:\u002F\u002Fcreativecommons.org\u002Flicenses\u002Fby-nc-sa\u002F3.0\u002Fch\u002Fdeed.en\n\n\n[\u002F\u002F]: # (reference links)\n\n   [paper1]: \u003Chttp:\u002F\u002Fwww.sciencedirect.com\u002Fscience\u002Farticle\u002Fpii\u002FS1361841516301839>\n\n   [paper2]: \u003Chttp:\u002F\u002Fwww.isles-challenge.org\u002FISLES2015\u002Farticles\u002Fkamnk1.pdf>","# DeepMedic 快速上手指南\n\nDeepMedic 是一个用于生物医学 3D 扫描图像分割的深度学习系统。它允许用户轻松创建和训练 3D 卷积神经网络（CNN），专门处理 NIFTI 格式的医学影像数据（如 MRI），适用于脑病变分割等任务。\n\n## 1. 环境准备\n\n在开始之前，请确保您的系统满足以下要求：\n\n*   **操作系统**: Linux\u002FUnix (Windows 需类似步骤，但主要测试环境为 Unix)。\n*   **Python**: 推荐 **Python 3.6.5** (兼容 Python 2，但不再保证未来支持)。\n*   **深度学习框架**: **TensorFlow 2.0+** (已测试版本 2.6.2) 或 1.15.0。\n*   **GPU 支持 (可选但推荐)**:\n    *   NVIDIA GPU 驱动程序。\n    *   **CUDA** 和 **cuDNN** (需与 TensorFlow 版本严格匹配)。\n    *   *测试通过的组合*: Python 3.6.5 + TF 2.6.2 + cuDNN 8.2.1。\n*   **核心依赖库**:\n    *   `NiBabel`: 用于加载 NIFTI 文件。\n    *   `numpy`: 数组处理。\n    *   `scipy`: 科学计算及图像增强操作。\n\n> **注意**: 安装前请务必确认 Python、TensorFlow 和 cuDNN 版本的兼容性，这是最常见的安装失败原因。\n\n## 2. 安装步骤\n\n建议使用 **Conda** 进行环境管理，以避免权限问题和依赖冲突。\n\n### 2.1 创建 Conda 环境\n\n打开终端（bash shell），执行以下命令创建独立环境：\n\n```bash\nconda create -p FOLDER_FOR_ENVS\u002Fve_dm_tf python=3.6.5 -y\nsource activate FOLDER_FOR_ENVS\u002Fve_dm_tf\n```\n*(请将 `FOLDER_FOR_ENVS` 替换为您希望存放环境的实际路径)*\n\n### 2.2 安装 TensorFlow 和 GPU 驱动库\n\n根据您的硬件情况安装 TensorFlow。若使用 GPU，请确保已安装对应的 CUDA\u002FcuDNN。\n\n```bash\n# 安装 TensorFlow GPU 版本 (示例版本 2.6.2)\npip install tensorflow-gpu==2.6.2\n\n# 安装 cuDNN (通过 conda 安装通常会自动处理部分依赖)\npip install cudnn==8.2.1\n```\n*国内用户加速建议*: 可使用清华或阿里镜像源加速 pip 安装：\n`pip install -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple tensorflow-gpu==2.6.2`\n\n### 2.3 克隆并安装 DeepMedic\n\n获取源代码并安装项目及其剩余依赖：\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002FKamnitsask\u002Fdeepmedic\u002F\ncd deepmedic\npip install .\n```\n\n### 2.4 配置 GPU 环境变量 (仅 GPU 用户)\n\n如果通过 conda 安装 cuDNN 后仍无法识别 GPU，需手动设置环境变量。将 `\u002Fpath\u002Fto\u002Fcuda` 替换为您的实际安装路径：\n\n```bash\nexport CUDA_HOME=\u002Fpath\u002Fto\u002Fcuda\nexport LD_LIBRARY_PATH=\u002Fpath\u002Fto\u002Fcuda\u002Flib64\nexport PATH=\u002Fpath\u002Fto\u002Fcuda\u002Fbin:$PATH\n```\n\n## 3. 基本使用\n\nDeepMedic 通过命令行工具 `deepMedicRun` 进行操作，所有配置均通过 `.cfg` 文件管理。\n\n### 3.1 数据预处理要求\n\n在运行之前，您的数据必须满足以下条件：\n1.  **格式**: 所有输入图像、标签（Ground Truth）、ROI 掩码必须是 **NIFTI (.nii)** 格式。\n2.  **配准**: 同一受试者的所有模态图像和标签必须已完成**空间配准**。\n3.  **维度**: 同一受试者的所有图像必须具有相同的像素维度。\n4.  **重采样**: 数据库中所有受试者的图像必须重采样至**相同的体素大小 (voxel size)**。\n5.  **标签索引**: 背景标记为 `0`，其他类别依次递增 (0, 1, 2...)，不可跳跃 (如 0, 10, 20)。\n6.  **归一化**: 强烈建议将 ROI 内的强度归一化为零均值、单位方差，否则默认配置性能会显著下降。\n\n### 3.2 运行最小示例 (验证安装)\n\n项目提供了一个微型 CNN 配置 (`tinyCnn`)，可在 CPU 上几分钟内完成训练，用于验证环境是否正常工作。\n\n**训练模型：**\n\n```bash\n.\u002FdeepMedicRun -model .\u002Fexamples\u002FconfigFiles\u002FtinyCnn\u002Fmodel\u002FmodelConfig.cfg \\\n               -train examples\u002FconfigFiles\u002FtinyCnn\u002Ftrain\u002FtrainConfigWithValidation.cfg\n```\n\n*   该命令会读取模型配置文件构建网络，并根据训练配置文件启动训练。\n*   输出结果将保存在 `.\u002Fexamples\u002Foutput\u002F` 目录下。\n\n**后续步骤：**\n一旦微型网络测试成功，您可以修改 `examples\u002FconfigFiles\u002FdeepMedic\u002F` 中的配置文件，将其指向您自己的预处理数据，从而开始正式的大规模模型训练。","某三甲医院放射科团队正致力于利用多模态 MRI 数据，自动化分割脑卒中患者的脑部病灶区域以辅助临床诊断。\n\n### 没有 deepmedic 时\n- **多尺度特征捕捉困难**：传统 3D 卷积网络难以同时兼顾病灶的局部细节与全局上下文信息，导致微小病变漏检或大病灶边界模糊。\n- **开发门槛高且周期长**：研究人员需从零搭建复杂的深度学习架构并手动处理 NIFTI 格式数据，模型调试与复现前沿算法耗时数月。\n- **训练效率低下**：缺乏针对医学影像优化的采样策略，面对类别极度不平衡的数据（病灶远小于正常组织），模型收敛缓慢且容易过拟合。\n- **人工标注负担重**：由于自动分割精度不足，医生仍需花费大量时间对三维影像进行逐层手动修正，严重拖慢科研与诊疗流程。\n\n### 使用 deepmedic 后\n- **精准的多尺度分割**：deepmedic 内置的双路径 3D CNN 架构能高效融合不同分辨率的特征，显著提升了复杂形状病灶的识别准确率与边界清晰度。\n- **开箱即用的工作流**：直接支持 NIFTI 图像输入与标准化配置，团队无需重写底层代码即可快速部署并训练符合最新研究标准的分割模型。\n- **高效的样本采样机制**：利用其特有的每类采样（per-class sampling）功能，有效解决了正负样本不平衡问题，大幅缩短了模型训练时间。\n- **释放临床生产力**：高精度的自动化分割结果将医生从繁琐的手动勾画中解放出来，使其能专注于病情分析与治疗方案的制定。\n\ndeepmedic 通过其高效的多尺度 3D 卷积架构，将脑病灶分割从耗时的手工探索转变为标准化、高精度的自动化流程，极大加速了医学影像分析的科研与临床应用落地。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdeepmedic_deepmedic_8b9b3d9e.png","DeepMedic","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fdeepmedic_0d0be357.jpg","Efficient Multi-Scale 3D Convolutional Neural Network for Medical Image Segmentation",null,"https:\u002F\u002Fgithub.com\u002Fdeepmedic",[78],{"name":79,"color":80,"percentage":81},"Python","#3572A5",100,1056,345,"2026-03-30T12:13:55","BSD-3-Clause",4,"Linux, macOS, Windows","非必需（小型网络可运行于 CPU），但大型 3D CNN 推荐 NVIDIA GPU。需安装与驱动兼容的 CUDA Toolkit 和 cuDNN。测试环境为 cudnn 8.2.1 (对应 TensorFlow 2.6.2)。显存大小未明确说明，但建议对大图像进行下采样以降低需求。","未说明",{"notes":91,"python":92,"dependencies":93},"1. 仅支持 NIFTI (.nii) 格式数据，且同一受试者的所有图像（模态、标签、ROI）必须已配准并具有相同维度。2. 数据库中的所有图像必须重采样至相同的体素大小。3. 强烈建议将 ROI 内的数据强度归一化为零均值、单位方差，否则性能会显著下降。4. 地面真值标签的背景必须为 0，类别索引必须连续（如 0,1,2）。5. 建议使用 Conda 管理环境以确保 Python、TensorFlow 和 cuDNN 版本兼容。","3.6.5 (默认推荐，支持 Python 2 但无未来保证)",[94,95,96,97],"tensorflow-gpu==2.6.2 (或 tensorflow>=2.0.0, \u003C=1.15.0)","nibabel>=3.0.2","numpy>=1.18.2","scipy",[14],[100,101,102,103,104],"deep-learning","machine-learning","medical-imaging","neural-networks","convolutional-neural-networks","2026-03-27T02:49:30.150509","2026-04-15T04:26:14.672939",[108,113,118,123,128,132],{"id":109,"question_zh":110,"answer_zh":111,"source_url":112},33581,"如何提取并保存网络中间层的特征图（Feature Maps）为 Nifti 格式或进行可视化？","您需要修改测试配置文件（testConfig.cfg）。在文件末尾找到标记为 \"++Feature Maps++\" 的部分，取消相关代码的注释。然后设置参数 minMaxIndicesOfFmsToSaveFromEachLayerOfNormalPathway 来指定要保存的特征图索引范围，例如设置为 [[0,4],[0,4],[0,4]] 以保存前三个层中索引 0 到 4 的特征图。运行测试后，生成的特征图将保存在测试输出文件夹的 features 目录中。","https:\u002F\u002Fgithub.com\u002Fdeepmedic\u002Fdeepmedic\u002Fissues\u002F144",{"id":114,"question_zh":115,"answer_zh":116,"source_url":117},33582,"在进行大体积图像推理（Testing）时遇到显存不足（Out of Memory）错误怎么办？","该问题通常是由于旧版本中测试进程的设计缺陷导致的：程序试图一次性将所有切分后的图像块加载到 GPU 中。解决方案是升级到最新版本（如 v0.5.4 或更高），维护者已在后续提交（commit f4a9d42）中修复了此问题，改为分批处理图像块，从而大幅降低显存占用。如果无法升级，尝试减小推理时的图像块大小（inference segment size）作为临时变通方法。","https:\u002F\u002Fgithub.com\u002Fdeepmedic\u002Fdeepmedic\u002Fissues\u002F27",{"id":119,"question_zh":120,"answer_zh":121,"source_url":122},33583,"DeepMedic 是否支持 Python 3？遇到 parallel python (pp) 模块不兼容问题如何解决？","从 v0.7.1 版本（2019 年 2 月 13 日之后的 master 分支）开始，项目已完全支持 Python 3。维护者移除了对第三方 pp (parallel-python) 模块的依赖，改用 Python 内置的 multiprocessing 模块进行处理。如果您使用的是旧版本且必须使用 Python 3，需要手动下载并安装 pp 的 beta 版本（1.6.4.4），但强烈建议直接升级到最新版本以获得原生支持和更好的性能。","https:\u002F\u002Fgithub.com\u002Fdeepmedic\u002Fdeepmedic\u002Fissues\u002F58",{"id":124,"question_zh":125,"answer_zh":126,"source_url":127},33584,"测试完成后生成的分割结果文件（Segm.nii）中所有像素值均为 0，可能是什么原因？","这通常与数据归一化（normalization）设置有关。提供的默认元参数配置是针对特定类型的归一化方式设定的，对该设置非常敏感。如果输入数据的归一化方式与配置不匹配，可能导致网络输出全零。请检查您的数据预处理步骤是否符合配置文件中的归一化要求，或者尝试调整学习率等超参数以适应新的归一化设置。此外，确保您使用的是较新的代码版本，因为旧版本在某些边缘情况下可能存在计算问题。","https:\u002F\u002Fgithub.com\u002Fdeepmedic\u002Fdeepmedic\u002Fissues\u002F19",{"id":129,"question_zh":130,"answer_zh":131,"source_url":127},33585,"训练结束后输出的 Dice 系数列表中包含异常大的数值（如 294），这是什么意思？","Dice 分数列表中的每个元素对应一个标签类别（Class-0, Class-1 等）。出现如 294 这样的异常大数值，通常是因为某些测试主体（subject）中完全不存在该类别，导致旧版本代码在计算时出错。这是一个已知问题，已在较新的版本中修复。解决方法是拉取最新的 master 分支代码重新运行评估。",{"id":133,"question_zh":134,"answer_zh":135,"source_url":122},33586,"如何在配置文件中控制训练时用于数据采样的子进程数量？","在当前的多进程实现中（使用 Python 内置 multiprocessing 模块），主线程会生成一个采样器线程，该采样器再生成多个子进程来加载数据并提取样本。您可以通过编辑训练配置文件（trainConfig.cfg），修改变量 num_processes_（具体变量名可能在文件中略有不同，通常在并行处理部分）来控制子采样进程的数量。增加进程数可以利用多核 CPU 加速数据加载，但需根据硬件资源适当调整。",[137,142,147,152,157,162,167],{"id":138,"version":139,"summary_zh":140,"released_at":141},255826,"v0.8.2","- 增加了对 TensorFlow 2.0 以及 TensorFlow 1.15.0 的兼容性。目前尚不支持 Eager Execution，敬请期待。\n- 对 .\u002Fdeepmedic\u002Fneuralnet 模块中的代码进行了大规模重构，使其更加模块化且整洁。\n- 改进了采样逻辑，使得多分类问题的采样速度显著提升。\n- 修复了一些小问题（使 TensorBoard 指标显示更美观、修复了一些小 Bug、日志输出更清晰等）。\n\n自上一版本以来配置文件的变化  \n本版本 v0.8.2 对模型配置文件做了两项小幅改动：\n- 将旧变量 ``kernelDimFor1stFcLayer`` 替换为 ``kernelDimPerLayerFC``。\n- 新增变量 ``padTypePerLayerFC``，允许为每一层单独定义填充方式（同样适用于 Normal 和下采样层，但默认隐藏）。","2020-04-26T16:45:23",{"id":143,"version":144,"summary_zh":145,"released_at":146},255827,"v0.8.0","- 将训练和验证指标记录到 TensorBoard。\n- 在训练过程中支持对输入进行实时归一化（默认关闭）。目前仅支持 Z-Score 归一化。\n- 重构并优化了训练、测试和采样部分的代码结构与美观性。","2019-11-14T18:21:20",{"id":148,"version":149,"summary_zh":150,"released_at":151},255828,"v0.7.2","变更\n- 批量大小现位于 trainConfig 和 testConfig 中，而非 model 配置中。\n- 改进了对挂起并行进程的处理（在 trainConfig 中，当 num_processes_sampling > 0 时）。\n- 数据增强模块化，便于进一步扩展。\n\n预计的主要差异：\n- 用户需调整配置文件，将批量大小从 modelconfig 移至 train\u002Ftest 配置中。\n- 若 trainConfig 中配置了 num_processes_sampling > 0，则并行处理将更加快速且稳定。\n- 性能略有提升，这得益于在片段而非整张图像上进行数据增强。","2019-03-18T13:15:19",{"id":153,"version":154,"summary_zh":155,"released_at":156},255829,"v0.7.1","变更：\n- 多进程实现由 pp 改为 Python 内置模块。\n- 改进了异常处理。\n- 默认 Python 版本切换为 Python 3。\n- 更新了默认配置，使用未归一化的动量。\n- 对采样相关代码进行了部分清理。\n\n主要功能差异：采样（进而整体训练）速度应有所提升。","2019-02-13T14:39:29",{"id":158,"version":159,"summary_zh":160,"released_at":161},255830,"v0.7.0","变更：\n- 后端已切换至 TensorFlow。\n- API 和命令行选项略有调整，相应更新了文档。\n- 在 .\u002Fexamples\u002Fconfig\u002Fdeepmedic 中更新了默认配置，新增三条路径。\n- 对代码进行了重构和重新组织。","2018-06-27T12:02:56",{"id":163,"version":164,"summary_zh":165,"released_at":166},255831,"v0.5.1","改进了进度的监控和图表展示。","2016-08-04T16:00:53",{"id":168,"version":169,"summary_zh":170,"released_at":171},255832,"v0.5","最初发布的版本，仅进行了少量错误修复。后续版本不向后兼容（即使用该版本训练的预训练模型无法在后续版本中加载）。\n","2016-08-04T15:58:12"]