[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-ahmedfgad--NumPyCNN":3,"tool-ahmedfgad--NumPyCNN":64},[4,18,26,35,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},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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107888,2,"2026-04-06T11:32:50",[14,15,13],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":10,"last_commit_at":41,"category_tags":42,"status":17},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[43,15,13,14],"语言模型",{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":10,"last_commit_at":50,"category_tags":51,"status":17},4292,"Deep-Live-Cam","hacksider\u002FDeep-Live-Cam","Deep-Live-Cam 是一款专注于实时换脸与视频生成的开源工具，用户仅需一张静态照片，即可通过“一键操作”实现摄像头画面的即时变脸或制作深度伪造视频。它有效解决了传统换脸技术流程繁琐、对硬件配置要求极高以及难以实时预览的痛点，让高质量的数字内容创作变得触手可及。\n\n这款工具不仅适合开发者和技术研究人员探索算法边界，更因其极简的操作逻辑（仅需三步：选脸、选摄像头、启动），广泛适用于普通用户、内容创作者、设计师及直播主播。无论是为了动画角色定制、服装展示模特替换，还是制作趣味短视频和直播互动，Deep-Live-Cam 都能提供流畅的支持。\n\n其核心技术亮点在于强大的实时处理能力，支持口型遮罩（Mouth Mask）以保留使用者原始的嘴部动作，确保表情自然精准；同时具备“人脸映射”功能，可同时对画面中的多个主体应用不同面孔。此外，项目内置了严格的内容安全过滤机制，自动拦截涉及裸露、暴力等不当素材，并倡导用户在获得授权及明确标注的前提下合规使用，体现了技术发展与伦理责任的平衡。",88924,"2026-04-06T03:28:53",[14,15,13,52],"视频",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",85013,"2026-04-06T11:09:19",[15,16,52,61,13,62,43,14,63],"插件","其他","音频",{"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":81,"owner_twitter":75,"owner_website":82,"owner_url":83,"languages":84,"stars":89,"forks":90,"last_commit_at":91,"license":79,"difficulty_score":92,"env_os":93,"env_gpu":94,"env_ram":94,"env_deps":95,"category_tags":100,"github_topics":101,"view_count":32,"oss_zip_url":79,"oss_zip_packed_at":79,"status":17,"created_at":113,"updated_at":114,"faqs":115,"releases":146},4482,"ahmedfgad\u002FNumPyCNN","NumPyCNN","Building Convolutional Neural Networks From Scratch using NumPy","NumPyCNN 是一个基于 Python NumPy 库从零构建卷积神经网络（CNN）的开源项目。它旨在帮助开发者深入理解 CNN 的内部运作机制，通过纯代码实现卷积、池化等核心操作，而非依赖现成的高级框架。\n\n该项目主要解决了深度学习初学者和研究者在学习过程中面临的“黑盒”难题。通过查看和运行 NumPyCNN 的源码，用户可以清晰地看到数据在网络中如何流动以及权重如何影响输出，从而掌握神经网络底层的数学原理与逻辑。目前，NumPyCNN 专注于实现网络的“前向传播”过程，适用于单标签图像分类任务。虽然它暂未包含标准的反向传播学习算法，但支持通过调整学习率来微调权重，并计划结合遗传算法库 PyGAD 进行更进阶的训练探索。\n\nNumPyCNN 非常适合希望夯实理论基础的开发人员、高校学生以及人工智能研究人员使用。对于想要脱离框架束缚、亲手编写神经网络每一行代码的技术爱好者来说，这是一个极佳的教学与实践工具。其最大的技术亮点在于完全摒弃了自动求导等高级特性，强制用户直面底层算法细节，是理解深度学习基石的理想起点。","# NumPyCNN: Implementing Convolutional Neural Networks From Scratch\nNumPyCNN is a Python implementation for convolutional neural networks (CNNs) from scratch using NumPy. \n\n**IMPORTANT** *If you are coming for the code of the tutorial titled [Building Convolutional Neural Network using NumPy from Scratch]( [https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad\u002F)), then it has been moved to the [TutorialProject](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN\u002Ftree\u002Fmaster\u002FTutorialProject) directory on 20 May 2020.*\n\nThe project has a single module named `cnn.py` which implements all classes and functions needed to build the CNN.\n\nIt is very important to note that the project only implements the **forward pass** of training CNNs and there is **no learning algorithm used**. Just the learning rate is used to make some changes to the weights after each epoch which is better than leaving the weights unchanged.\n\nThe project can be used for classification problems where only 1 class per sample is allowed.\n\nThe project will be extended to **train CNN using the genetic algorithm** with the help of a library named [PyGAD](https:\u002F\u002Fpypi.org\u002Fproject\u002Fpygad). Check the library's documentation at [Read The Docs](https:\u002F\u002Fpygad.readthedocs.io\u002F): https:\u002F\u002Fpygad.readthedocs.io\n\n# Donation\n\n- [Credit\u002FDebit Card](https:\u002F\u002Fdonate.stripe.com\u002FeVa5kO866elKgM0144): https:\u002F\u002Fdonate.stripe.com\u002FeVa5kO866elKgM0144\n- [Open Collective](https:\u002F\u002Fopencollective.com\u002Fpygad): [opencollective.com\u002Fpygad](https:\u002F\u002Fopencollective.com\u002Fpygad)\n- PayPal: Use either this link: [paypal.me\u002Fahmedfgad](https:\u002F\u002Fpaypal.me\u002Fahmedfgad) or the e-mail address ahmed.f.gad@gmail.com\n- Interac e-Transfer: Use e-mail address ahmed.f.gad@gmail.com\n\n# Installation\n\nTo install [PyGAD](https:\u002F\u002Fpypi.org\u002Fproject\u002Fpygad), simply use pip to download and install the library from [PyPI](https:\u002F\u002Fpypi.org\u002Fproject\u002Fpygad) (Python Package Index). The library is at PyPI at this page https:\u002F\u002Fpypi.org\u002Fproject\u002Fpygad.\n\nInstall PyGAD with the following command:\n\n```python\npip install pygad\n```\n\nTo get started with PyGAD, please read the documentation at [Read The Docs](https:\u002F\u002Fpygad.readthedocs.io\u002F) https:\u002F\u002Fpygad.readthedocs.io.\n\n# PyGAD Source Code\n\nThe source code of the PyGAD' modules is found in the following GitHub projects:\n\n- [pygad](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FGeneticAlgorithmPython): (https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FGeneticAlgorithmPython)\n- [pygad.nn](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyANN): https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyANN\n- [pygad.gann](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNeuralGenetic): https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNeuralGenetic\n- [pygad.cnn](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN): https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN\n- [pygad.gacnn](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FCNNGenetic): https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FCNNGenetic\n- [pygad.kerasga](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FKerasGA): https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FKerasGA\n- [pygad.torchga](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FTorchGA): https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FTorchGA\n\nThe documentation of PyGAD is available at [Read The Docs](https:\u002F\u002Fpygad.readthedocs.io\u002F) https:\u002F\u002Fpygad.readthedocs.io.\n\n# PyGAD Documentation\n\nThe documentation of the PyGAD library is available at [Read The Docs](https:\u002F\u002Fpygad.readthedocs.io) at this link: https:\u002F\u002Fpygad.readthedocs.io. It discusses the modules supported by PyGAD, all its classes, methods, attribute, and functions. For each module, a number of examples are given.\n\nIf there is an issue using PyGAD, feel free to post at issue in this [GitHub repository](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FGeneticAlgorithmPython) https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FGeneticAlgorithmPython or by sending an e-mail to ahmed.f.gad@gmail.com. \n\nIf you built a project that uses PyGAD, then please drop an e-mail to ahmed.f.gad@gmail.com with the following information so that your project is included in the documentation.\n\n- Project title\n- Brief description\n- Preferably, a link that directs the readers to your project\n\nPlease check the **Contact Us** section for more contact details.\n\n# Life Cycle of PyGAD\n\nThe next figure lists the different stages in the lifecycle of an instance of the `pygad.GA` class. Note that PyGAD stops when either all generations are completed or when the function passed to the `on_generation` parameter returns the string `stop`.\n\n![PyGAD Lifecycle](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_b0a501f9d60b.jpg)\n\nThe next code implements all the callback functions to trace the execution of the genetic algorithm. Each callback function prints its name.\n\n```python\nimport pygad\nimport numpy\n\nfunction_inputs = [4,-2,3.5,5,-11,-4.7]\ndesired_output = 44\n\ndef fitness_func(ga_instance, solution, solution_idx):\n    output = numpy.sum(solution*function_inputs)\n    fitness = 1.0 \u002F (numpy.abs(output - desired_output) + 0.000001)\n    return fitness\n\nfitness_function = fitness_func\n\ndef on_start(ga_instance):\n    print(\"on_start()\")\n\ndef on_fitness(ga_instance, population_fitness):\n    print(\"on_fitness()\")\n\ndef on_parents(ga_instance, selected_parents):\n    print(\"on_parents()\")\n\ndef on_crossover(ga_instance, offspring_crossover):\n    print(\"on_crossover()\")\n\ndef on_mutation(ga_instance, offspring_mutation):\n    print(\"on_mutation()\")\n\ndef on_generation(ga_instance):\n    print(\"on_generation()\")\n\ndef on_stop(ga_instance, last_population_fitness):\n    print(\"on_stop()\")\n\nga_instance = pygad.GA(num_generations=3,\n                       num_parents_mating=5,\n                       fitness_func=fitness_function,\n                       sol_per_pop=10,\n                       num_genes=len(function_inputs),\n                       on_start=on_start,\n                       on_fitness=on_fitness,\n                       on_parents=on_parents,\n                       on_crossover=on_crossover,\n                       on_mutation=on_mutation,\n                       on_generation=on_generation,\n                       on_stop=on_stop)\n\nga_instance.run()\n```\n\nBased on the used 3 generations as assigned to the `num_generations` argument, here is the output.\n\n```\non_start()\n\non_fitness()\non_parents()\non_crossover()\non_mutation()\non_generation()\n\non_fitness()\non_parents()\non_crossover()\non_mutation()\non_generation()\n\non_fitness()\non_parents()\non_crossover()\non_mutation()\non_generation()\n\non_stop()\n```\n\n# Example\n\nCheck the [PyGAD's documentation](https:\u002F\u002Fpygad.readthedocs.io\u002Fen\u002Flatest\u002Fcnn.html) for information about the implementation of this example.\n\n```python\nimport numpy\nimport pygad.cnn\n\ntrain_inputs = numpy.load(\"dataset_inputs.npy\")\ntrain_outputs = numpy.load(\"dataset_outputs.npy\")\n\nsample_shape = train_inputs.shape[1:]\nnum_classes = 4\n\ninput_layer = pygad.cnn.Input2D(input_shape=sample_shape)\nconv_layer1 = pygad.cnn.Conv2D(num_filters=2,\n                               kernel_size=3,\n                               previous_layer=input_layer,\n                               activation_function=None)\nrelu_layer1 = pygad.cnn.Sigmoid(previous_layer=conv_layer1)\naverage_pooling_layer = pygad.cnn.AveragePooling2D(pool_size=2, \n                                                   previous_layer=relu_layer1,\n                                                   stride=2)\n\nconv_layer2 = pygad.cnn.Conv2D(num_filters=3,\n                               kernel_size=3,\n                               previous_layer=average_pooling_layer,\n                               activation_function=None)\nrelu_layer2 = pygad.cnn.ReLU(previous_layer=conv_layer2)\nmax_pooling_layer = pygad.cnn.MaxPooling2D(pool_size=2, \n                                           previous_layer=relu_layer2,\n                                           stride=2)\n\nconv_layer3 = pygad.cnn.Conv2D(num_filters=1,\n                               kernel_size=3,\n                               previous_layer=max_pooling_layer,\n                               activation_function=None)\nrelu_layer3 = pygad.cnn.ReLU(previous_layer=conv_layer3)\npooling_layer = pygad.cnn.AveragePooling2D(pool_size=2, \n                                           previous_layer=relu_layer3,\n                                           stride=2)\n\nflatten_layer = pygad.cnn.Flatten(previous_layer=pooling_layer)\ndense_layer1 = pygad.cnn.Dense(num_neurons=100, \n                               previous_layer=flatten_layer,\n                               activation_function=\"relu\")\ndense_layer2 = pygad.cnn.Dense(num_neurons=num_classes, \n                               previous_layer=dense_layer1,\n                               activation_function=\"softmax\")\n\nmodel = pygad.cnn.Model(last_layer=dense_layer2,\n                        epochs=1,\n                        learning_rate=0.01)\n\nmodel.summary()\n\nmodel.train(train_inputs=train_inputs, \n            train_outputs=train_outputs)\n\npredictions = model.predict(data_inputs=train_inputs)\nprint(predictions)\n\nnum_wrong = numpy.where(predictions != train_outputs)[0]\nnum_correct = train_outputs.size - num_wrong.size\naccuracy = 100 * (num_correct\u002Ftrain_outputs.size)\nprint(\"Number of correct classifications : {num_correct}.\".format(num_correct=num_correct))\nprint(\"Number of wrong classifications : {num_wrong}.\".format(num_wrong=num_wrong.size))\nprint(\"Classification accuracy : {accuracy}.\".format(accuracy=accuracy))\n```\n\n# For More Information\n\nThere are different resources that can be used to get started with the building CNN and its Python implementation. \n\n## Tutorial: Implementing Genetic Algorithm in Python\n\nTo start with coding the genetic algorithm, you can check the tutorial titled [**Genetic Algorithm Implementation in Python**](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fgenetic-algorithm-implementation-python-ahmed-gad) available at these links:\n\n- [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fgenetic-algorithm-implementation-python-ahmed-gad)\n- [Towards Data Science](https:\u002F\u002Ftowardsdatascience.com\u002Fgenetic-algorithm-implementation-in-python-5ab67bb124a6)\n- [KDnuggets](https:\u002F\u002Fwww.kdnuggets.com\u002F2018\u002F07\u002Fgenetic-algorithm-implementation-python.html)\n\n[This tutorial](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fgenetic-algorithm-implementation-python-ahmed-gad) is prepared based on a previous version of the project but it still a good resource to start with coding the genetic algorithm.\n\n[![Genetic Algorithm Implementation in Python](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_7844a7f9ba02.png)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fgenetic-algorithm-implementation-python-ahmed-gad)\n\n## Tutorial: Introduction to Genetic Algorithm\n\nGet started with the genetic algorithm by reading the tutorial titled [**Introduction to Optimization with Genetic Algorithm**](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fintroduction-optimization-genetic-algorithm-ahmed-gad) which is available at these links:\n\n* [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fintroduction-optimization-genetic-algorithm-ahmed-gad)\n* [Towards Data Science](https:\u002F\u002Fwww.kdnuggets.com\u002F2018\u002F03\u002Fintroduction-optimization-with-genetic-algorithm.html)\n* [KDnuggets](https:\u002F\u002Ftowardsdatascience.com\u002Fintroduction-to-optimization-with-genetic-algorithm-2f5001d9964b)\n\n[![Introduction to Genetic Algorithm](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_4f24e8ee79ea.jpg)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fintroduction-optimization-genetic-algorithm-ahmed-gad)\n\n## Tutorial: Build Neural Networks in Python\n\nRead about building neural networks in Python through the tutorial titled [**Artificial Neural Network Implementation using NumPy and Classification of the Fruits360 Image Dataset**](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fartificial-neural-network-implementation-using-numpy-fruits360-gad) available at these links:\n\n* [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fartificial-neural-network-implementation-using-numpy-fruits360-gad)\n* [Towards Data Science](https:\u002F\u002Ftowardsdatascience.com\u002Fartificial-neural-network-implementation-using-numpy-and-classification-of-the-fruits360-image-3c56affa4491)\n* [KDnuggets](https:\u002F\u002Fwww.kdnuggets.com\u002F2019\u002F02\u002Fartificial-neural-network-implementation-using-numpy-and-image-classification.html)\n\n[![Building Neural Networks Python](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_ff2e0e87cd27.jpg)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fartificial-neural-network-implementation-using-numpy-fruits360-gad)\n\n## Tutorial: Optimize Neural Networks with Genetic Algorithm\n\nRead about training neural networks using the genetic algorithm through the tutorial titled [**Artificial Neural Networks Optimization using Genetic Algorithm with Python**](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fartificial-neural-networks-optimization-using-genetic-ahmed-gad) available at these links:\n\n- [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fartificial-neural-networks-optimization-using-genetic-ahmed-gad)\n- [Towards Data Science](https:\u002F\u002Ftowardsdatascience.com\u002Fartificial-neural-networks-optimization-using-genetic-algorithm-with-python-1fe8ed17733e)\n- [KDnuggets](https:\u002F\u002Fwww.kdnuggets.com\u002F2019\u002F03\u002Fartificial-neural-networks-optimization-genetic-algorithm-python.html)\n\n[![Training Neural Networks using Genetic Algorithm Python](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_913447204355.jpg)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fartificial-neural-networks-optimization-using-genetic-ahmed-gad)\n\n## Tutorial: Building CNN in Python\n\nTo start with coding the genetic algorithm, you can check the tutorial titled [**Building Convolutional Neural Network using NumPy from Scratch**](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad) available at these links:\n\n- [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad)\n- [Towards Data Science](https:\u002F\u002Ftowardsdatascience.com\u002Fbuilding-convolutional-neural-network-using-numpy-from-scratch-b30aac50e50a)\n- [KDnuggets](https:\u002F\u002Fwww.kdnuggets.com\u002F2018\u002F04\u002Fbuilding-convolutional-neural-network-numpy-scratch.html)\n- [Chinese Translation](http:\u002F\u002Fm.aliyun.com\u002Fyunqi\u002Farticles\u002F585741)\n\n[This tutorial](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad)) is prepared based on a previous version of the project but it still a good resource to start with coding CNNs.\n\n[![Building CNN in Python](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_1b1616c24d91.png)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad)\n\n## Tutorial: Derivation of CNN from FCNN\n\nGet started with the genetic algorithm by reading the tutorial titled [**Derivation of Convolutional Neural Network from Fully Connected Network Step-By-Step**](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fderivation-convolutional-neural-network-from-fully-connected-gad) which is available at these links:\n\n* [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fderivation-convolutional-neural-network-from-fully-connected-gad)\n* [Towards Data Science](https:\u002F\u002Ftowardsdatascience.com\u002Fderivation-of-convolutional-neural-network-from-fully-connected-network-step-by-step-b42ebafa5275)\n* [KDnuggets](https:\u002F\u002Fwww.kdnuggets.com\u002F2018\u002F04\u002Fderivation-convolutional-neural-network-fully-connected-step-by-step.html)\n\n[![Derivation of CNN from FCNN](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_726939802f6c.png)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fderivation-convolutional-neural-network-from-fully-connected-gad)\n\n## Book: Practical Computer Vision Applications Using Deep Learning with CNNs\n\nYou can also check my book cited as [**Ahmed Fawzy Gad 'Practical Computer Vision Applications Using Deep Learning with CNNs'. Dec. 2018, Apress, 978-1-4842-4167-7**](https:\u002F\u002Fwww.amazon.com\u002FPractical-Computer-Vision-Applications-Learning\u002Fdp\u002F1484241665) which discusses neural networks, convolutional neural networks, deep learning, genetic algorithm, and more.\n\nFind the book at these links:\n\n- [Amazon](https:\u002F\u002Fwww.amazon.com\u002FPractical-Computer-Vision-Applications-Learning\u002Fdp\u002F1484241665)\n- [Springer](https:\u002F\u002Flink.springer.com\u002Fbook\u002F10.1007\u002F978-1-4842-4167-7)\n- [Apress](https:\u002F\u002Fwww.apress.com\u002Fgp\u002Fbook\u002F9781484241660)\n- [O'Reilly](https:\u002F\u002Fwww.oreilly.com\u002Flibrary\u002Fview\u002Fpractical-computer-vision\u002F9781484241677)\n- [Google Books](https:\u002F\u002Fbooks.google.com.eg\u002Fbooks?id=xLd9DwAAQBAJ)\n\n![Fig04](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_4aba9998f41f.jpg)\n\n# Citing PyGAD - Bibtex Formatted Citation\n\nIf you used PyGAD, please consider adding a citation to the following paper about PyGAD:\n\n```\n@misc{gad2021pygad,\n      title={PyGAD: An Intuitive Genetic Algorithm Python Library}, \n      author={Ahmed Fawzy Gad},\n      year={2021},\n      eprint={2106.06158},\n      archivePrefix={arXiv},\n      primaryClass={cs.NE}\n}\n```\n\n# Contact Us\n\n* E-mail: ahmed.f.gad@gmail.com\n* [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fahmedfgad)\n* [Amazon Author Page](https:\u002F\u002Famazon.com\u002Fauthor\u002Fahmedgad)\n* [Heartbeat](https:\u002F\u002Fheartbeat.fritz.ai\u002F@ahmedfgad)\n* [Paperspace](https:\u002F\u002Fblog.paperspace.com\u002Fauthor\u002Fahmed)\n* [KDnuggets](https:\u002F\u002Fkdnuggets.com\u002Fauthor\u002Fahmed-gad)\n* [TowardsDataScience](https:\u002F\u002Ftowardsdatascience.com\u002F@ahmedfgad)\n* [GitHub](https:\u002F\u002Fgithub.com\u002Fahmedfgad)\n","# NumPyCNN：从零开始实现卷积神经网络\nNumPyCNN 是一个使用 NumPy 从零开始实现的卷积神经网络（CNN）Python 库。\n\n**重要提示** *如果您是为名为[使用 NumPy 从零开始构建卷积神经网络]( [https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad\u002F)) 的教程代码而来，那么该代码已于 2020 年 5 月 20 日移至 [TutorialProject](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN\u002Ftree\u002Fmaster\u002FTutorialProject) 目录下。*\n\n该项目包含一个名为 `cnn.py` 的模块，实现了构建 CNN 所需的所有类和函数。\n\n需要注意的是，该项目仅实现了 CNN 训练的 **前向传播**，并且 **未使用任何学习算法**。每次迭代后仅会根据学习率对权重进行一些调整，这比保持权重不变要好。\n\n该项目可用于分类问题，但每个样本只能属于一个类别。\n\n未来，该项目将借助名为 [PyGAD](https:\u002F\u002Fpypi.org\u002Fproject\u002Fpygad) 的库扩展为 **使用遗传算法训练 CNN**。请参阅该库的文档：[Read The Docs](https:\u002F\u002Fpygad.readthedocs.io)：https:\u002F\u002Fpygad.readthedocs.io\n\n# 捐赠\n\n- [信用卡\u002F借记卡](https:\u002F\u002Fdonate.stripe.com\u002FeVa5kO866elKgM0144)：https:\u002F\u002Fdonate.stripe.com\u002FeVa5kO866elKgM0144\n- [Open Collective](https:\u002F\u002Fopencollective.com\u002Fpygad)：[opencollective.com\u002Fpygad](https:\u002F\u002Fopencollective.com\u002Fpygad)\n- PayPal：可使用此链接：[paypal.me\u002Fahmedfgad](https:\u002F\u002Fpaypal.me\u002Fahmedfgad)，或发送邮件至 ahmed.f.gad@gmail.com\n- Interac 电子转账：请使用电子邮件地址 ahmed.f.gad@gmail.com\n\n# 安装\n\n要安装 [PyGAD](https:\u002F\u002Fpypi.org\u002Fproject\u002Fpygad)，只需使用 pip 从 [PyPI](https:\u002F\u002Fpypi.org\u002Fproject\u002Fpygad)（Python 软件包索引）下载并安装该库。该库在 PyPI 上的页面为：https:\u002F\u002Fpypi.org\u002Fproject\u002Fpygad。\n\n通过以下命令安装 PyGAD：\n\n```python\npip install pygad\n```\n\n要开始使用 PyGAD，请阅读位于 [Read The Docs](https:\u002F\u002Fpygad.readthedocs.io\u002F) 的文档：https:\u002F\u002Fpygad.readthedocs.io。\n\n# PyGAD 源代码\n\nPyGAD 各模块的源代码位于以下 GitHub 项目中：\n\n- [pygad](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FGeneticAlgorithmPython)：(https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FGeneticAlgorithmPython)\n- [pygad.nn](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyANN)：https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyANN\n- [pygad.gann](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNeuralGenetic)：https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNeuralGenetic\n- [pygad.cnn](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN)：https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN\n- [pygad.gacnn](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FCNNGenetic)：https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FCNNGenetic\n- [pygad.kerasga](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FKerasGA)：https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FKerasGA\n- [pygad.torchga](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FTorchGA)：https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FTorchGA\n\nPyGAD 的文档可在 [Read The Docs](https:\u002F\u002Fpygad.readthedocs.io) 上找到：https:\u002F\u002Fpygad.readthedocs.io。\n\n# PyGAD 文档\n\nPyGAD 库的文档可在 [Read The Docs](https:\u002F\u002Fpygad.readthedocs.io) 上找到，链接为：https:\u002F\u002Fpygad.readthedocs.io。文档详细介绍了 PyGAD 支持的模块、所有类、方法、属性和函数，并为每个模块提供了多个示例。\n\n如果在使用 PyGAD 时遇到问题，欢迎在 [GitHub 仓库](https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FGeneticAlgorithmPython) 中提交问题：https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FGeneticAlgorithmPython，或发送邮件至 ahmed.f.gad@gmail.com。\n\n如果您开发了使用 PyGAD 的项目，请将以下信息发送至 ahmed.f.gad@gmail.com，以便您的项目能被收录到文档中：\n\n- 项目标题\n- 简要描述\n- 最好附上指向您项目的链接\n\n更多联系方式请参阅“联系我们”部分。\n\n# PyGAD 生命周期\n\n下图列出了 `pygad.GA` 类实例生命周期中的各个阶段。请注意，当所有代数完成，或者传递给 `on_generation` 参数的函数返回字符串 `stop` 时，PyGAD 将停止运行。\n\n![PyGAD 生命周期](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_b0a501f9d60b.jpg)\n\n以下代码实现了所有回调函数，用于跟踪遗传算法的执行过程。每个回调函数都会打印其名称。\n\n```python\nimport pygad\nimport numpy\n\nfunction_inputs = [4,-2,3.5,5,-11,-4.7]\ndesired_output = 44\n\ndef fitness_func(ga_instance, solution, solution_idx):\n    output = numpy.sum(solution*function_inputs)\n    fitness = 1.0 \u002F (numpy.abs(output - desired_output) + 0.000001)\n    return fitness\n\nfitness_function = fitness_func\n\ndef on_start(ga_instance):\n    print(\"on_start()\")\n\ndef on_fitness(ga_instance, population_fitness):\n    print(\"on_fitness()\")\n\ndef on_parents(ga_instance, selected_parents):\n    print(\"on_parents()\")\n\ndef on_crossover(ga_instance, offspring_crossover):\n    print(\"on_crossover()\")\n\ndef on_mutation(ga_instance, offspring_mutation):\n    print(\"on_mutation()\")\n\ndef on_generation(ga_instance):\n    print(\"on_generation()\")\n\ndef on_stop(ga_instance, last_population_fitness):\n    print(\"on_stop()\")\n\nga_instance = pygad.GA(num_generations=3,\n                       num_parents_mating=5,\n                       fitness_func=fitness_function,\n                       sol_per_pop=10,\n                       num_genes=len(function_inputs),\n                       on_start=on_start,\n                       on_fitness=on_fitness,\n                       on_parents=on_parents,\n                       on_crossover=on_crossover,\n                       on_mutation=on_mutation,\n                       on_generation=on_generation,\n                       on_stop=on_stop)\n\nga_instance.run()\n```\n\n根据 `num_generations` 参数设置的 3 个世代，输出如下：\n\n```\non_start()\n\non_fitness()\non_parents()\non_crossover()\non_mutation()\non_generation()\n\non_fitness()\non_parents()\non_crossover()\non_mutation()\non_generation()\n\non_fitness()\non_parents()\non_crossover()\non_mutation()\non_generation()\n\non_stop()\n```\n\n# 示例\n\n有关此示例的实现信息，请参阅 [PyGAD 的文档](https:\u002F\u002Fpygad.readthedocs.io\u002Fen\u002Flatest\u002Fcnn.html)。\n\n```python\nimport numpy\nimport pygad.cnn\n\ntrain_inputs = numpy.load(\"dataset_inputs.npy\")\ntrain_outputs = numpy.load(\"dataset_outputs.npy\")\n\nsample_shape = train_inputs.shape[1:]\nnum_classes = 4\n\ninput_layer = pygad.cnn.Input2D(input_shape=sample_shape)\nconv_layer1 = pygad.cnn.Conv2D(num_filters=2,\n                               kernel_size=3,\n                               previous_layer=input_layer,\n                               activation_function=None)\nrelu_layer1 = pygad.cnn.Sigmoid(previous_layer=conv_layer1)\naverage_pooling_layer = pygad.cnn.AveragePooling2D(pool_size=2, \n                                                   previous_layer=relu_layer1,\n                                                   stride=2)\n\nconv_layer2 = pygad.cnn.Conv2D(num_filters=3,\n                               kernel_size=3,\n                               previous_layer=average_pooling_layer,\n                               activation_function=None)\nrelu_layer2 = pygad.cnn.ReLU(previous_layer=conv_layer2)\nmax_pooling_layer = pygad.cnn.MaxPooling2D(pool_size=2, \n                                           previous_layer=relu_layer2,\n                                           stride=2)\n\nconv_layer3 = pygad.cnn.Conv2D(num_filters=1,\n                               kernel_size=3,\n                               previous_layer=max_pooling_layer,\n                               activation_function=None)\nrelu_layer3 = pygad.cnn.ReLU(previous_layer=conv_layer3)\npooling_layer = pygad.cnn.AveragePooling2D(pool_size=2, \n                                           previous_layer=relu_layer3,\n                                           stride=2)\n\nflatten_layer = pygad.cnn.Flatten(previous_layer=pooling_layer)\ndense_layer1 = pygad.cnn.Dense(num_neurons=100, \n                               previous_layer=flatten_layer,\n                               activation_function=\"relu\")\ndense_layer2 = pygad.cnn.Dense(num_neurons=num_classes, \n                               previous_layer=dense_layer1,\n                               activation_function=\"softmax\")\n\nmodel = pygad.cnn.Model(last_layer=dense_layer2,\n                        epochs=1,\n                        learning_rate=0.01)\n\nmodel.summary()\n\nmodel.train(train_inputs=train_inputs, \n            train_outputs=train_outputs)\n\npredictions = model.predict(data_inputs=train_inputs)\nprint(predictions)\n\nnum_wrong = numpy.where(predictions != train_outputs)[0]\nnum_correct = train_outputs.size - num_wrong.size\naccuracy = 100 * (num_correct\u002Ftrain_outputs.size)\nprint(\"正确分类的数量：{num_correct}。\".format(num_correct=num_correct))\nprint(\"错误分类的数量：{num_wrong}。\".format(num_wrong=num_wrong.size))\nprint(\"分类准确率：{accuracy}%。\".format(accuracy=accuracy))\n```\n\n# 更多信息\n\n有多种资源可以帮助您开始构建卷积神经网络及其 Python 实现。\n\n## 教程：在 Python 中实现遗传算法\n\n要开始编写遗传算法代码，您可以查看题为 **“在 Python 中实现遗传算法”** 的教程，该教程可通过以下链接访问：\n\n- [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fgenetic-algorithm-implementation-python-ahmed-gad)\n- [Towards Data Science](https:\u002F\u002Ftowardsdatascience.com\u002Fgenetic-algorithm-implementation-in-python-5ab67bb124a6)\n- [KDnuggets](https:\u002F\u002Fwww.kdnuggets.com\u002F2018\u002F07\u002Fgenetic-algorithm-implementation-python.html)\n\n[本教程](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fgenetic-algorithm-implementation-python-ahmed-gad) 是基于该项目的早期版本编写的，但仍然是开始学习遗传算法编程的一个很好的资源。\n\n[![在 Python 中实现遗传算法](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_7844a7f9ba02.png)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fgenetic-algorithm-implementation-python-ahmed-gad)\n\n## 教程：遗传算法简介\n\n通过阅读题为 **“使用遗传算法进行优化简介”** 的教程来入门遗传算法，该教程可通过以下链接访问：\n\n* [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fintroduction-optimization-genetic-algorithm-ahmed-gad)\n* [Towards Data Science](https:\u002F\u002Fwww.kdnuggets.com\u002F2018\u002F03\u002Fintroduction-optimization-with-genetic-algorithm.html)\n* [KDnuggets](https:\u002F\u002Ftowardsdatascience.com\u002Fintroduction-to-optimization-with-genetic-algorithm-2f5001d9964b)\n\n[![遗传算法简介](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_4f24e8ee79ea.jpg)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fintroduction-optimization-genetic-algorithm-ahmed-gad)\n\n## 教程：在 Python 中构建神经网络\n\n通过题为 **“使用 NumPy 实现人工神经网络并分类 Fruits360 图像数据集”** 的教程了解如何在 Python 中构建神经网络，该教程可通过以下链接访问：\n\n* [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fartificial-neural-network-implementation-using-numpy-fruits360-gad)\n* [Towards Data Science](https:\u002F\u002Ftowardsdatascience.com\u002Fartificial-neural-network-implementation-using-numpy-and-classification-of-the-fruits360-image-3c56affa4491)\n* [KDnuggets](https:\u002F\u002Fwww.kdnuggets.com\u002F2019\u002F02\u002Fartificial-neural-network-implementation-using-numpy-and-image-classification.html)\n\n[![Python 中构建神经网络](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_ff2e0e87cd27.jpg)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fartificial-neural-network-implementation-using-numpy-fruits360-gad)\n\n## 教程：用遗传算法优化神经网络\n\n通过题为 **“使用遗传算法和 Python 优化人工神经网络”** 的教程了解如何利用遗传算法训练神经网络，该教程可通过以下链接访问：\n\n- [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fartificial-neural-networks-optimization-using-genetic-ahmed-gad)\n- [Towards Data Science](https:\u002F\u002Ftowardsdatascience.com\u002Fartificial-neural-networks-optimization-using-genetic-algorithm-with-python-1fe8ed17733e)\n- [KDnuggets](https:\u002F\u002Fwww.kdnuggets.com\u002F2019\u002F03\u002Fartificial-neural-networks-optimization-genetic-algorithm-python.html)\n\n[![使用遗传算法训练神经网络](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_913447204355.jpg)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fartificial-neural-networks-optimization-using-genetic-ahmed-gad)\n\n## 教程：用Python构建卷积神经网络\n\n要开始编写遗传算法，您可以查看题为[**从零开始使用NumPy构建卷积神经网络**](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad)的教程，该教程可通过以下链接访问：\n\n- [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad)\n- [Towards Data Science](https:\u002F\u002Ftowardsdatascience.com\u002Fbuilding-convolutional-neural-network-using-numpy-from-scratch-b30aac50e50a)\n- [KDnuggets](https:\u002F\u002Fwww.kdnuggets.com\u002F2018\u002F04\u002Fbuilding-convolutional-neural-network-numpy-scratch.html)\n- [中文翻译](http:\u002F\u002Fm.aliyun.com\u002Fyunqi\u002Farticles\u002F585741)\n\n[本教程](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad)是基于该项目的早期版本编写的，但仍然是开始编码CNN的一个很好的资源。\n\n[![用Python构建CNN](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_1b1616c24d91.png)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fbuilding-convolutional-neural-network-using-numpy-from-ahmed-gad)\n\n## 教程：从全连接神经网络推导卷积神经网络\n\n通过阅读题为[**逐步从全连接网络推导卷积神经网络**](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fderivation-convolutional-neural-network-from-fully-connected-gad)的教程，您可以开始学习遗传算法。该教程可通过以下链接访问：\n\n* [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fderivation-convolutional-neural-network-from-fully-connected-gad)\n* [Towards Data Science](https:\u002F\u002Ftowardsdatascience.com\u002Fderivation-of-convolutional-neural-network-from-fully-connected-network-step-by-step-b42ebafa5275)\n* [KDnuggets](https:\u002F\u002Fwww.kdnuggets.com\u002F2018\u002F04\u002Fderivation-convolutional-neural-network-fully-connected-step-by-step.html)\n\n[![从FCNN推导CNN](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_726939802f6c.png)](https:\u002F\u002Fwww.linkedin.com\u002Fpulse\u002Fderivation-convolutional-neural-network-from-fully-connected-gad)\n\n## 书籍：使用CNN进行深度学习的实用计算机视觉应用\n\n您还可以查阅我的著作，即[**Ahmed Fawzy Gad《使用CNN进行深度学习的实用计算机视觉应用》。2018年12月，Apress出版社，ISBN 978-1-4842-4167-7**](https:\u002F\u002Fwww.amazon.com\u002FPractical-Computer-Vision-Applications-Learning\u002Fdp\u002F148424165)，书中讨论了神经网络、卷积神经网络、深度学习、遗传算法等内容。\n\n您可以通过以下链接找到该书：\n\n- [亚马逊](https:\u002F\u002Fwww.amazon.com\u002FPractical-Computer-Vision-Applications-Learning\u002Fdp\u002F1484241665)\n- [施普林格](https:\u002F\u002Flink.springer.com\u002Fbook\u002F10.1007\u002F978-1-4842-4167-7)\n- [Apress](https:\u002F\u002Fwww.apress.com\u002Fgp\u002Fbook\u002F9781484241660)\n- [O'Reilly](https:\u002F\u002Fwww.oreilly.com\u002Flibrary\u002Fview\u002Fpractical-computer-vision\u002F9781484241677)\n- [Google图书](https:\u002F\u002Fbooks.google.com.eg\u002Fbooks?id=xLd9DwAAQBAJ)\n\n![Fig04](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_readme_4aba9998f41f.jpg)\n\n# 引用PyGAD——BibTeX格式的引用\n\n如果您使用了PyGAD，请考虑在关于PyGAD的论文中添加以下引用：\n\n```\n@misc{gad2021pygad,\n      title={PyGAD: 一个直观的遗传算法Python库}, \n      author={Ahmed Fawzy Gad},\n      year={2021},\n      eprint={2106.06158},\n      archivePrefix={arXiv},\n      primaryClass={cs.NE}\n}\n```\n\n# 联系我们\n\n* 邮箱：ahmed.f.gad@gmail.com\n* [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fahmedfgad)\n* [亚马逊作者页面](https:\u002F\u002Famazon.com\u002Fauthor\u002Fahmedgad)\n* [Heartbeat](https:\u002F\u002Fheartbeat.fritz.ai\u002F@ahmedfgad)\n* [Paperspace](https:\u002F\u002Fblog.paperspace.com\u002Fauthor\u002Fahmed)\n* [KDnuggets](https:\u002F\u002Fkdnuggets.com\u002Fauthor\u002Fahmed-gad)\n* [TowardsDataScience](https:\u002F\u002Ftowardsdatascience.com\u002F@ahmedfgad)\n* [GitHub](https:\u002F\u002Fgithub.com\u002Fahmedfgad)","# NumPyCNN 快速上手指南\n\nNumPyCNN 是一个完全使用 Python 和 NumPy 从零开始实现的卷积神经网络（CNN）库。该项目主要用于教学和理解 CNN 的前向传播原理，并计划结合遗传算法（通过 PyGAD 库）进行模型训练。\n\n> **注意**：当前版本主要实现 CNN 的**前向传播**。虽然支持通过简单的学习率调整权重，但并未包含标准的反向传播学习算法。完整的训练功能需配合 `PyGAD` 库使用遗传算法实现。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**：Windows、Linux 或 macOS\n*   **Python 版本**：Python 3.x\n*   **核心依赖**：\n    *   `numpy`：用于数值计算\n    *   `pygad`：用于遗传算法训练（NumPyCNN 的核心训练依赖）\n\n## 安装步骤\n\n推荐使用 pip 进行安装。如果您在中国大陆地区，建议使用国内镜像源以加速下载。\n\n### 1. 安装依赖库\n\n使用清华镜像源安装 `pygad`（该库已包含对 NumPyCNN 的支持及 numpy 依赖）：\n\n```bash\npip install pygad -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n或者使用阿里云镜像源：\n\n```bash\npip install pygad -i https:\u002F\u002Fmirrors.aliyun.com\u002Fpypi\u002Fsimple\u002F\n```\n\n### 2. 验证安装\n\n安装完成后，您可以在 Python 中尝试导入模块以验证是否成功：\n\n```python\nimport pygad.cnn\nimport numpy\nprint(\"Installation successful!\")\n```\n\n## 基本使用\n\n以下是一个构建简单 CNN 模型并进行预测的最小化示例。该示例展示了如何定义网络层、初始化模型以及执行前向传播。\n\n### 代码示例\n\n```python\nimport numpy\nimport pygad.cnn\n\n# 1. 准备数据 (此处使用随机数据演示，实际使用时请加载您的数据集)\n# 假设输入形状为 (样本数, 高, 宽, 通道数)，例如 (10, 28, 28, 1)\ntrain_inputs = numpy.random.rand(10, 28, 28, 1)\n# 假设输出为分类标签 (0-3)\ntrain_outputs = numpy.random.randint(0, 4, size=(10,))\n\nsample_shape = train_inputs.shape[1:]\nnum_classes = 4\n\n# 2. 构建网络层\n# 输入层\ninput_layer = pygad.cnn.Input2D(input_shape=sample_shape)\n\n# 卷积层 1 + 激活函数\nconv_layer1 = pygad.cnn.Conv2D(num_filters=2,\n                               kernel_size=3,\n                               previous_layer=input_layer,\n                               activation_function=None)\nrelu_layer1 = pygad.cnn.Sigmoid(previous_layer=conv_layer1) # 原文示例使用 Sigmoid，也可用 ReLU\n\n# 池化层 1\naverage_pooling_layer = pygad.cnn.AveragePooling2D(pool_size=2, \n                                                   previous_layer=relu_layer1,\n                                                   stride=2)\n\n# 卷积层 2 + 激活函数\nconv_layer2 = pygad.cnn.Conv2D(num_filters=3,\n                               kernel_size=3,\n                               previous_layer=average_pooling_layer,\n                               activation_function=None)\nrelu_layer2 = pygad.cnn.ReLU(previous_layer=conv_layer2)\n\n# 池化层 2\nmax_pooling_layer = pygad.cnn.MaxPooling2D(pool_size=2, \n                                           previous_layer=relu_layer2,\n                                           stride=2)\n\n# 卷积层 3 + 激活函数\nconv_layer3 = pygad.cnn.Conv2D(num_filters=1,\n                               kernel_size=3,\n                               previous_layer=max_pooling_layer,\n                               activation_function=None)\nrelu_layer3 = pygad.cnn.ReLU(previous_layer=conv_layer3)\n\n# 展平层\nflatten_layer = pygad.cnn.Flatten(previous_layer=relu_layer3)\n\n# 全连接层 (Dense Layers)\ndense_layer1 = pygad.cnn.Dense(num_neurons=100, \n                               previous_layer=flatten_layer,\n                               activation_function=\"relu\")\ndense_layer2 = pygad.cnn.Dense(num_neurons=num_classes, \n                               previous_layer=dense_layer1,\n                               activation_function=\"softmax\")\n\n# 3. 初始化模型\nmodel = pygad.cnn.Model(last_layer=dense_layer2,\n                        epochs=1,          # 迭代次数\n                        learning_rate=0.01) # 学习率\n\n# 查看模型结构摘要\nmodel.summary()\n\n# 4. 训练模型\n# 注意：此处的 train 方法主要基于遗传算法框架或简单的权重扰动，非传统反向传播\nmodel.train(train_inputs=train_inputs, \n            train_outputs=train_outputs)\n\n# 5. 进行预测\npredictions = model.predict(data_inputs=train_inputs)\n\n# 6. 计算准确率\nnum_wrong = numpy.where(predictions != train_outputs)[0]\nnum_correct = train_outputs.size - num_wrong.size\naccuracy = 100 * (num_correct\u002Ftrain_outputs.size)\n\nprint(f\"Number of correct classifications : {num_correct}.\")\nprint(f\"Number of wrong classifications : {num_wrong.size}.\")\nprint(f\"Classification accuracy : {accuracy}.\")\n```\n\n### 说明\n*   **层连接**：每一层通过 `previous_layer` 参数连接到上一层，形成链式结构。\n*   **训练机制**：由于本项目侧重于从零实现原理，其 `train` 方法在未结合外部优化器时，仅利用学习率对权重进行微调。若要获得更好的训练效果，请参考 PyGAD 文档使用遗传算法进行优化。\n*   **数据类型**：本示例适用于单标签分类问题（每个样本仅属于一个类别）。","某高校人工智能实验室的研究员正在为本科生设计一门深度学习原理课程，需要让学生在不依赖高级框架的情况下，亲手理解卷积神经网络的底层数学机制。\n\n### 没有 NumPyCNN 时\n- 学生必须从零开始编写每一行矩阵运算代码来构建卷积层和池化层，极易因索引错误导致调试困难，耗费大量时间在非核心逻辑上。\n- 缺乏统一的模块化结构，不同学生实现的“手写 CNN\"代码风格迥异，教师难以进行统一的教学评估和代码审查。\n- 由于手动实现反向传播算法难度极高且容易出错，课程往往只能停留在理论推导，无法让学生看到模型实际运行和权重更新的过程。\n- 想要尝试不同的优化策略（如遗传算法）时，需要重新重构整个训练循环，扩展性极差，限制了实验的深度。\n\n### 使用 NumPyCNN 后\n- 学生直接调用 `cnn.py` 中封装好的类即可搭建完整的 CNN 前向传播流程，将精力集中在理解卷积核如何提取特征这一核心教学目标上。\n- 项目提供了标准化的单模块实现，所有学生基于同一套清晰的代码基线进行实验，极大提升了教学效率和代码可比性。\n- 虽然默认仅包含前向传播，但结合简单的学习率调整机制，学生能直观观察到权重变化对分类结果的影响，成功打通理论与实践的最后一公里。\n- 架构天然支持与 PyGAD 库对接，学生可以轻松替换训练逻辑，利用遗传算法训练网络，从而深入探索传统梯度下降之外的优化路径。\n\nNumPyCNN 通过剥离高级框架的黑盒特性，为教育者和研究者提供了一个透明、可定制的底层实验平台，让深度学习的内部机理真正变得可见且可操作。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fahmedfgad_NumPyCNN_eb4585c8.png","ahmedfgad","Ahmed Gad","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fahmedfgad_6fdf3b67.jpg","Machine Learning Researcher & Technical Author \u002F\u002F Open to Work",null,"Ottawa, ON, Canada","ahmed.f.gad@gmail.com","https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fahmedfgad","https:\u002F\u002Fgithub.com\u002Fahmedfgad",[85],{"name":86,"color":87,"percentage":88},"Python","#3572A5",100,601,188,"2026-04-05T12:29:54",1,"","未说明",{"notes":96,"python":94,"dependencies":97},"该项目仅使用 NumPy 从零实现卷积神经网络（CNN）的前向传播，不包含反向传播或标准学习算法。若需训练模型，需配合 PyGAD 库使用遗传算法。项目适用于单标签分类问题。安装主要依赖为 numpy 和 pygad（可通过 pip install pygad 安装）。由于纯 Python\u002FNumPy 实现，未提及特定的操作系统、GPU 加速或内存硬性要求，理论上支持任何能运行 Python 和 NumPy 的环境。",[98,99],"numpy","pygad",[16,62,15],[98,102,103,104,105,106,107,108,109,110,111,112,99],"convolutional-neural-networks","convnet","cnn","python","computer-vision","data-science","relu","relu-layer","convolution","conv-layer","filter","2026-03-27T02:49:30.150509","2026-04-06T23:57:37.457323",[116,121,126,131,136,141],{"id":117,"question_zh":118,"answer_zh":119,"source_url":120},20386,"运行代码时出现 'operands could not be broadcast together' 形状不匹配错误怎么办？","该错误通常由整数除法导致计算出的区域尺寸小于滤波器尺寸引起。例如，`numpy.ceil(3\u002F2)` 在整数除法下结果为 1 而非预期的 2。解决方法是将除法运算中的一个数改为浮点数，确保执行浮点除法。请将代码中的 `numpy.ceil(filter_size\u002F2)` 修改为 `numpy.ceil(filter_size\u002F2.0)`，同样适用于 `numpy.floor` 部分，以确保区域切片大小正确。","https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN\u002Fissues\u002F1",{"id":122,"question_zh":123,"answer_zh":124,"source_url":125},20387,"如何创建并使用自己的数据集进行训练？","数据集本质上是一个保存为 `.npy` 文件的 NumPy 数组。你可以编写一个循环来读取图像文件，将每张图像追加到一个 NumPy 数组中，最后使用 `numpy.save` 将该数组保存为 `.npy` 文件。加载时直接使用 `numpy.load` 读取该文件即可作为输入数据。","https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN\u002Fissues\u002F12",{"id":127,"question_zh":128,"answer_zh":129,"source_url":130},20388,"为什么卷积核（滤波器）要使用随机数初始化？原理是什么？","通常情况下，CNN 的所有卷积核都是随机初始化的，因为它们是网络需要学习的权重。项目中前两层使用特定值（如计算水平和垂直梯度）是为了便于书籍演示和结果解释。在实际应用或从头训练时，应遵循惯例将所有卷积核随机初始化。","https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN\u002Fissues\u002F9",{"id":132,"question_zh":133,"answer_zh":134,"source_url":135},20389,"ReLU 激活函数实现中存在什么常见代码错误？","原始代码中 `numpy.max(feature_map[r, c, map_num], 0)` 写法有误，无法正确比较标量与 0。正确的写法需要将参数放入列表中，即修改为 `numpy.max([feature_map[r, c, map_num], 0])`，这样才能正确返回两者中的最大值。","https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN\u002Fissues\u002F4",{"id":137,"question_zh":138,"answer_zh":139,"source_url":140},20390,"池化层（Pooling）输出尺寸计算错误或功能异常如何修复？","池化层输出尺寸计算公式有误。原代码 `(feature_map.shape[0]-size+1)\u002Fstride` 会导致尺寸偏差。正确的初始化代码应为：`pool_out = numpy.zeros((numpy.uint16((feature_map.shape[0]-size)\u002Fstride+1), numpy.uint16((feature_map.shape[1]-size)\u002Fstride+1), feature_map.shape[-1]))`。请确保分子中减去 size 后直接除以 stride 再加 1。","https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN\u002Fissues\u002F5",{"id":142,"question_zh":143,"answer_zh":144,"source_url":145},20391,"卷积函数中图像通道数与滤波器深度不匹配的检查逻辑有何缺陷？","原有的检查逻辑在图像维度大于 2 但滤波器维度不匹配时可能失效。建议增加维度数量的一致性检查。在检查通道数之前，先添加判断：`if len(img.shape) != len(conv_filter.shape) - 1`，如果维度数量不匹配（例如图像是 3 维而滤波器不是 4 维），则直接报错退出，确保后续通道数比较逻辑的有效性。","https:\u002F\u002Fgithub.com\u002Fahmedfgad\u002FNumPyCNN\u002Fissues\u002F8",[]]