[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-divamgupta--image-segmentation-keras":3,"tool-divamgupta--image-segmentation-keras":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},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,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},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 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":80,"owner_email":79,"owner_twitter":75,"owner_website":81,"owner_url":82,"languages":83,"stars":92,"forks":93,"last_commit_at":94,"license":95,"difficulty_score":23,"env_os":96,"env_gpu":97,"env_ram":98,"env_deps":99,"category_tags":105,"github_topics":79,"view_count":23,"oss_zip_url":79,"oss_zip_packed_at":79,"status":16,"created_at":106,"updated_at":107,"faqs":108,"releases":138},3902,"divamgupta\u002Fimage-segmentation-keras","image-segmentation-keras","Implementation of Segnet, FCN, UNet , PSPNet and other models in Keras.","image-segmentation-keras 是一个基于 Keras 框架开发的深度学习工具库，专注于实现多种主流图像语义分割模型。它旨在解决将图像中的每个像素精准分类的技术难题，帮助计算机“看懂”图片中不同物体的轮廓与区域，广泛应用于自动驾驶、医疗影像分析及卫星地图处理等领域。\n\n该工具特别适合 AI 开发者、研究人员以及希望快速验证算法的学生使用。其核心优势在于集成了 SegNet、FCN、U-Net、PSPNet 等经典架构，并支持 VGG、ResNet、MobileNet 等多种骨干网络作为基础，用户可根据实际需求灵活选择模型组合。除了提供标准的 Python 编程接口和命令行工具外，它还拥有完善的教程与 Google Colab 示例，大幅降低了上手门槛。此外，部分功能已与 Liner.ai 平台整合，提供了可视化的图形界面，让用户无需编写代码即可进行模型训练与推理导出。作为一个开源项目，image-segmentation-keras 以简洁的代码结构和丰富的预训练模型，成为进入图像分割领域的实用起点。","# Image Segmentation Keras : Implementation of Segnet, FCN, UNet, PSPNet and other models in Keras.\n\n[![PyPI version](https:\u002F\u002Fbadge.fury.io\u002Fpy\u002Fkeras-segmentation.svg)](https:\u002F\u002Fbadge.fury.io\u002Fpy\u002Fkeras-segmentation)\n[![Downloads](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_a9aef7920f47.png)](https:\u002F\u002Fpepy.tech\u002Fproject\u002Fkeras-segmentation)\n[![Build Status](https:\u002F\u002Ftravis-ci.org\u002Fdivamgupta\u002Fimage-segmentation-keras.png)](https:\u002F\u002Ftravis-ci.org\u002Fdivamgupta\u002Fimage-segmentation-keras)\n[![MIT license](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-blue.svg)](http:\u002F\u002Fperso.crans.org\u002Fbesson\u002FLICENSE.html)\n[![Twitter](https:\u002F\u002Fimg.shields.io\u002Ftwitter\u002Furl.svg?label=Follow%20%40divamgupta&style=social&url=https%3A%2F%2Ftwitter.com%2Fdivamgupta)](https:\u002F\u002Ftwitter.com\u002Fdivamgupta)\n\n\n\nImplementation of various Deep Image Segmentation models in keras.\n\n### News : Some functionality of this repository has been integrated with https:\u002F\u002Fliner.ai . Check it out!! \n\n\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_f52a1b3faaa9.png\" width=\"50%\" >\n\u003C\u002Fp>\n\nLink to the full blog post with tutorial : https:\u002F\u002Fdivamgupta.com\u002Fimage-segmentation\u002F2019\u002F06\u002F06\u002Fdeep-learning-semantic-segmentation-keras.html\n\n\n## Working Google Colab Examples:\n* Python Interface: https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1q_eCYEzKxixpCKH1YDsLnsvgxl92ORcv?usp=sharing\n* CLI Interface: https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1Kpy4QGFZ2ZHm69mPfkmLSUes8kj6Bjyi?usp=sharing\n\n## Training using GUI interface\nYou can also train segmentation models on your computer with https:\u002F\u002Fliner.ai  \n\nTrain   |  Inference \u002F Export\n:-------------------------:|:-------------------------:\n![https:\u002F\u002Fliner.ai ](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_dda283ff5c2b.png)  |  ![https:\u002F\u002Fliner.ai ](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_8997f0cdbc35.png)\n![https:\u002F\u002Fliner.ai ](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_36fca441a2ec.png)  |  ![https:\u002F\u002Fliner.ai ](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_192e6109ea7a.png)\n\n\n## Models\n\nFollowing models are supported:\n\n| model_name       | Base Model        | Segmentation Model |\n|------------------|-------------------|--------------------|\n| fcn_8            | Vanilla CNN       | FCN8               |\n| fcn_32           | Vanilla CNN       | FCN8               |\n| fcn_8_vgg        | VGG 16            | FCN8               |\n| fcn_32_vgg       | VGG 16            | FCN32              |\n| fcn_8_resnet50   | Resnet-50         | FCN32              |\n| fcn_32_resnet50  | Resnet-50         | FCN32              |\n| fcn_8_mobilenet  | MobileNet         | FCN32              |\n| fcn_32_mobilenet | MobileNet         | FCN32              |\n| pspnet           | Vanilla CNN       | PSPNet             |\n| pspnet_50        | Vanilla CNN       | PSPNet             |\n| pspnet_101       | Vanilla CNN       | PSPNet             |\n| vgg_pspnet       | VGG 16            | PSPNet             |\n| resnet50_pspnet  | Resnet-50         | PSPNet             |\n| unet_mini        | Vanilla Mini CNN  | U-Net              |\n| unet             | Vanilla CNN       | U-Net              |\n| vgg_unet         | VGG 16            | U-Net              |\n| resnet50_unet    | Resnet-50         | U-Net              |\n| mobilenet_unet   | MobileNet         | U-Net              |\n| segnet           | Vanilla CNN       | Segnet             |\n| vgg_segnet       | VGG 16            | Segnet             |\n| resnet50_segnet  | Resnet-50         | Segnet             |\n| mobilenet_segnet | MobileNet         | Segnet             |\n\n\nExample results for the pre-trained models provided :\n\nInput Image            |  Output Segmentation Image\n:-------------------------:|:-------------------------:\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_3eb7f400d4de.jpg)  |  ![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_6b780a8bafeb.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_579f1df6e944.jpg)  |  ![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_6e4d098c0d73.png)\n\n\n## How to cite\n\nIf you are using this library, please cite using:\n\n```\n@article{gupta2023image,\n  title={Image segmentation keras: Implementation of segnet, fcn, unet, pspnet and other models in keras},\n  author={Gupta, Divam},\n  journal={arXiv preprint arXiv:2307.13215},\n  year={2023}\n}\n\n```\n\n\n## Getting Started\n\n### Prerequisites\n\n* Keras ( recommended version : 2.4.3 )\n* OpenCV for Python\n* Tensorflow ( recommended  version : 2.4.1 )\n\n```shell\napt-get install -y libsm6 libxext6 libxrender-dev\npip install opencv-python\n```\n\n### Installing\n\nInstall the module\n\nRecommended way:\n```shell\npip install --upgrade git+https:\u002F\u002Fgithub.com\u002Fdivamgupta\u002Fimage-segmentation-keras\n```\n\n### or \n\n```shell\npip install keras-segmentation\n```\n\n### or\n\n```shell\ngit clone https:\u002F\u002Fgithub.com\u002Fdivamgupta\u002Fimage-segmentation-keras\ncd image-segmentation-keras\npython setup.py install\n```\n\n\n## Pre-trained models:\n```python\nfrom keras_segmentation.pretrained import pspnet_50_ADE_20K , pspnet_101_cityscapes, pspnet_101_voc12\n\nmodel = pspnet_50_ADE_20K() # load the pretrained model trained on ADE20k dataset\n\nmodel = pspnet_101_cityscapes() # load the pretrained model trained on Cityscapes dataset\n\nmodel = pspnet_101_voc12() # load the pretrained model trained on Pascal VOC 2012 dataset\n\n# load any of the 3 pretrained models\n\nout = model.predict_segmentation(\n    inp=\"input_image.jpg\",\n    out_fname=\"out.png\"\n)\n\n```\n\n\n### Preparing the data for training\n\nYou need to make two folders\n\n*  Images Folder - For all the training images\n* Annotations Folder - For the corresponding ground truth segmentation images\n\nThe filenames of the annotation images should be same as the filenames of the RGB images.\n\nThe size of the annotation image for the corresponding RGB image should be same.\n\nFor each pixel in the RGB image, the class label of that pixel in the annotation image would be the value of the blue pixel.\n\nExample code to generate annotation images :\n\n```python\nimport cv2\nimport numpy as np\n\nann_img = np.zeros((30,30,3)).astype('uint8')\nann_img[ 3 , 4 ] = 1 # this would set the label of pixel 3,4 as 1\n\ncv2.imwrite( \"ann_1.png\" ,ann_img )\n```\n\nOnly use bmp or png format for the annotation images.\n\n## Download the sample prepared dataset\n\nDownload and extract the following:\n\nhttps:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F0B0d9ZiqAgFkiOHR1NTJhWVJMNEU\u002Fview?usp=sharing\n\nYou will get a folder named dataset1\u002F\n\n\n## Using the python module\n\nYou can import keras_segmentation in  your python script and use the API\n\n```python\nfrom keras_segmentation.models.unet import vgg_unet\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608  )\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5\n)\n\nout = model.predict_segmentation(\n    inp=\"dataset1\u002Fimages_prepped_test\u002F0016E5_07965.png\",\n    out_fname=\"\u002Ftmp\u002Fout.png\"\n)\n\nimport matplotlib.pyplot as plt\nplt.imshow(out)\n\n# evaluating the model \nprint(model.evaluate_segmentation( inp_images_dir=\"dataset1\u002Fimages_prepped_test\u002F\"  , annotations_dir=\"dataset1\u002Fannotations_prepped_test\u002F\" ) )\n\n```\n\n\n## Usage via command line\nYou can also use the tool just using command line\n\n### Visualizing the prepared data\n\nYou can also visualize your prepared annotations for verification of the prepared data.\n\n\n```shell\npython -m keras_segmentation verify_dataset \\\n --images_path=\"dataset1\u002Fimages_prepped_train\u002F\" \\\n --segs_path=\"dataset1\u002Fannotations_prepped_train\u002F\"  \\\n --n_classes=50\n```\n\n```shell\npython -m keras_segmentation visualize_dataset \\\n --images_path=\"dataset1\u002Fimages_prepped_train\u002F\" \\\n --segs_path=\"dataset1\u002Fannotations_prepped_train\u002F\"  \\\n --n_classes=50\n```\n\n\n\n### Training the Model\n\nTo train the model run the following command:\n\n```shell\npython -m keras_segmentation train \\\n --checkpoints_path=\"path_to_checkpoints\" \\\n --train_images=\"dataset1\u002Fimages_prepped_train\u002F\" \\\n --train_annotations=\"dataset1\u002Fannotations_prepped_train\u002F\" \\\n --val_images=\"dataset1\u002Fimages_prepped_test\u002F\" \\\n --val_annotations=\"dataset1\u002Fannotations_prepped_test\u002F\" \\\n --n_classes=50 \\\n --input_height=320 \\\n --input_width=640 \\\n --model_name=\"vgg_unet\"\n```\n\nChoose model_name from the table above\n\n\n\n### Getting the predictions\n\nTo get the predictions of a trained model\n\n```shell\npython -m keras_segmentation predict \\\n --checkpoints_path=\"path_to_checkpoints\" \\\n --input_path=\"dataset1\u002Fimages_prepped_test\u002F\" \\\n --output_path=\"path_to_predictions\"\n\n```\n\n\n\n### Video inference\n\nTo get predictions of a video\n```shell\npython -m keras_segmentation predict_video \\\n --checkpoints_path=\"path_to_checkpoints\" \\\n --input=\"path_to_video\" \\\n --output_file=\"path_for_save_inferenced_video\" \\\n --display\n```\n\nIf you want to make predictions on your webcam, don't use `--input`, or pass your device number: `--input 0`  \n`--display` opens a window with the predicted video. Remove this argument when using a headless system.\n\n\n### Model Evaluation \n\nTo get the IoU scores \n\n```shell\npython -m keras_segmentation evaluate_model \\\n --checkpoints_path=\"path_to_checkpoints\" \\\n --images_path=\"dataset1\u002Fimages_prepped_test\u002F\" \\\n --segs_path=\"dataset1\u002Fannotations_prepped_test\u002F\"\n```\n\n\n\n## Fine-tuning from existing segmentation model\n\nThe following example shows how to fine-tune a model with 10 classes .\n\n```python\nfrom keras_segmentation.models.model_utils import transfer_weights\nfrom keras_segmentation.pretrained import pspnet_50_ADE_20K\nfrom keras_segmentation.models.pspnet import pspnet_50\n\npretrained_model = pspnet_50_ADE_20K()\n\nnew_model = pspnet_50( n_classes=51 )\n\ntransfer_weights( pretrained_model , new_model  ) # transfer weights from pre-trained model to your model\n\nnew_model.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5\n)\n\n\n```\n\n\n\n## Knowledge distillation for compressing the model\n\nThe following example shows transfer the knowledge from a larger ( and more accurate ) model to a smaller model. In most cases the smaller model trained via knowledge distilation is more accurate compared to the same model trained using vanilla supervised learning. \n\n```python\nfrom keras_segmentation.predict import model_from_checkpoint_path\nfrom keras_segmentation.models.unet import unet_mini\nfrom keras_segmentation.model_compression import perform_distilation\n\nmodel_large = model_from_checkpoint_path( \"\u002Fcheckpoints\u002Fpath\u002Fof\u002Ftrained\u002Fmodel\" )\nmodel_small = unet_mini( n_classes=51, input_height=300, input_width=400  )\n\nperform_distilation ( data_path=\"\u002Fpath\u002Fto\u002Flarge_image_set\u002F\" , checkpoints_path=\"path\u002Fto\u002Fsave\u002Fcheckpoints\" , \n    teacher_model=model_large ,  student_model=model_small  , distilation_loss='kl' , feats_distilation_loss='pa' )\n\n```\n\n\n\n\n\n## Adding custom augmentation function to training\n\nThe following example shows how to define a custom augmentation function for training.\n\n```python\n\nfrom keras_segmentation.models.unet import vgg_unet\nfrom imgaug import augmenters as iaa\n\ndef custom_augmentation():\n    return  iaa.Sequential(\n        [\n            # apply the following augmenters to most images\n            iaa.Fliplr(0.5),  # horizontally flip 50% of all images\n            iaa.Flipud(0.5), # horizontally flip 50% of all images\n        ])\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608)\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5, \n    do_augment=True, # enable augmentation \n    custom_augmentation=custom_augmentation # sets the augmention function to use\n)\n```\n## Custom number of input channels\n\nThe following example shows how to set the number of input channels.\n\n```python\n\nfrom keras_segmentation.models.unet import vgg_unet\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608, \n                 channels=1 # Sets the number of input channels\n                 )\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5, \n    read_image_type=0  # Sets how opencv will read the images\n                       # cv2.IMREAD_COLOR = 1 (rgb),\n                       # cv2.IMREAD_GRAYSCALE = 0,\n                       # cv2.IMREAD_UNCHANGED = -1 (4 channels like RGBA)\n)\n```\n\n## Custom preprocessing\n\nThe following example shows how to set a custom image preprocessing function.\n\n```python\n\nfrom keras_segmentation.models.unet import vgg_unet\n\ndef image_preprocessing(image):\n    return image + 1\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608)\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5,\n    preprocessing=image_preprocessing # Sets the preprocessing function\n)\n```\n\n## Custom callbacks\n\nThe following example shows how to set custom callbacks for the model training.\n\n```python\n\nfrom keras_segmentation.models.unet import vgg_unet\nfrom keras.callbacks import ModelCheckpoint, EarlyStopping\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608 )\n\n# When using custom callbacks, the default checkpoint saver is removed\ncallbacks = [\n    ModelCheckpoint(\n                filepath=\"checkpoints\u002F\" + model.name + \".{epoch:05d}\",\n                save_weights_only=True,\n                verbose=True\n            ),\n    EarlyStopping()\n]\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5,\n    callbacks=callbacks\n)\n```\n\n## Multi input image input\n\nThe following example shows how to add additional image inputs for models.\n\n```python\n\nfrom keras_segmentation.models.unet import vgg_unet\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608)\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5,\n    other_inputs_paths=[\n        \"\u002Fpath\u002Fto\u002Fother\u002Fdirectory\"\n    ],\n    \n    \n#     Ability to add preprocessing\n    preprocessing=[lambda x: x+1, lambda x: x+2, lambda x: x+3], # Different prepocessing for each input\n#     OR\n    preprocessing=lambda x: x+1, # Same preprocessing for each input\n)\n```\n\n\n## Projects using keras-segmentation\nHere are a few projects which are using our library :\n* https:\u002F\u002Fgithub.com\u002FSteliosTsop\u002FQF-image-segmentation-keras [paper](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1908.02242.pdf)\n* https:\u002F\u002Fgithub.com\u002Fwillembressers\u002Fbouquet_quality\n* https:\u002F\u002Fgithub.com\u002Fjqueguiner\u002Fimage-segmentation\n* https:\u002F\u002Fgithub.com\u002Fpan0rama\u002FCS230-Microcrystal-Facet-Segmentation\n* https:\u002F\u002Fgithub.com\u002Ftheerawatramchuen\u002FKeras_Segmentation\n* https:\u002F\u002Fgithub.com\u002Fneheller\u002Flabels18\n* https:\u002F\u002Fgithub.com\u002FDivyam10\u002FFace-Matting-using-Unet\n* https:\u002F\u002Fgithub.com\u002Fshsh-a\u002Fsegmentation-over-web\n* https:\u002F\u002Fgithub.com\u002Fchenwe73\u002Fdeep_active_learning_segmentation\n* https:\u002F\u002Fgithub.com\u002Fvigneshrajap\u002Fvision-based-navigation-agri-fields\n* https:\u002F\u002Fgithub.com\u002Fronalddas\u002FPneumonia-Detection\n* https:\u002F\u002Fgithub.com\u002FAiwiscal\u002FECG_UNet\n* https:\u002F\u002Fgithub.com\u002FTianzhongSong\u002FUnet-for-Person-Segmentation\n* https:\u002F\u002Fgithub.com\u002FGuyanqi\u002FGMDNN\n* https:\u002F\u002Fgithub.com\u002Fkozemzak\u002Fprostate-lesion-segmentation\n* https:\u002F\u002Fgithub.com\u002Flixiaoyu12138\u002Ffcn-date\n* https:\u002F\u002Fgithub.com\u002Fsagarbhokre\u002FLyftChallenge\n* https:\u002F\u002Fgithub.com\u002FTianzhongSong\u002FPerson-Segmentation-Keras\n* https:\u002F\u002Fgithub.com\u002Fdivyanshpuri02\u002FCOCO_2018-Stuff-Segmentation-Challenge\n* https:\u002F\u002Fgithub.com\u002FXiangbingJi\u002FStanford-cs230-final-project\n* https:\u002F\u002Fgithub.com\u002Flsh1994\u002Fkeras-segmentation\n* https:\u002F\u002Fgithub.com\u002FSpirinEgor\u002Fmobile_semantic_segmentation\n* https:\u002F\u002Fgithub.com\u002FLeadingIndiaAI\u002FCOCO-DATASET-STUFF-SEGMENTATION-CHALLENGE\n* https:\u002F\u002Fgithub.com\u002Flidongyue12138\u002FImage-Segmentation-by-Keras\n* https:\u002F\u002Fgithub.com\u002Flaoj2\u002Fsegnet_crfasrnn\n* https:\u002F\u002Fgithub.com\u002Francheng\u002FAirSimProjects\n* https:\u002F\u002Fgithub.com\u002FRadiumScriptTang\u002Fcartoon_segmentation\n* https:\u002F\u002Fgithub.com\u002Fdquail\u002FNerveSegmentation\n* https:\u002F\u002Fgithub.com\u002FBhomik\u002FSemanticHumanMatting\n* https:\u002F\u002Fgithub.com\u002FSymefa\u002FFP-Biomedik-Breast-Cancer\n* https:\u002F\u002Fgithub.com\u002FAlpha-Monocerotis\u002FPDF_FigureTable_Extraction\n* https:\u002F\u002Fgithub.com\u002Frusito-23\u002Fmobile_unet_segmentation\n* https:\u002F\u002Fgithub.com\u002FPhilliec459\u002FThinSection-image-segmentation-keras\n* https:\u002F\u002Fgithub.com\u002Fimsadia\u002Fcv-assignment-three.git\n* https:\u002F\u002Fgithub.com\u002Fkejitan\u002FESVGscale\n\nIf you use our code in a publicly available project, please add the link here ( by posting an issue or creating a PR )\n\n","# Keras图像分割：在Keras中实现SegNet、FCN、U-Net、PSPNet等模型。\n\n[![PyPI版本](https:\u002F\u002Fbadge.fury.io\u002Fpy\u002Fkeras-segmentation.svg)](https:\u002F\u002Fbadge.fury.io\u002Fpy\u002Fkeras-segmentation)\n[![下载量](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_a9aef7920f47.png)](https:\u002F\u002Fpepy.tech\u002Fproject\u002Fkeras-segmentation)\n[![构建状态](https:\u002F\u002Ftravis-ci.org\u002Fdivamgupta\u002Fimage-segmentation-keras.png)](https:\u002F\u002Ftravis-ci.org\u002Fdivamgupta\u002Fimage-segmentation-keras)\n[![MIT许可证](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-blue.svg)](http:\u002F\u002Fperso.crans.org\u002Fbesson\u002FLICENSE.html)\n[![Twitter](https:\u002F\u002Fimg.shields.io\u002Ftwitter\u002Furl.svg?label=关注%20@divamgupta&style=social&url=https%3A%2F%2Ftwitter.com%2Fdivamgupta)](https:\u002F\u002Ftwitter.com\u002Fdivamgupta)\n\n\n\n在Keras中实现多种深度图像分割模型。\n\n### 新闻：该仓库的部分功能已集成到https:\u002F\u002Fliner.ai。快去看看吧！！\n\n\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_f52a1b3faaa9.png\" width=\"50%\" >\n\u003C\u002Fp>\n\n完整博客文章及教程链接：https:\u002F\u002Fdivamgupta.com\u002Fimage-segmentation\u002F2019\u002F06\u002F06\u002Fdeep-learning-semantic-segmentation-keras.html\n\n\n## 可运行的Google Colab示例：\n* Python接口：https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1q_eCYEzKxixpCKH1YDsLnsvgxl92ORcv?usp=sharing\n* CLI接口：https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1Kpy4QGFZ2ZHm69mPfkmLSUes8kj6Bjyi?usp=sharing\n\n## 使用GUI界面进行训练\n您也可以通过https:\u002F\u002Fliner.ai在您的计算机上训练分割模型。\n\n训练   |  推理 \u002F 导出\n:-------------------------:|:-------------------------:\n![https:\u002F\u002Fliner.ai ](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_dda283ff5c2b.png)  |  ![https:\u002F\u002Fliner.ai ](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_8997f0cdbc35.png)\n![https:\u002F\u002Fliner.ai ](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_36fca441a2ec.png)  |  ![https:\u002F\u002Fliner.ai ](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_192e6109ea7a.png)\n\n\n## 模型\n\n支持以下模型：\n\n| model_name       | 基础模型        | 分割模型 |\n|------------------|-------------------|--------------------|\n| fcn_8            | 原生CNN       | FCN8               |\n| fcn_32           | 原生CNN       | FCN8               |\n| fcn_8_vgg        | VGG 16            | FCN8               |\n| fcn_32_vgg       | VGG 16            | FCN32              |\n| fcn_8_resnet50   | Resnet-50         | FCN32              |\n| fcn_32_resnet50  | Resnet-50         | FCN32              |\n| fcn_8_mobilenet  | MobileNet         | FCN32              |\n| fcn_32_mobilenet | MobileNet         | FCN32              |\n| pspnet           | 原生CNN       | PSPNet             |\n| pspnet_50        | 原生CNN       | PSPNet             |\n| pspnet_101       | 原生CNN       | PSPNet             |\n| vgg_pspnet       | VGG 16            | PSPNet             |\n| resnet50_pspnet  | Resnet-50         | PSPNet             |\n| unet_mini        | 原生Mini CNN  | U-Net              |\n| unet             | 原生CNN       | U-Net              |\n| vgg_unet         | VGG 16            | U-Net              |\n| resnet50_unet    | Resnet-50         | U-Net              |\n| mobilenet_unet   | MobileNet         | U-Net              |\n| segnet           | 原生CNN       | Segnet             |\n| vgg_segnet       | VGG 16            | Segnet             |\n| resnet50_segnet  | Resnet-50         | Segnet             |\n| mobilenet_segnet | MobileNet         | Segnet             |\n\n\n提供的预训练模型示例结果：\n\n输入图像            |  输出分割图像\n:-------------------------:|:-------------------------:\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_3eb7f400d4de.jpg)  |  ![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_6b780a8bafeb.png)\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_579f1df6e944.jpg)  |  ![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_readme_6e4d098c0d73.png)\n\n\n## 如何引用\n\n如果您使用此库，请使用以下方式引用：\n\n```\n@article{gupta2023image,\n  title={Image segmentation keras: Implementation of segnet, fcn, unet, pspnet and other models in keras},\n  author={Gupta, Divam},\n  journal={arXiv preprint arXiv:2307.13215},\n  year={2023}\n}\n\n```\n\n\n## 入门指南\n\n### 先决条件\n\n* Keras（推荐版本：2.4.3）\n* OpenCV for Python\n* Tensorflow（推荐版本：2.4.1）\n\n```shell\napt-get install -y libsm6 libxext6 libxrender-dev\npip install opencv-python\n```\n\n### 安装\n\n安装模块\n\n推荐方式：\n```shell\npip install --upgrade git+https:\u002F\u002Fgithub.com\u002Fdivamgupta\u002Fimage-segmentation-keras\n```\n\n### 或者 \n\n```shell\npip install keras-segmentation\n```\n\n### 或者\n\n```shell\ngit clone https:\u002F\u002Fgithub.com\u002Fdivamgupta\u002Fimage-segmentation-keras\ncd image-segmentation-keras\npython setup.py install\n```\n\n\n## 预训练模型：\n```python\nfrom keras_segmentation.pretrained import pspnet_50_ADE_20K , pspnet_101_cityscapes, pspnet_101_voc12\n\nmodel = pspnet_50_ADE_20K() # 加载在ADE20k数据集上训练的预训练模型\n\nmodel = pspnet_101_cityscapes() # 加载在Cityscapes数据集上训练的预训练模型\n\nmodel = pspnet_101_voc12() # 加载在Pascal VOC 2012数据集上训练的预训练模型\n\n# 加载以上任意一个预训练模型\n\nout = model.predict_segmentation(\n    inp=\"input_image.jpg\",\n    out_fname=\"out.png\"\n)\n\n```\n\n\n### 准备训练数据\n\n您需要创建两个文件夹：\n\n* 图像文件夹——用于所有训练图像\n* 标注文件夹——用于对应的真值分割图像\n\n标注图像的文件名应与RGB图像的文件名相同。\n\n标注图像的尺寸应与对应RGB图像的尺寸一致。\n\n对于RGB图像中的每个像素，其在标注图像中的类别标签即为该像素的蓝色通道值。\n\n生成标注图像的示例代码：\n\n```python\nimport cv2\nimport numpy as np\n\nann_img = np.zeros((30,30,3)).astype('uint8')\nann_img[ 3 , 4 ] = 1 # 这会将像素3,4的标签设置为1\n\ncv2.imwrite( \"ann_1.png\" ,ann_img )\n```\n\n标注图像仅支持bmp或png格式。\n\n## 下载示例准备好的数据集\n\n下载并解压以下文件：\n\nhttps:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F0B0d9ZiqAgFkiOHR1NTJhWVJMNEU\u002Fview?usp=sharing\n\n您将得到一个名为dataset1\u002F的文件夹。\n\n\n## 使用Python模块\n\n您可以在Python脚本中导入keras_segmentation并使用API。\n\n```python\nfrom keras_segmentation.models.unet import vgg_unet\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608  )\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5\n)\n\nout = model.predict_segmentation(\n    inp=\"dataset1\u002Fimages_prepped_test\u002F0016E5_07965.png\",\n    out_fname=\"\u002Ftmp\u002Fout.png\"\n)\n\nimport matplotlib.pyplot as plt\nplt.imshow(out)\n\n# 评估模型 \nprint(model.evaluate_segmentation( inp_images_dir=\"dataset1\u002Fimages_prepped_test\u002F\"  , annotations_dir=\"dataset1\u002Fannotations_prepped_test\u002F\" ) )\n\n```\n\n\n## 通过命令行使用\n您也可以仅使用命令行来使用该工具。\n\n### 可视化准备好的数据\n\n你还可以可视化准备好的标注数据，以验证数据是否正确准备。\n\n```shell\npython -m keras_segmentation verify_dataset \\\n --images_path=\"dataset1\u002Fimages_prepped_train\u002F\" \\\n --segs_path=\"dataset1\u002Fannotations_prepped_train\u002F\"  \\\n --n_classes=50\n```\n\n```shell\npython -m keras_segmentation visualize_dataset \\\n --images_path=\"dataset1\u002Fimages_prepped_train\u002F\" \\\n --segs_path=\"dataset1\u002Fannotations_prepped_train\u002F\"  \\\n --n_classes=50\n```\n\n\n\n### 训练模型\n\n要训练模型，请运行以下命令：\n\n```shell\npython -m keras_segmentation train \\\n --checkpoints_path=\"path_to_checkpoints\" \\\n --train_images=\"dataset1\u002Fimages_prepped_train\u002F\" \\\n --train_annotations=\"dataset1\u002Fannotations_prepped_train\u002F\" \\\n --val_images=\"dataset1\u002Fimages_prepped_test\u002F\" \\\n --val_annotations=\"dataset1\u002Fannotations_prepped_test\u002F\" \\\n --n_classes=50 \\\n --input_height=320 \\\n --input_width=640 \\\n --model_name=\"vgg_unet\"\n```\n\n请从上表中选择 `model_name`。\n\n\n\n### 获取预测结果\n\n要获取已训练模型的预测结果：\n\n```shell\npython -m keras_segmentation predict \\\n --checkpoints_path=\"path_to_checkpoints\" \\\n --input_path=\"dataset1\u002Fimages_prepped_test\u002F\" \\\n --output_path=\"path_to_predictions\"\n\n```\n\n\n\n### 视频推理\n\n要对视频进行预测：\n\n```shell\npython -m keras_segmentation predict_video \\\n --checkpoints_path=\"path_to_checkpoints\" \\\n --input=\"path_to_video\" \\\n --output_file=\"path_for_save_inferenced_video\" \\\n --display\n```\n\n如果你想对网络摄像头进行预测，不要使用 `--input` 参数，或者直接传入设备编号：`--input 0`。`--display` 参数会打开一个窗口显示预测后的视频。在无头系统中，请移除此参数。\n\n\n\n### 模型评估\n\n要获取 IoU 分数：\n\n```shell\npython -m keras_segmentation evaluate_model \\\n --checkpoints_path=\"path_to_checkpoints\" \\\n --images_path=\"dataset1\u002Fimages_prepped_test\u002F\" \\\n --segs_path=\"dataset1\u002Fannotations_prepped_test\u002F\"\n```\n\n\n\n## 从现有分割模型进行微调\n\n以下示例展示了如何对一个具有 10 个类别的模型进行微调。\n\n```python\nfrom keras_segmentation.models.model_utils import transfer_weights\nfrom keras_segmentation.pretrained import pspnet_50_ADE_20K\nfrom keras_segmentation.models.pspnet import pspnet_50\n\npretrained_model = pspnet_50_ADE_20K()\n\nnew_model = pspnet_50( n_classes=51 )\n\ntransfer_weights( pretrained_model , new_model  ) # 将预训练模型的权重迁移到你的模型\n\nnew_model.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5\n)\n```\n\n\n\n## 知识蒸馏压缩模型\n\n以下示例展示了如何将知识从较大的（且更精确的）模型迁移到较小的模型中。在大多数情况下，通过知识蒸馏训练的小模型比使用普通监督学习训练的相同模型更加精确。\n\n```python\nfrom keras_segmentation.predict import model_from_checkpoint_path\nfrom keras_segmentation.models.unet import unet_mini\nfrom keras_segmentation.model_compression import perform_distilation\n\nmodel_large = model_from_checkpoint_path( \"\u002Fcheckpoints\u002Fpath\u002Fof\u002Ftrained\u002Fmodel\" )\nmodel_small = unet_mini( n_classes=51, input_height=300, input_width=400  )\n\nperform_distilation ( data_path=\"\u002Fpath\u002Fto\u002Flarge_image_set\u002F\" , checkpoints_path=\"path\u002Fto\u002Fsave\u002Fcheckpoints\" , \n    teacher_model=model_large ,  student_model=model_small  , distilation_loss='kl' , feats_distilation_loss='pa' )\n```\n\n\n\n\n\n## 在训练中添加自定义增强函数\n\n以下示例展示了如何定义一个用于训练的自定义增强函数。\n\n```python\n\nfrom keras_segmentation.models.unet import vgg_unet\nfrom imgaug import augmenters as iaa\n\ndef custom_augmentation():\n    return  iaa.Sequential(\n        [\n            # 对大多数图像应用以下增强操作\n            iaa.Fliplr(0.5),  \u002F\u002F 水平翻转 50% 的图像\n            iaa.Flipud(0.5), \u002F\u002F 垂直翻转 50% 的图像\n        ])\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608)\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5, \n    do_augment=True, \u002F\u002F 启用数据增强\n    custom_augmentation=custom_augmentation \u002F\u002F 设置使用的增强函数\n)\n```\n## 自定义输入通道数\n\n以下示例展示了如何设置输入通道数。\n\n```python\n\nfrom keras_segmentation.models.unet import vgg_unet\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608, \n                 channels=1 \u002F\u002F 设置输入通道数\n                 )\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5, \n    read_image_type=0  \u002F\u002F 设置 OpenCV 读取图像的方式\n                       \u002F\u002F cv2.IMREAD_COLOR = 1 (RGB),\n                       \u002F\u002F cv2.IMREAD_GRAYSCALE = 0,\n                       \u002F\u002F cv2.IMREAD_UNCHANGED = -1 (RGBA 四通道)\n)\n```\n\n## 自定义预处理\n\n以下示例展示了如何设置自定义的图像预处理函数。\n\n```python\n\nfrom keras_segmentation.models.unet import vgg_unet\n\ndef image_preprocessing(image):\n    return image + 1\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608)\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5,\n    preprocessing=image_preprocessing \u002F\u002F 设置预处理函数\n)\n```\n\n## 自定义回调函数\n\n以下示例展示了如何为模型训练设置自定义回调函数。\n\n```python\n\nfrom keras_segmentation.models.unet import vgg_unet\nfrom keras.callbacks import ModelCheckpoint, EarlyStopping\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608 )\n\n\u002F\u002F 使用自定义回调时，会移除默认的检查点保存器\ncallbacks = [\n    ModelCheckpoint(\n                filepath=\"checkpoints\u002F\" + model.name + \".{epoch:05d}\",\n                save_weights_only=True,\n                verbose=True\n            ),\n    EarlyStopping()\n]\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5,\n    callbacks=callbacks\n)\n```\n\n## 多输入图像输入\n\n以下示例展示了如何为模型添加额外的图像输入。\n\n```python\n\nfrom keras_segmentation.models.unet import vgg_unet\n\nmodel = vgg_unet(n_classes=51 ,  input_height=416, input_width=608)\n\nmodel.train(\n    train_images =  \"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations = \"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path = \"\u002Ftmp\u002Fvgg_unet_1\" , epochs=5,\n    other_inputs_paths=[\n        \"\u002Fpath\u002Fto\u002Fother\u002Fdirectory\"\n    ],\n    \n    \n#     可以添加预处理\n    preprocessing=[lambda x: x+1, lambda x: x+2, lambda x: x+3], # 每个输入使用不同的预处理\n#     或者\n    preprocessing=lambda x: x+1, # 所有输入使用相同的预处理\n)\n```\n\n\n## 使用 keras-segmentation 的项目\n以下是一些正在使用我们库的项目：\n* https:\u002F\u002Fgithub.com\u002FSteliosTsop\u002FQF-image-segmentation-keras [论文](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1908.02242.pdf)\n* https:\u002F\u002Fgithub.com\u002Fwillembressers\u002Fbouquet_quality\n* https:\u002F\u002Fgithub.com\u002Fjqueguiner\u002Fimage-segmentation\n* https:\u002F\u002Fgithub.com\u002Fpan0rama\u002FCS230-Microcrystal-Facet-Segmentation\n* https:\u002F\u002Fgithub.com\u002Ftheerawatramchuen\u002FKeras_Segmentation\n* https:\u002F\u002Fgithub.com\u002Fneheller\u002Flabels18\n* https:\u002F\u002Fgithub.com\u002FDivyam10\u002FFace-Matting-using-Unet\n* https:\u002F\u002Fgithub.com\u002Fshsh-a\u002Fsegmentation-over-web\n* https:\u002F\u002Fgithub.com\u002Fchenwe73\u002Fdeep_active_learning_segmentation\n* https:\u002F\u002Fgithub.com\u002Fvigneshrajap\u002Fvision-based-navigation-agri-fields\n* https:\u002F\u002Fgithub.com\u002Fronalddas\u002FPneumonia-Detection\n* https:\u002F\u002Fgithub.com\u002FAiwiscal\u002FECG_UNet\n* https:\u002F\u002Fgithub.com\u002FTianzhongSong\u002FUnet-for-Person-Segmentation\n* https:\u002F\u002Fgithub.com\u002FGuyanqi\u002FGMDNN\n* https:\u002F\u002Fgithub.com\u002Fkozemzak\u002Fprostate-lesion-segmentation\n* https:\u002F\u002Fgithub.com\u002Flixiaoyu12138\u002Ffcn-date\n* https:\u002F\u002Fgithub.com\u002Fsagarbhokre\u002FLyftChallenge\n* https:\u002F\u002Fgithub.com\u002FTianzhongSong\u002FPerson-Segmentation-Keras\n* https:\u002F\u002Fgithub.com\u002Fdivyanshpuri02\u002FCOCO_2018-Stuff-Segmentation-Challenge\n* https:\u002F\u002Fgithub.com\u002FXiangbingJi\u002FStanford-cs230-final-project\n* https:\u002F\u002Fgithub.com\u002Flsh1994\u002Fkeras-segmentation\n* https:\u002F\u002Fgithub.com\u002FSpirinEgor\u002Fmobile_semantic_segmentation\n* https:\u002F\u002Fgithub.com\u002FLeadingIndiaAI\u002FCOCO-DATASET-STUFF-SEGMENTATION-CHALLENGE\n* https:\u002F\u002Fgithub.com\u002Flidongyue12138\u002FImage-Segmentation-by-Keras\n* https:\u002F\u002Fgithub.com\u002Flaoj2\u002Fsegnet_crfasrnn\n* https:\u002F\u002Fgithub.com\u002Francheng\u002FAirSimProjects\n* https:\u002F\u002Fgithub.com\u002FRadiumScriptTang\u002Fcartoon_segmentation\n* https:\u002F\u002Fgithub.com\u002Fdquail\u002FNerveSegmentation\n* https:\u002F\u002Fgithub.com\u002FBhomik\u002FSemanticHumanMatting\n* https:\u002F\u002Fgithub.com\u002FSymefa\u002FFP-Biomedik-Breast-Cancer\n* https:\u002F\u002Fgithub.com\u002FAlpha-Monocerotis\u002FPDF_FigureTable_Extraction\n* https:\u002F\u002Fgithub.com\u002Frusito-23\u002Fmobile_unet_segmentation\n* https:\u002F\u002Fgithub.com\u002FPhilliec459\u002FThinSection-image-segmentation-keras\n* https:\u002F\u002Fgithub.com\u002Fimsadia\u002Fcv-assignment-three.git\n* https:\u002F\u002Fgithub.com\u002Fkejitan\u002FESVGscale\n\n如果您在公开可用的项目中使用了我们的代码，请在此处添加链接（通过提交 issue 或创建 PR）。","# image-segmentation-keras 快速上手指南\n\n`image-segmentation-keras` 是一个基于 Keras 实现的深度学习图像分割工具库，内置了 SegNet、FCN、U-Net、PSPNet 等多种主流模型。本指南将帮助你快速完成环境配置、安装及基础使用。\n\n## 1. 环境准备\n\n在开始之前，请确保你的系统满足以下要求：\n\n*   **操作系统**: Linux (推荐), macOS, Windows\n*   **Python**: 3.6+\n*   **核心依赖**:\n    *   TensorFlow (推荐版本: 2.4.1)\n    *   Keras (推荐版本: 2.4.3)\n    *   OpenCV for Python\n\n### 安装系统级依赖 (Linux)\n如果你使用的是 Ubuntu\u002FDebian 系统，需要先安装 OpenCV 所需的系统库：\n\n```shell\napt-get install -y libsm6 libxext6 libxrender-dev\n```\n\n### 安装 Python 依赖\n建议先安装基础的 Python 包。国内用户可使用清华或阿里镜像源加速安装：\n\n```shell\npip install opencv-python tensorflow==2.4.1 keras==2.4.3 -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n## 2. 安装步骤\n\n你可以通过以下任意一种方式安装 `keras-segmentation`：\n\n### 方式一：通过 PyPI 安装（推荐）\n最简单的方式，适合大多数用户：\n\n```shell\npip install keras-segmentation\n```\n\n### 方式二：从 GitHub 源码安装（获取最新功能）\n如果需要最新的功能修复或未发布的特性：\n\n```shell\npip install --upgrade git+https:\u002F\u002Fgithub.com\u002Fdivamgupta\u002Fimage-segmentation-keras\n```\n\n### 方式三：本地源码安装\n适合需要修改源码的开发者：\n\n```shell\ngit clone https:\u002F\u002Fgithub.com\u002Fdivamgupta\u002Fimage-segmentation-keras\ncd image-segmentation-keras\npython setup.py install\n```\n\n## 3. 基本使用\n\n### 场景 A：直接使用预训练模型进行推理\n如果你只想快速测试效果，可以直接加载官方提供的预训练模型（基于 ADE20k、Cityscapes 或 Pascal VOC 数据集训练）。\n\n```python\nfrom keras_segmentation.pretrained import pspnet_50_ADE_20K\n\n# 加载在 ADE20k 数据集上预训练的 PSPNet-50 模型\nmodel = pspnet_50_ADE_20K() \n\n# 执行分割预测\n# inp: 输入图片路径，out_fname: 输出结果保存路径\nout = model.predict_segmentation(\n    inp=\"input_image.jpg\",\n    out_fname=\"out.png\"\n)\n```\n\n### 场景 B：训练自定义模型\n如果你有标注好的数据集，可以训练自己的模型。\n\n**数据准备要求：**\n1.  **images_folder**: 存放原始训练图片。\n2.  **annotations_folder**: 存放对应的分割掩码（Mask）图片。\n    *   文件名必须与原始图片一致。\n    *   尺寸必须与原始图片一致。\n    *   格式建议使用 `.png` 或 `.bmp`。\n    *   **标签规则**: 像素点的类别标签由该像素在 Mask 图中的 **蓝色通道 (Blue Channel)** 值决定。\n\n**训练代码示例：**\n\n```python\nfrom keras_segmentation.models.unet import vgg_unet\n\n# 初始化模型 (以 VGG-U-Net 为例)\n# n_classes: 类别数量 (包含背景类)\nmodel = vgg_unet(n_classes=51, input_height=416, input_width=608)\n\n# 开始训练\nmodel.train(\n    train_images=\"dataset1\u002Fimages_prepped_train\u002F\",\n    train_annotations=\"dataset1\u002Fannotations_prepped_train\u002F\",\n    checkpoints_path=\"\u002Ftmp\u002Fvgg_unet_1\", # 模型权重保存路径\n    epochs=5\n)\n\n# 使用训练好的模型进行预测\nout = model.predict_segmentation(\n    inp=\"dataset1\u002Fimages_prepped_test\u002F0016E5_07965.png\",\n    out_fname=\"\u002Ftmp\u002Fout.png\"\n)\n\n# 可选：评估模型性能 (输出 IoU 等指标)\nprint(model.evaluate_segmentation(\n    inp_images_dir=\"dataset1\u002Fimages_prepped_test\u002F\",\n    annotations_dir=\"dataset1\u002Fannotations_prepped_test\u002F\"\n))\n```\n\n### 场景 C：命令行工具 (CLI)\n如果不希望编写 Python 脚本，也可以直接使用命令行进行操作。\n\n**验证数据集格式：**\n```shell\npython -m keras_segmentation verify_dataset \\\n --images_path=\"dataset1\u002Fimages_prepped_train\u002F\" \\\n --segs_path=\"dataset1\u002Fannotations_prepped_train\u002F\" \\\n --n_classes=50\n```\n\n**训练模型：**\n```shell\npython -m keras_segmentation train \\\n --checkpoints_path=\"path_to_checkpoints\" \\\n --train_images=\"dataset1\u002Fimages_prepped_train\u002F\" \\\n --train_annotations=\"dataset1\u002Fannotations_prepped_train\u002F\" \\\n --val_images=\"dataset1\u002Fimages_prepped_test\u002F\" \\\n --val_annotations=\"dataset1\u002Fannotations_prepped_test\u002F\" \\\n --n_classes=50 \\\n --input_height=320 \\\n --input_width=640 \\\n --model_name=\"vgg_unet\"\n```\n\n**批量预测：**\n```shell\npython -m keras_segmentation predict \\\n --checkpoints_path=\"path_to_checkpoints\" \\\n --input_path=\"dataset1\u002Fimages_prepped_test\u002F\" \\\n --output_path=\"path_to_predictions\"\n```\n\n> **提示**: 支持的模型名称包括 `vgg_unet`, `segnet`, `fcn_8_vgg`, `pspnet_50` 等，具体可参考官方文档模型列表。","某智慧农业团队正致力于开发一套无人机作物病害监测系统，需要快速从航拍图中精准提取病斑区域以评估受灾面积。\n\n### 没有 image-segmentation-keras 时\n- **模型复现成本极高**：团队成员需手动查阅 FCN、U-Net 等论文的数学公式，从零搭建复杂的编码器 - 解码器架构，耗时数周且极易出错。\n- **基线对比困难**：想要验证哪种主干网络（如 VGG16 或 ResNet50）更适合当前数据集，必须为每种组合单独编写训练代码，实验迭代周期长达数月。\n- **数据预处理繁琐**：缺乏统一的接口来处理标注掩码（Mask）和图像增强，导致数据加载逻辑与模型训练逻辑强耦合，代码维护性差。\n- **部署门槛高**：将训练好的模型导出并集成到边缘设备（如无人机机载电脑）时，因缺乏标准的推理脚本，往往需要重新重写后端逻辑。\n\n### 使用 image-segmentation-keras 后\n- **开箱即用的模型库**：直接调用 `unet`、`pspnet` 或 `segnet` 等预置模型，一行代码即可切换不同架构，将模型搭建时间从数周缩短至几分钟。\n- **灵活的实验配置**：通过简单的参数修改，就能快速尝试 \"ResNet50 + U-Net\" 或 \"MobileNet + SegNet\" 等多种组合，迅速锁定精度与速度最优的平衡点。\n- **标准化的工作流**：利用内置的数据生成器和 CLI 工具，统一了数据读取、增强及训练流程，让团队能专注于病害特征分析而非底层代码调试。\n- **便捷的推理与导出**：直接使用提供的预训练权重进行预测，并支持一键导出模型，轻松将算法部署到田间地头的移动设备上实时运行。\n\nimage-segmentation-keras 通过提供标准化、模块化的深度学习分割方案，让农业团队得以跳过重复造轮子的过程，将研发重心完全回归到解决实际的作物病害问题上。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdivamgupta_image-segmentation-keras_dda283ff.png","divamgupta","Divam Gupta","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fdivamgupta_6a843d0f.jpg","Creator of one-click ML tool - Liner.ai • AI for VR @ Meta • Previously: research @ Microsoft , robotics @ CMU",null,"San Francisco, United States","https:\u002F\u002Fdivamgupta.com\u002F","https:\u002F\u002Fgithub.com\u002Fdivamgupta",[84,88],{"name":85,"color":86,"percentage":87},"Python","#3572A5",99.1,{"name":89,"color":90,"percentage":91},"Dockerfile","#384d54",0.9,3003,1162,"2026-04-01T08:04:51","MIT","Linux, macOS, Windows","未说明（基于 TensorFlow\u002FKeras，支持 CPU 和 GPU，具体取决于安装的 TensorFlow 版本）","未说明",{"notes":100,"python":98,"dependencies":101},"安装 OpenCV 前在 Linux 系统上可能需要运行 'apt-get install -y libsm6 libxext6 libxrender-dev'。该工具支持多种分割模型（如 SegNet, FCN, U-Net, PSPNet），并提供预训练模型。支持通过 CLI 或 Python API 进行训练、预测和视频推理。在无头系统（headless system）上进行视频推理时需移除 '--display' 参数。",[102,103,104],"keras==2.4.3","tensorflow==2.4.1","opencv-python",[14,13],"2026-03-27T02:49:30.150509","2026-04-06T07:12:49.788157",[109,114,119,124,129,134],{"id":110,"question_zh":111,"answer_zh":112,"source_url":113},17824,"运行预测命令时出现 'Checkpoint not found' 错误怎么办？","该错误通常是因为代码无法正确解析检查点文件名。如果是 Windows 系统，路径分隔符可能导致解析失败。可以尝试修改 `find_latest_checkpoint` 函数，将路径分割逻辑改为兼容反斜杠：\n\ndef find_latest_checkpoint(checkpoints_path, fail_safe=True):\n    def get_epoch_number_from_path(path):\n        t_path = path.split(\"\\\\\")[-1]  # 针对 Windows 路径\n        m_path = t_path.strip(\".\")\n        return m_path\n    # 后续逻辑过滤出纯数字的文件名并获取最新权重","https:\u002F\u002Fgithub.com\u002Fdivamgupta\u002Fimage-segmentation-keras\u002Fissues\u002F237",{"id":115,"question_zh":116,"answer_zh":117,"source_url":118},17825,"加载 VGG 权重时出现维度不匹配错误（如 [102400,4096] vs [25088,4096]）如何解决？","这是因为 VGG 网络包含全连接层，对输入图像尺寸敏感。如果输入图像尺寸不是标准的 224x224，在全连接层展平时会发生维度不匹配。\n解决方案：\n1. 确保输入图像尺寸调整为 224x224。\n2. 或者升级库到最新版本，新版本已修复此兼容性问题。","https:\u002F\u002Fgithub.com\u002Fdivamgupta\u002Fimage-segmentation-keras\u002Fissues\u002F3",{"id":120,"question_zh":121,"answer_zh":122,"source_url":123},17826,"导入 predict 或 predict_multiple 时提示 'module object is not callable' 或 'cannot import name' 错误？","这是因为调用方式不正确或版本差异。注意以下几点：\n1. 运行预测前必须先训练模型以生成检查点文件（checkpoint file）。\n2. 对于 VGG_UNet 等模型，预训练权重会自动下载，但必须确保网络能正常访问。\n3. 检查导入方式，较新版本可能改变了 API 结构，建议参考最新文档或使用 `keras_segmentation.models` 下的具体模型类进行实例化和预测。","https:\u002F\u002Fgithub.com\u002Fdivamgupta\u002Fimage-segmentation-keras\u002Fissues\u002F134",{"id":125,"question_zh":126,"answer_zh":127,"source_url":128},17827,"训练时出现 'ModuleNotFoundError: No module named VGGUnet' 错误？","这通常是 Python 3 兼容性或模块导入路径问题。解决方法如下：\n1. 确保使用的是支持 Python 3 的最新版本库。\n2. 如果是旧版本，需手动修改 `Models\u002F__init__.py` 文件，显式导入子模块：\n\nimport Models.VGGUnet\nimport Models.VGGSegnet\nimport Models.FCN8\nimport Models.FCN32\n\n保存后重新运行即可。","https:\u002F\u002Fgithub.com\u002Fdivamgupta\u002Fimage-segmentation-keras\u002Fissues\u002F8",{"id":130,"question_zh":131,"answer_zh":132,"source_url":133},17828,"训练准确率和验证准确率很高，但预测结果很差（全是黑图或错误分割）是什么原因？","这通常是因为标注图片（Label\u002FMask）的格式不符合要求。常见原因及解决步骤：\n1. 通道数问题：使用 LabelMe 等工具生成的标注图可能是多通道（RGB），而本库需要单通道（灰度图，值为 0, 1, 2... 代表类别）。\n2. 解决方法：编写脚本将标注图转换为单通道灰度图。例如在 Python 中使用：\n\nfrom skimage.color import rgb2gray\n# 读取多通道标签图并转换，注意可能需要进一步处理确保像素值为整数类别索引而非连续灰度值\n\n或者在 MATLAB 中读取 PNG 标签图并重新保存为单通道 PNG。转换后的标签图看起来可能是黑色的，这是正常的，只要像素值代表正确的类别索引即可。","https:\u002F\u002Fgithub.com\u002Fdivamgupta\u002Fimage-segmentation-keras\u002Fissues\u002F132",{"id":135,"question_zh":136,"answer_zh":137,"source_url":118},17829,"在 Python 3 环境下运行遇到 'zip.next()' 相关错误或迭代器错误怎么办？","这是 Python 2 到 Python 3 的语法兼容性问题。在 `LoadBatches.py` 文件中，找到 `zipped.next()` 的调用，将其替换为 Python 3 的语法 `zipped.__next__()` 即可解决。建议直接升级到支持 Python 3 的库版本以避免此类手动修改。",[139],{"id":140,"version":141,"summary_zh":142,"released_at":143},108133,"pretrained_model_1","添加VOC预训练模型","2019-04-26T05:53:38"]