[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-kamenbliznashki--normalizing_flows":3,"tool-kamenbliznashki--normalizing_flows":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 真正成长为懂上",160015,2,"2026-04-18T11:30:52",[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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",109154,"2026-04-18T11:18:24",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":75,"owner_location":76,"owner_email":77,"owner_twitter":75,"owner_website":75,"owner_url":78,"languages":79,"stars":84,"forks":85,"last_commit_at":86,"license":75,"difficulty_score":10,"env_os":87,"env_gpu":88,"env_ram":89,"env_deps":90,"category_tags":97,"github_topics":98,"view_count":32,"oss_zip_url":75,"oss_zip_packed_at":75,"status":17,"created_at":103,"updated_at":104,"faqs":105,"releases":136},9295,"kamenbliznashki\u002Fnormalizing_flows","normalizing_flows","Pytorch implementations of density estimation algorithms: BNAF, Glow, MAF, RealNVP, planar flows","normalizing_flows 是一个基于 PyTorch 的开源项目，集成了多种主流归一化流（Normalizing Flows）算法的实现，包括 BNAF、Glow、MAF、RealNVP 以及平面流等。它主要致力于解决复杂的概率密度估计与生成建模问题，能够将简单的已知分布（如高斯分布）通过可逆变换映射为复杂的数据分布，从而实现对数据的高效建模和样本生成。\n\n该项目特别适合人工智能研究人员、算法工程师以及对生成模型感兴趣的高级开发者使用。无论是需要复现经典论文实验、验证新算法思路，还是希望深入理解可逆神经网络内部机制，normalizing_flows 都提供了清晰、模块化的代码参考。其技术亮点在于不仅涵盖了从基础的平面流到先进的 Glow（引入可逆 1x1 卷积）和 BNAF（块神经自回归流）等多种架构，还包含了在 2D 玩具数据集及 CelebA、MNIST 等真实图像数据上的完整训练与可视化示例。通过这些实现，用户可以直观地观察模型如何学习数据分布细节，并在稳定的训练过程中获得高质量的生成结果，是探索深度生成模型领域的实用工具库。","# Normalizing flows\n\nReimplementations of density estimation algorithms from:\n* [Block Neural Autoregressive Flow](https:\u002F\u002Farxiv.org\u002Fabs\u002F1904.04676)\n* [Glow: Generative Flow with Invertible 1×1 Convolutions](https:\u002F\u002Farxiv.org\u002Fabs\u002F1807.03039)\n* [Masked Autoregressive Flow for Density Estimation](https:\u002F\u002Farxiv.org\u002Fabs\u002F1705.07057)\n* [Density Estimation using RealNVP](https:\u002F\u002Farxiv.org\u002Fabs\u002F1605.08803)\n* [Variational Inference with Normalizing Flows](https:\u002F\u002Farxiv.org\u002Fabs\u002F1505.05770)\n\n## Block Neural Autoregressive Flow\nhttps:\u002F\u002Farxiv.org\u002Fabs\u002F1904.04676\n\nImplementation of BNAF on toy density estimation datasets.\n\n#### Results\nDensity estimation of 2d toy data and density estimation of 2d test energy potentials (cf. Figure 2 & 3 in paper):\n\nThe models were trained for 20,000 steps with the architectures and hyperparameters described in the Section 5 of the paper, with the exception of `rings` dataset (bottom right) which had 5 hidden layers. The models trained significantly faster than the planar flow model in Rezende & Mohamed and were much more stable; interestingly, BNAF stretches space differently and requires a lot more test points to show a smooth potential.\n\n| Density matching on 2d energy potentials | Density estimation on 2d toy data |\n| --- | --- |\n| ![bnaf_u1](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_8493f33db304.png) | ![bnaf_8gaussians](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_77e2b1571346.png) |\n| ![bnaf_u2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_cd0967d4e93f.png) | ![bnaf_checkerboard](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_74af6b1380ab.png) |\n| ![bnaf_u3](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_61bbc824278e.png) | ![bnaf_2spirals](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_22319c9da1ba.png) |\n| ![bnaf_u4](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_2bfdd39418a9.png) | ![bnaf_rings](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_67f2d576cc1c.png) |\n\n\n#### Usage\nTo train model:\n```\npython bnaf.py --train\n               --dataset      # choice from u1, u2, u3, u4, 8gaussians, checkerboard, 2spirals\n               --log_interval # how often to save the model and visualize results\n               --n_steps      # number of training steps\n               --n_hidden     # number of hidden layers\n               --hidden_dim   # dimension of the hidden layer\n               --[add'l options]\n```\nAdditional options are: learning rate, learning rate decay and patience, cuda device id, batch_size.\n\nTo plot model:\n```\npython bnaf.py --plot\n               --restore_file [path to .pt checkpoint]\n```\n\n#### Useful resources\n* Official implementation by the authors https:\u002F\u002Fgithub.com\u002Fnicola-decao\u002FBNAF\n\n## Glow: Generative Flow with Invertible 1x1 Convolutions\nhttps:\u002F\u002Farxiv.org\u002Fabs\u002F1807.03039\n\nImplementation of Glow on CelebA and MNIST datasets.\n\n#### Results\nI trained two models:\n- Model A with 3 levels, 32 depth, 512 width (~74M parameters). Trained on 5 bit images, batch size of 16 per GPU over 100K iterations.\n- Model B with 3 levels, 24 depth, 256 width (~22M parameters). Trained on 4 bit images, batch size of 32 per GPU over 100K iterations.\n\nIn both cases, gradients were clipped at norm 50, learning rate was 1e-3 with linear warmup from 0 over 2 epochs. Both reached similar results and 4.2 bits\u002Fdim.\n\n##### Samples at varying temperatures\nTemperatures ranging 0, 0.25, 0.5, 0.6, 0.7, 0.8, 0.9, 1 (rows, top to bottom):\n\n| Model A | Model B |\n| --- | --- |\n| ![model_a_range](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_1daac8fe5c2c.png) | ![model_b_range](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_573141d018d9.png) |\n\n##### Samples at temperature 0.7:\n| Model A | Model B |\n| --- | --- |\n| ![model_a_range](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_a8ae6da25b36.png) | ![model_b_range](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_cb6298872bce.png) |\n\n##### Model A attribute manipulation on in-distribution sample:\n\nEmbedding vectors were calculated for the first 30K training images and positive \u002F negative attributes were averaged then subtracting. The resulting `dz` was ranged and applied on a test set image (middle image represents the unchanged \u002F actual data point).\n\n| Attribute | `dz` range [-2, -1, 0, 1, 2] |\n| --- | --- |\n| Brown hair | ![attr_8](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_371b80913de1.png) |\n| Male | ![attr_20](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_c581de06c8df.png) |\n| Mouth slightly opened | ![attr_21](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_610674add87d.png) |\n| Young | ![attr_39](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_62ad2887060f.png) |\n\n##### Model A attribute manipulation on 'out-of-distribution' sample (i.e. me):\n\n| Attribute | `dz` range |\n| --- | --- |\n| Brown hair | ![me_8](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_21b10985f083.png) |\n| Mouth slightly opened | ![me_21](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_7f3508461ada.png) |\n\n\n#### Usage\n\nTo train a model using pytorch distributed package:\n```\npython -m torch.distributed.launch --nproc_per_node=NUM_GPUS_YOU_HAVE \\\n       glow.py --train \\\n               --distributed \\\n               --dataset=celeba \\\n               --data_dir=[path to data source] \\\n               --n_levels=3 \\\n               --depth=32 \\\n               --width=512 \\\n               --batch_size=16 [this is per GPU]\n```\nFor larger models or image sizes add `--checkpoint_grads` to checkpoint gradients using pytorch's library. I trained a 3 layer \u002F 32 depth \u002F 512 width model with batch size of 16 without gradient checkpointing and a 4 layer \u002F 48 depth \u002F 512 width model with batch size of 16 which had ~190M params so required gradient checkpointing (and was painfully slow on 8 GPUs).\n\n\nTo evaluate model:\n```\npython glow.py --evaluate \\\n               --restore_file=[path to .pt checkpoint] \\\n               --dataset=celeba \\\n               --data_dir=[path to data source] \\\n               --[options of the saved model: n_levels, depth, width, batch_size]\n```\n\nTo generate samples from a trained model:\n```\npython glow.py --generate \\\n               --restore_file=[path to .pt checkpoint] \\\n               --dataset=celeba \\\n               --data_dir=[path to data source] \\\n               --[options of the saved model: n_levels, depth, width, batch_size] \\\n               --z_std=[temperature parameter; if blank, generates range]\n```\n\nTo visualize manipulations on specific image given a trained model:\n```\npython glow.py --visualize \\\n               --restore_file=[path to .pt checkpoint] \\\n               --dataset=celeba \\\n               --data_dir=[path to data source] \\\n               --[options of the saved model: n_levels, depth, width, batch_size] \\\n               --z_std=[temperature parameter; if blank, uses default] \\\n               --vis_attrs=[list of indices of attribute to be manipulated, if blank, manipulates every attribute] \\\n               --vis_alphas=[list of values by which `dz` should be multiplied, defaults [-2,2]] \\\n               --vis_img=[path to image to manipulate (note: size needs to match dataset); if blank uses example from test dataset]\n```\n\n#### Datasets\n\nTo download CelebA follow the instructions [here](http:\u002F\u002Fmmlab.ie.cuhk.edu.hk\u002Fprojects\u002FCelebA.html). A nice script that simplifies downloading and extracting can be found here: https:\u002F\u002Fgithub.com\u002Fnperraud\u002Fdownload-celebA-HQ\u002F\n\n\n#### References\n* Official implementation in Tensorflow: https:\u002F\u002Fgithub.com\u002Fopenai\u002Fglow\n\n\n## Masked Autoregressive Flow\nhttps:\u002F\u002Farxiv.org\u002Fabs\u002F1705.07057\n\nReimplementation of MADE, MAF, Mixture of Gaussians MADE, Mixture of\nGausssians MAF, and RealNVP modules on UCI datasets and MNIST.\n\n#### Results\nAverage test log likelihood for un\u002Fconditional density estimation (cf.\nTable 1 & 2 in paper for results and parameters; models here were trained for 50 epochs):\n\n| Model | POWER | GAS | HEPMASS | MINIBOONE | BSDS300 | MNIST (uncond) | MNIST (cond) |\n| --- | --- | --- | --- | --- | --- | --- | --- |\n| MADE | -3.10 +\u002F- 0.02 | 2.53 +\u002F- 0.02 | -21.13 +\u002F- 0.01 | -15.36 +\u002F- 15.06 | 146.42 +\u002F- 0.14 | -1393.67 +\u002F- 1.90 | -1340.98 +\u002F- 1.71 |\n| MADE MOG | 0.37 +\u002F- 0.01 | 8.08 +\u002F- 0.02 | -15.70 +\u002F- 0.02 | -11.64 +\u002F- 0.44 | 153.56 +\u002F- 0.28 | -1023.13 +\u002F- 1.69 | -1013.75 +\u002F- 1.61 |\n| RealNVP (5) | -0.49 +\u002F- 0.01 | 7.01 +\u002F- 0.06 | -19.96 +\u002F- 0.02 | -16.88 +\u002F- 0.21 | 148.34 +\u002F- 0.26 | -1279.76 +\u002F- 9.91 | -1276.33 +\u002F- 12.21 |\n| MAF (5) | 0.03 +\u002F- 0.01 | 6.23 +\u002F- 0.01 | -17.97 +\u002F- 0.01 | -11.57 +\u002F- 0.21 | 153.53 +\u002F- 0.27 | -1272.70 +\u002F- 1.87 | -1268.24 +\u002F- 2.73 |\n| MAF MOG (5) | 0.09 +\u002F- 0.01 | 7.96 +\u002F- 0.02 | -17.29 +\u002F- 0.02 | -11.27 +\u002F- 0.41 | 153.35 +\u002F- 0.26 | -1080.46 +\u002F- 1.53 | -1070.33 +\u002F- 1.53 |\n\n\nToy density model (cf. Figure 1 in paper):\n\n| Target density | Learned density with MADE \u003Cbr> and random numbers driving MADE | Learned density with MAF 5 layers \u003Cbr> and random numbers driving MAF |\n| --- | --- | --- |\n| ![fig1a](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_78a9015db22e.png) | ![fig1b](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_e586ed4897f5.png) | ![fig1c](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_62b9083f301d.png) |\n\nClass-conditional generated images from MNIST using MAF (5) model; generated data arrange by decreasing log probability (cf. Figure 3 in paper):\n\n![mafmnist](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_0ab2671de957.png)\n\n#### Usage\nTo train model:\n```\npython maf.py -- train \\\n              -- model=['made' | 'mademog' | 'maf' | 'mafmog' | 'realnvp'] \\\n              -- dataset=['POWER' | 'GAS' | 'HEPMASS' | 'MINIBOONE' | 'BSDS300' | MNIST'] \\\n              -- n_blocks=[for maf\u002Fmafmog and realnvp specify # of MADE-blocks \u002F coupling layers] \\\n              -- n_components=[if mixture of Gaussians, specify # of components] \\\n              -- conditional [if MNIST, can train class-conditional log likelihood] \\\n              -- [add'l options see py file]\n```\n\nTo evaluate model:\n```\npython maf.py -- evaluate \\\n              -- restore_file=[path to .pt checkpoint]\n              -- [options of the saved model: n_blocks, n_hidden, hidden_size, n_components, conditional]\n```\n\nTo generate data from a trained model (for MNIST dataset):\n```\npython maf.py -- generate \\\n              -- restore_file=[path to .pt checkpoint]\n              -- dataset='MNIST'\n              -- [options of the saved model: n_blocks, n_hidden, hidden_size, n_components, conditional]\n```\n\n#### Datasets\n\nDatasets and preprocessing code are forked from the MAF authors' implementation [here](https:\u002F\u002Fgithub.com\u002Fgpapamak\u002Fmaf#how-to-get-the-datasets). The unzipped datasets should be symlinked into the `.\u002Fdata` folder or the data_dir argument should be specified to point to the actual data.\n\n#### References\n* The original Theano implementation by the authors https:\u002F\u002Fgithub.com\u002Fgpapamak\u002Fmaf\u002F\n* https:\u002F\u002Fgithub.com\u002Fikostrikov\u002Fpytorch-flows\n\n\n## Variational inference with normalizing flows\nImplementation of [Variational Inference with Normalizing Flows](https:\u002F\u002Farxiv.org\u002Fabs\u002F1505.05770)\n\n#### Results\nDensity estimation of 2-d test energy potentials (cf. Table 1 & Figure 3 in paper).\n\n| Target density | Flow K = 2 | Flow K = 32 | Training parameters |\n| --- | --- | --- | --- |\n| ![uz1](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_d77e02126b0b.png) | ![uz1k2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_7d75e235060d.png) | ![uz1k32](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_d76a5b3df399.png) | weight init Normal(0,1), base dist. scale 2 |\n| ![uz2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_e76d0957ab43.png) | ![uz2k2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_bc3b61955bc4.png) | ![uz2k32](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_6bd0e69d5645.png) | weight init Normal(0,1), base dist. scale 1 |\n| ![uz3](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_e52fd7644f9a.png) | ![uz3k2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_7ed0f5631deb.png) | ![uz3k32](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_21655528244f.png) | weight init Normal(0,1), base dist. scale 1, weight decay 1e-3 |\n| ![uz4](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_d47677be6b5c.png) | ![uz4k2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_0f0f9b621f17.png) | ![uz4k32](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_67f773960262.png) | weight init Normal(0,1), base dist. scale 4, weight decay 1e-3 |\n\n\n#### Usage\nTo train model:\n```\npython planar_flow.py -- train \\\n                      -- target_potential=[choice from u_z1 | u_z2 | u_z3 | u_z4] \\\n                      -- flow_length=[# of layers in flow] \\\n                      -- [add'l options]\n```\nAdditional options are: base distribution (q0) scale, weight initialization\nscale, weight decay, learnable first affine layer (I did not find adding an affine layer beneficial).\n\nTo evaluate model:\n```\npython planar_flow.py -- evaluate \\\n                      -- restore_file=[path to .pt checkpoint]\n```\n\n#### Useful resources\n* https:\u002F\u002Fgithub.com\u002Fcasperkaae\u002Fparmesan\u002Fissues\u002F22\n\n\n## Dependencies\n* python 3.6\n* pytorch 1.0\n* numpy\n* matplotlib\n* tensorboardX\n\n###### Some of the datasets further require:\n* pandas\n* sklearn\n* h5py\n","# 归一化流\n\n对以下论文中的密度估计算法进行了重新实现：\n* [块神经自回归流](https:\u002F\u002Farxiv.org\u002Fabs\u002F1904.04676)\n* [Glow：具有可逆 1×1 卷积的生成流](https:\u002F\u002Farxiv.org\u002Fabs\u002F1807.03039)\n* [用于密度估计的掩码自回归流](https:\u002F\u002Farxiv.org\u002Fabs\u002F1705.07057)\n* [使用 RealNVP 进行密度估计](https:\u002F\u002Farxiv.org\u002Fabs\u002F1605.08803)\n* [基于归一化流的变分推断](https:\u002F\u002Farxiv.org\u002Fabs\u002F1505.05770)\n\n## 块神经自回归流\nhttps:\u002F\u002Farxiv.org\u002Fabs\u002F1904.04676\n\n在玩具密度估计数据集上实现了 BNAF。\n\n#### 结果\n对二维玩具数据的密度估计以及对二维测试能量势能的密度估计（参见论文中的图 2 和图 3）：\n\n这些模型按照论文第 5 节中描述的架构和超参数训练了 20,000 步，除了 `rings` 数据集（右下角）使用了 5 层隐藏层。与 Rezende & Mohamed 中的平面流模型相比，BNAF 训练得更快且更加稳定；有趣的是，BNAF 对空间的拉伸方式不同，需要更多的测试点才能显示出平滑的势能。\n\n| 二维能量势能上的密度匹配 | 二维玩具数据上的密度估计 |\n| --- | --- |\n| ![bnaf_u1](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_8493f33db304.png) | ![bnaf_8gaussians](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_77e2b1571346.png) |\n| ![bnaf_u2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_cd0967d4e93f.png) | ![bnaf_checkerboard](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_74af6b1380ab.png) |\n| ![bnaf_u3](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_61bbc824278e.png) | ![bnaf_2spirals](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_22319c9da1ba.png) |\n| ![bnaf_u4](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_2bfdd39418a9.png) | ![bnaf_rings](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_67f2d576cc1c.png) |\n\n\n#### 使用方法\n训练模型：\n```\npython bnaf.py --train\n               --dataset      # 可选 u1、u2、u3、u4、8gaussians、checkerboard、2spirals\n               --log_interval # 模型保存和结果可视化的频率\n               --n_steps      # 训练步数\n               --n_hidden     # 隐藏层数量\n               --hidden_dim   # 隐藏层维度\n               --[其他选项]\n```\n其他选项包括：学习率、学习率衰减及耐心值、CUDA 设备 ID、批量大小。\n\n绘制模型：\n```\npython bnaf.py --plot\n               --restore_file [路径到 .pt 检查点文件]\n```\n\n#### 有用资源\n* 作者官方实现 https:\u002F\u002Fgithub.com\u002Fnicola-decao\u002FBNAF\n\n## Glow：带有可逆1×1卷积的生成流模型\nhttps:\u002F\u002Farxiv.org\u002Fabs\u002F1807.03039\n\n在CelebA和MNIST数据集上实现Glow模型。\n\n#### 结果\n我训练了两个模型：\n- 模型A：3个层级，深度32，宽度512（约7400万参数）。在5位图像上训练，每张GPU上的批量大小为16，共进行了10万次迭代。\n- 模型B：3个层级，深度24，宽度256（约2200万参数）。在4位图像上训练，每张GPU上的批量大小为32，共进行了10万次迭代。\n\n在这两种情况下，梯度都被裁剪至范数50，学习率为1e-3，并在前2个epoch内从0线性预热。两者都达到了相似的结果，即4.2比特\u002F维度。\n\n##### 不同温度下的采样结果\n温度范围为0、0.25、0.5、0.6、0.7、0.8、0.9、1（行，从上到下）：\n\n| 模型A | 模型B |\n| --- | --- |\n| ![model_a_range](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_1daac8fe5c2c.png) | ![model_b_range](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_573141d018d9.png) |\n\n##### 温度为0.7时的采样结果：\n| 模型A | 模型B |\n| --- | --- |\n| ![model_a_range](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_a8ae6da25b36.png) | ![model_b_range](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_cb6298872bce.png) |\n\n##### 模型A对分布内样本的属性操控：\n\n对前3万个训练图像计算了嵌入向量，分别取正负属性的平均值并相减。得到的`dz`被归一化后应用于测试集中的一个图像（中间图表示未改变的真实数据点）。\n\n| 属性 | `dz` 范围 [-2, -1, 0, 1, 2] |\n| --- | --- |\n| 棕色头发 | ![attr_8](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_371b80913de1.png) |\n| 男性 | ![attr_20](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_c581de06c8df.png) |\n| 嘴微微张开 | ![attr_21](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_610674add87d.png) |\n| 年轻 | ![attr_39](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_62ad2887060f.png) |\n\n##### 模型A对“分布外”样本（即我自己）的属性操控：\n\n| 属性 | `dz` 范围 |\n| --- | --- |\n| 棕色头发 | ![me_8](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_21b10985f083.png) |\n| 嘴微微张开 | ![me_21](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_7f3508461ada.png) |\n\n\n#### 使用方法\n\n使用PyTorch分布式包训练模型：\n```\npython -m torch.distributed.launch --nproc_per_node=NUM_GPUS_YOU_HAVE \\\n       glow.py --train \\\n               --distributed \\\n               --dataset=celeba \\\n               --data_dir=[数据源路径 ] \\\n               --n_levels=3 \\\n               --depth=32 \\\n               --width=512 \\\n               --batch_size=16 [这是每张GPU上的批量大小]\n```\n对于更大的模型或更高分辨率的图像，可以添加`--checkpoint_grads`选项来使用PyTorch库进行梯度检查点保存。我曾训练过一个3层\u002F深度32\u002F宽度512、批量大小为16且未使用梯度检查点的模型，以及一个4层\u002F深度48\u002F宽度512、批量大小为16的模型，后者约有1.9亿参数，因此必须使用梯度检查点（并且在8张GPU上运行时速度非常慢）。\n\n评估模型：\n```\npython glow.py --evaluate \\\n               --restore_file=[ .pt 检查点文件路径 ] \\\n               --dataset=celeba \\\n               --data_dir=[ 数据源路径 ] \\\n               --[ 已保存模型的参数：n_levels、depth、width、batch_size ]\n```\n\n从已训练好的模型生成样本：\n```\npython glow.py --generate \\\n               --restore_file=[ .pt 检查点文件路径 ] \\\n               --dataset=celeba \\\n               --data_dir=[ 数据源路径 ] \\\n               --[ 已保存模型的参数：n_levels、depth、width、batch_size ] \\\n               --z_std=[ 温度参数；若为空，则生成一系列样本 ]\n```\n\n可视化特定图像的操控效果（需已训练好模型）：\n```\npython glow.py --visualize \\\n               --restore_file=[ .pt 检查点文件路径 ] \\\n               --dataset=celeba \\\n               --data_dir=[ 数据源路径 ] \\\n               --[ 已保存模型的参数：n_levels、depth、width、batch_size ] \\\n               --z_std=[ 温度参数；若为空，则使用默认值 ] \\\n               --vis_attrs=[ 需要操控的属性索引列表；若为空，则操控所有属性 ] \\\n               --vis_alphas=[ 用于乘以`dz`的数值列表；默认为[-2,2] ] \\\n               --vis_img=[ 需要操控的图像路径（注意：尺寸需与数据集一致）；若为空，则使用测试集中的示例 ]\n```\n\n#### 数据集\n\n下载CelebA数据集，请按照[此处](http:\u002F\u002Fmmlab.ie.cuhk.edu.hk\u002Fprojects\u002FCelebA.html)的说明操作。这里有一个方便的脚本可以帮助简化下载和解压过程：https:\u002F\u002Fgithub.com\u002Fnperraud\u002Fdownload-celebA-HQ\u002F\n\n\n#### 参考文献\n* 官方TensorFlow实现：https:\u002F\u002Fgithub.com\u002Fopenai\u002Fglow\n\n## 掩码自回归流\nhttps:\u002F\u002Farxiv.org\u002Fabs\u002F1705.07057\n\n在 UCI 数据集和 MNIST 上重新实现了 MADE、MAF、高斯混合 MADE、高斯混合 MAF 以及 RealNVP 模块。\n\n#### 结果\n无条件\u002F条件密度估计的平均测试对数似然（参考论文中的表 1 和表 2 以获取结果和参数；此处模型训练了 50 个 epoch）：\n\n| 模型 | POWER | GAS | HEPMASS | MINIBOONE | BSDS300 | MNIST（无条件） | MNIST（条件） |\n| --- | --- | --- | --- | --- | --- | --- | --- |\n| MADE | -3.10 ± 0.02 | 2.53 ± 0.02 | -21.13 ± 0.01 | -15.36 ± 15.06 | 146.42 ± 0.14 | -1393.67 ± 1.90 | -1340.98 ± 1.71 |\n| MADE MOG | 0.37 ± 0.01 | 8.08 ± 0.02 | -15.70 ± 0.02 | -11.64 ± 0.44 | 153.56 ± 0.28 | -1023.13 ± 1.69 | -1013.75 ± 1.61 |\n| RealNVP (5) | -0.49 ± 0.01 | 7.01 ± 0.06 | -19.96 ± 0.02 | -16.88 ± 0.21 | 148.34 ± 0.26 | -1279.76 ± 9.91 | -1276.33 ± 12.21 |\n| MAF (5) | 0.03 ± 0.01 | 6.23 ± 0.01 | -17.97 ± 0.01 | -11.57 ± 0.21 | 153.53 ± 0.27 | -1272.70 ± 1.87 | -1268.24 ± 2.73 |\n| MAF MOG (5) | 0.09 ± 0.01 | 7.96 ± 0.02 | -17.29 ± 0.02 | -11.27 ± 0.41 | 153.35 ± 0.26 | -1080.46 ± 1.53 | -1070.33 ± 1.53 |\n\n\n玩具密度模型（参考论文中的图 1）：\n\n| 目标密度 | 使用 MADE 及随机数驱动 MADE 学习到的密度 | 使用 MAF 5 层及随机数驱动 MAF 学习到的密度 |\n| --- | --- | --- |\n| ![fig1a](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_78a9015db22e.png) | ![fig1b](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_e586ed4897f5.png) | ![fig1c](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_62b9083f301d.png) |\n\n使用 MAF (5) 模型生成的 MNIST 类条件图像；生成数据按对数似然递减排序（参考论文中的图 3）：\n\n![mafmnist](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_0ab2671de957.png)\n\n#### 使用方法\n训练模型：\n```\npython maf.py -- train \\\n              -- model=['made' | 'mademog' | 'maf' | 'mafmog' | 'realnvp'] \\\n              -- dataset=['POWER' | 'GAS' | 'HEPMASS' | 'MINIBOONE' | 'BSDS300' | MNIST'] \\\n              -- n_blocks=[对于 maf\u002Fmafmog 和 realnvp，指定 MADE 块或耦合层的数量] \\\n              -- n_components=[如果是高斯混合，则指定组件数量] \\\n              -- conditional [如果是 MNIST，可以训练类条件对数似然] \\\n              -- [更多选项请参阅 py 文件]\n```\n\n评估模型：\n```\npython maf.py -- evaluate \\\n              -- restore_file=[.pt 检查点路径] \\\n              -- [保存模型的选项：n_blocks、n_hidden、hidden_size、n_components、conditional]\n```\n\n从已训练模型生成数据（针对 MNIST 数据集）：\n```\npython maf.py -- generate \\\n              -- restore_file=[.pt 检查点路径] \\\n              -- dataset='MNIST' \\\n              -- [保存模型的选项：n_blocks、n_hidden、hidden_size、n_components、conditional]\n```\n\n#### 数据集\n\n数据集和预处理代码源自 MAF 作者的实现 [这里](https:\u002F\u002Fgithub.com\u002Fgpapamak\u002Fmaf#how-to-get-the-datasets)。解压后的数据集应符号链接到 `.\u002Fdata` 文件夹，或指定 `data_dir` 参数指向实际数据。\n\n#### 参考文献\n* 作者的原始 Theano 实现 https:\u002F\u002Fgithub.com\u002Fgpapamak\u002Fmaf\u002F\n* https:\u002F\u002Fgithub.com\u002Fikostrikov\u002Fpytorch-flows\n\n\n## 基于归一化流的变分推断\n实现了 [基于归一化流的变分推断](https:\u002F\u002Farxiv.org\u002Fabs\u002F1505.05770)\n\n#### 结果\n二维测试能量势的密度估计（参考论文中的表 1 和图 3）。\n\n| 目标密度 | 流 K = 2 | 流 K = 32 | 训练参数 |\n| --- | --- | --- | --- |\n| ![uz1](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_d77e02126b0b.png) | ![uz1k2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_7d75e235060d.png) | ![uz1k32](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_d76a5b3df399.png) | 权重初始化为 N(0,1)，基础分布尺度为 2 |\n| ![uz2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_e76d0957ab43.png) | ![uz2k2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_bc3b61955bc4.png) | ![uz2k32](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_6bd0e69d5645.png) | 权重初始化为 N(0,1)，基础分布尺度为 1 |\n| ![uz3](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_e52fd7644f9a.png) | ![uz3k2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_7ed0f5631deb.png) | ![uz3k32](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_21655528244f.png) | 权重初始化为 N(0,1)，基础分布尺度为 1，权重衰减为 1e-3 |\n| ![uz4](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_d47677be6b5c.png) | ![uz4k2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_0f0f9b621f17.png) | ![uz4k32](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_readme_67f773960262.png) | 权重初始化为 N(0,1)，基础分布尺度为 4，权重衰减为 1e-3 |\n\n\n#### 使用方法\n训练模型：\n```\npython planar_flow.py -- train \\\n                      -- target_potential=[选择 u_z1 | u_z2 | u_z3 | u_z4] \\\n                      -- flow_length=[流的层数] \\\n                      -- [其他选项]\n```\n\n其他选项包括：基础分布（q0）的尺度、权重初始化的尺度、权重衰减以及可学习的第一层仿射变换（我没有发现添加仿射层有益）。\n\n评估模型：\n```\npython planar_flow.py -- evaluate \\\n                      -- restore_file=[.pt 检查点路径]\n```\n\n#### 有用资源\n* https:\u002F\u002Fgithub.com\u002Fcasperkaae\u002Fparmesan\u002Fissues\u002F22\n\n\n## 依赖项\n* python 3.6\n* pytorch 1.0\n* numpy\n* matplotlib\n* tensorboardX\n\n###### 部分数据集还需要：\n* pandas\n* sklearn\n* h5py","# Normalizing Flows 快速上手指南\n\n本工具集成了多种基于归一化流（Normalizing Flows）的密度估计与生成模型复现，包括 BNAF、Glow、MAF、RealNVP 及基础平面流（Planar Flow）。以下指南将帮助您快速配置环境并运行核心示例。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**: Linux 或 macOS (Windows 需通过 WSL 运行)\n*   **Python 版本**: 推荐 Python 3.6 - 3.8 (基于 PyTorch 兼容性)\n*   **核心依赖**:\n    *   PyTorch (建议安装支持 CUDA 的版本以加速训练)\n    *   torchvision\n    *   NumPy\n    *   Matplotlib (用于可视化结果)\n*   **硬件建议**: 运行 Glow 等大模型时，建议使用配备 NVIDIA GPU 的机器。\n\n**依赖安装命令：**\n```bash\npip install torch torchvision numpy matplotlib\n# 如果国内下载较慢，推荐使用清华源加速\n# pip install torch torchvision numpy matplotlib -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n## 安装步骤\n\n该项目为纯 Python 实现，无需复杂的编译安装过程。只需克隆仓库并进入目录即可。\n\n1.  **克隆代码库**\n    ```bash\n    git clone https:\u002F\u002Fgithub.com\u002Fikostrikov\u002Fpytorch-flows.git\n    cd pytorch-flows\n    ```\n\n2.  **验证文件结构**\n    确保目录下包含以下核心脚本文件：\n    *   `bnaf.py` (Block Neural Autoregressive Flow)\n    *   `glow.py` (Glow: Generative Flow with Invertible 1x1 Convolutions)\n    *   `maf.py` (Masked Autoregressive Flow)\n    *   `planar_flow.py` (Variational Inference with Normalizing Flows)\n\n## 基本使用\n\n以下展示三个主要模型的最低限度运行示例。首次运行时，脚本会自动下载或读取指定路径的数据集（如 MNIST, CelebA 等）。\n\n### 1. 运行 BNAF (2D 玩具数据密度估计)\n此示例将在 2D 高斯混合分布数据上训练模型 20,000 步，并保存可视化结果。\n\n```bash\npython bnaf.py --train \\\n               --dataset 8gaussians \\\n               --log_interval 1000 \\\n               --n_steps 20000 \\\n               --n_hidden 5 \\\n               --hidden_dim 64\n```\n*训练完成后，可使用 `--plot` 参数配合生成的 `.pt`  checkpoint 文件查看密度图。*\n\n### 2. 运行 MAF (MNIST 数据集密度估计)\n此示例使用掩码自回归流（MAF）在 MNIST 数据集上进行无条件密度估计训练 1 个 epoch（演示用，正式训练需更多 epoch）。\n\n```bash\npython maf.py --train \\\n              --model maf \\\n              --dataset MNIST \\\n              --n_blocks 5 \\\n              --conditional False\n```\n*注：如需进行类别条件生成，可添加 `--conditional True` 参数。*\n\n### 3. 运行 Glow (图像生成)\n**注意**：Glow 模型较大，首次运行前需准备 CelebA 或 MNIST 数据集。若使用 CelebA，请将数据解压后通过 `--data_dir` 指定路径。以下以单卡训练简化版为例：\n\n```bash\npython glow.py --train \\\n               --dataset celeba \\\n               --data_dir .\u002Fdata\u002Fceleba \\\n               --n_levels 3 \\\n               --depth 24 \\\n               --width 256 \\\n               --batch_size 16\n```\n\n*   **多卡分布式训练**（可选）：\n    ```bash\n    python -m torch.distributed.launch --nproc_per_node=NUM_GPUS_YOU_HAVE \\\n           glow.py --train --distributed --dataset=celeba --data_dir=.\u002Fdata\u002Fceleba ...\n    ```\n\n### 4. 运行基础平面流 (Planar Flow)\n针对论文中的 2D 能量势函数进行变分推断演示：\n\n```bash\npython planar_flow.py --train \\\n                      --target_potential u_z1 \\\n                      --flow_length 32\n```\n\n---\n**提示**：所有训练生成的模型检查点默认为 `.pt` 格式。使用 `--restore_file [path\u002Fto\u002Fmodel.pt]` 配合 `--evaluate` 或 `--generate` 参数即可加载预训练模型进行评估或采样生成。","某计算机视觉团队正在开发一个人脸属性编辑系统，需要基于 CelebA 数据集生成高质量且可精确控制的人脸图像。\n\n### 没有 normalizing_flows 时\n- **分布建模能力弱**：传统 GAN 模型难以精确计算数据概率密度，导致生成的样本多样性不足，容易陷入模式崩溃，无法覆盖复杂的人脸特征分布。\n- **属性编辑不可控**：缺乏可逆映射机制，无法在潜在空间中进行精确的数学运算，修改“微笑”或“戴眼镜”等属性时往往伴随身份特征丢失或画面伪影。\n- **训练稳定性差**：对抗训练过程波动大，需要大量调参技巧才能收敛，且不同温度下的采样质量参差不齐，难以满足生产环境对稳定性的要求。\n\n### 使用 normalizing_flows 后\n- **精准密度估计**：利用 Glow 算法的可逆 1x1 卷积特性，实现了对人脸数据分布的精确建模，生成的样本在多种温度设置下均保持高清晰度与自然度。\n- **线性属性操纵**：借助可逆流的双向特性，团队能在潜在空间中通过向量加减（如 $z_{new} = z + \\Delta z$）精确调整特定属性，同时完美保留人物身份和其他细节。\n- **训练高效稳定**：基于最大似然估计的训练目标避免了博弈震荡，模型在 10 万次迭代内即可稳定收敛至 4.2 bits\u002Fdim，显著降低了运维成本。\n\nnormalizing_flows 通过引入可逆变换与精确密度估计，将原本黑盒式的生成过程转化为可控、可解释的数学流，彻底解决了复杂数据分布下的生成质量与编辑精度难题。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkamenbliznashki_normalizing_flows_8493f33d.png","kamenbliznashki","Kamen Bliznashki","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fkamenbliznashki_2d36b16b.png",null,"Washington, DC","kamen.bliznashki@gmail.com","https:\u002F\u002Fgithub.com\u002Fkamenbliznashki",[80],{"name":81,"color":82,"percentage":83},"Python","#3572A5",100,637,102,"2026-01-21T07:35:45","未说明","训练 Glow 模型时建议使用多 GPU (通过 torch.distributed.launch)，具体显存需求取决于模型大小和批次大小 (例如：74M 参数模型在单卡上使用 batch_size=16，更大模型需使用梯度检查点 --checkpoint_grads 以节省显存)。其他模型 (BNAF, MAF) 支持 CUDA 但未强制要求。","未说明 (大模型训练如 Glow 的 190M 参数版本可能需要较大内存)",{"notes":91,"python":92,"dependencies":93},"1. 该项目是多种归一化流 (Normalizing Flows) 算法 (BNAF, Glow, MAF, RealNVP, Planar Flow) 的 PyTorch 复现。\n2. Glow 模型训练 CelebA 数据集时需自行下载数据并配置路径。\n3. 对于参数量巨大的模型 (如 Glow 的大尺寸版本)，必须添加 '--checkpoint_grads' 参数启用梯度检查点以防止显存溢出，但这会显著降低训练速度。\n4. 部分实验结果基于特定的超参数和数据预处理 (如 4-bit 或 5-bit 图像量化)，复现时需注意命令行参数配置。","未说明 (基于 PyTorch，通常建议 Python 3.6+)",[94,95,96],"torch","numpy","Pillow (用于图像处理)",[14],[99,100,101,102],"density-estmation","probability","deep-learning","normalizing-flows","2026-03-27T02:49:30.150509","2026-04-19T06:02:50.629592",[106,111,116,121,126,131],{"id":107,"question_zh":108,"answer_zh":109,"source_url":110},41729,"运行 BNAF 时出现 'torch.uint8' 已弃用的警告，该如何修复？","这是由于 PyTorch 版本变更（1.2 版本后）导致的，uint8 掩码已被 bool 取代。请在 bnaf.py 第 190 行将代码从 `logdet[self.mask_d.byte()]` 修改为 `logdet[self.mask_d.bool()]` 即可解决。","https:\u002F\u002Fgithub.com\u002Fkamenbliznashki\u002Fnormalizing_flows\u002Fissues\u002F9",{"id":112,"question_zh":113,"answer_zh":114,"source_url":115},41730,"运行 planar_flow.py 时报错 'name optimizer_state is not defined' 怎么办？","该错误通常发生在尝试从检查点恢复模型时。optimizer_state 仅在需要从检查点恢复时才需要加载。维护者已提交修复，如果您遇到此问题，请确保拉取最新代码，或者在逻辑上确保仅在存在检查点状态时才执行加载操作。","https:\u002F\u002Fgithub.com\u002Fkamenbliznashki\u002Fnormalizing_flows\u002Fissues\u002F5",{"id":117,"question_zh":118,"answer_zh":119,"source_url":120},41731,"为什么在耦合层（Coupling Layer）中还包含一个 ActNorm 层？","原始实现（如 OpenAI Glow）在所有中间卷积层之后都包含了 ActNorm。虽然未进行严格的对比实验，但在流深度较大且分辨率较高导致批量大小（batch size）受限的情况下，对所有预激活值进行归一化有助于提高训练的稳定性。","https:\u002F\u002Fgithub.com\u002Fkamenbliznashki\u002Fnormalizing_flows\u002Fissues\u002F3",{"id":122,"question_zh":123,"answer_zh":124,"source_url":125},41732,"MAF 模型评估函数中是否存在关于 log 概率和标签使用的错误？","是的，存在两处修正：1. 在均匀先验下，标签的对数先验概率应为 log(1\u002Fn_labels)；2. 评估循环应遍历每个可能的标签并通过 logsumexp 进行边缘化，因此 log_prob 计算时应使用动态生成的 `labels` 变量（即 `model.log_prob(x, labels)`），且在循环中正确更新 `labels[:,i] = 1`。","https:\u002F\u002Fgithub.com\u002Fkamenbliznashki\u002Fnormalizing_flows\u002Fissues\u002F1",{"id":127,"question_zh":128,"answer_zh":129,"source_url":130},41733,"RealNVP 的 BatchNorm 实现是否应该按通道计算均值和方差？","这取决于具体实现场景。该项目是遵循 MAF 论文的一维实现，使用的是表格数据集（tabular datasets），因此当前按整个批次计算均值和方差是符合该特定实验设置的。如果您处理的是图像数据或需要按通道归一化，则可能需要调整计算维度（如使用 `x.mean([0,2,3])`）。","https:\u002F\u002Fgithub.com\u002Fkamenbliznashki\u002Fnormalizing_flows\u002Fissues\u002F12",{"id":132,"question_zh":133,"answer_zh":134,"source_url":135},41734,"运行代码时提示 'No module named tqdm' 错误，如何解决？","这是因为缺少 tqdm 进度条库。请使用 pip 安装该依赖：`pip install tqdm`。安装完成后即可正常运行 bnaf.py 等脚本。","https:\u002F\u002Fgithub.com\u002Fkamenbliznashki\u002Fnormalizing_flows\u002Fissues\u002F2",[]]