[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-maxpumperla--hyperas":3,"tool-maxpumperla--hyperas":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 真正成长为懂上",151918,2,"2026-04-12T11:33:05",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":77,"owner_email":78,"owner_twitter":72,"owner_website":79,"owner_url":80,"languages":81,"stars":90,"forks":91,"last_commit_at":92,"license":93,"difficulty_score":32,"env_os":94,"env_gpu":94,"env_ram":94,"env_deps":95,"category_tags":102,"github_topics":103,"view_count":32,"oss_zip_url":75,"oss_zip_packed_at":75,"status":17,"created_at":105,"updated_at":106,"faqs":107,"releases":137},6903,"maxpumperla\u002Fhyperas","hyperas","Keras + Hyperopt: A very simple wrapper for convenient hyperparameter optimization","Hyperas 是一款专为 Keras 深度学习框架设计的超参数优化辅助工具。它巧妙地将强大的 Hyperopt 优化算法与用户熟悉的 Keras 建模流程结合在一起，旨在解决传统超参数调优过程中代码复杂、学习成本高的问题。\n\n在使用 Hyperas 之前，开发者通常需要专门学习 Hyperopt 的特定语法来定义搜索空间，这往往打断了原本流畅的建模思路。Hyperas 通过独特的“模板标记”技术解决了这一痛点：用户只需在标准的 Keras 模型代码中，用双花括号 `{{ }}` 包裹需要优化的参数（如 Dropout 概率、层节点数或激活函数），并指定分布类型，即可直接启动自动化搜索。这种设计让用户无需跳出舒适的编码环境，就能轻松实现从均匀分布采样到条件化网络结构构建等多种高级优化策略。\n\nHyperas 特别适合正在使用 Keras 进行模型开发的深度学习工程师、数据科学家及研究人员。无论是希望快速验证想法的初学者，还是需要精细调整模型性能的专业人士，都能利用它以极低的改造成本显著提升实验效率，将更多精力集中在模型架构创新而非繁琐的调参代码上。","# Hyperas [![Build Status](https:\u002F\u002Ftravis-ci.org\u002Fmaxpumperla\u002Fhyperas.svg?branch=master)](https:\u002F\u002Ftravis-ci.org\u002Fmaxpumperla\u002Fhyperas)  [![PyPI version](https:\u002F\u002Fbadge.fury.io\u002Fpy\u002Fhyperas.svg)](https:\u002F\u002Fbadge.fury.io\u002Fpy\u002Fhyperas)\nHyperas brings fast experimentation with Keras and hyperparameter optimization with Hyperopt together.\nIt lets you use the power of hyperopt without having to learn the syntax of it.\nInstead, just define your keras model as you are used to, but use a simple template notation to define hyper-parameter ranges to tune.\n\n## Installation\n```python\npip install hyperas\n```\n\n## Quick start\n\nAssume you have data generated as such\n\n```python\ndef data():\n    x_train = np.zeros(100)\n    x_test = np.zeros(100)\n    y_train = np.zeros(100)\n    y_test = np.zeros(100)\n    return x_train, y_train, x_test, y_test\n```\n\nand an existing keras model like the following\n\n```python\ndef create_model(x_train, y_train, x_test, y_test):\n    model = Sequential()\n    model.add(Dense(512, input_shape=(784,)))\n    model.add(Activation('relu'))\n    model.add(Dropout(0.2))\n    model.add(Dense(512))\n    model.add(Activation('relu'))\n    model.add(Dropout(0.2))\n    model.add(Dense(10))\n    model.add(Activation('softmax'))\n\n    # ... model fitting\n\n    return model\n```\n\n\nTo do hyper-parameter optimization on this model,\njust wrap the parameters you want to optimize into double curly brackets\nand choose a distribution over which to run the algorithm.\n\nIn the above example, let's say we want to optimize\nfor the best dropout probability in both dropout layers.\nChoosing a uniform distribution over the interval ```[0,1]```,\nthis translates into the following definition.\nNote that before returning the model, to optimize,\nwe also have to define which evaluation metric of the model is important to us.\nFor example, in the following, we optimize for accuracy.\n\n**Note**: In the following code we use `'loss': -accuracy`, i.e. the negative of accuracy. That's because under the hood `hyperopt` will always minimize whatever metric you provide. If instead you want to actually want to minimize a metric, say MSE or another loss function, you keep a positive sign (e.g. `'loss': mse`).\n\n\n```python\nfrom hyperas.distributions import uniform\n\ndef create_model(x_train, y_train, x_test, y_test):\n    model = Sequential()\n    model.add(Dense(512, input_shape=(784,)))\n    model.add(Activation('relu'))\n    model.add(Dropout({{uniform(0, 1)}}))\n    model.add(Dense(512))\n    model.add(Activation('relu'))\n    model.add(Dropout({{uniform(0, 1)}}))\n    model.add(Dense(10))\n    model.add(Activation('softmax'))\n\n    # ... model fitting\n\n    score = model.evaluate(x_test, y_test, verbose=0)\n    accuracy = score[1]\n    return {'loss': -accuracy, 'status': STATUS_OK, 'model': model}\n```\n\nThe last step is to actually run the optimization, which is done as follows:\n\n```python\nbest_run = optim.minimize(model=create_model,\n                          data=data,\n                          algo=tpe.suggest,\n                          max_evals=10,\n                          trials=Trials())\n```\nIn this example we use at most 10 evaluation runs and the TPE algorithm from hyperopt for optimization.\n\nCheck the \"complete example\" below for more details.\n\n\n## Complete example\n**Note:** It is important to wrap your data and model into functions as shown below, and then pass them as parameters to the minimizer. ```data()``` returns the data the ```create_model()``` needs. An extended version of the above example in one script reads as follows. This example shows many potential use cases of hyperas, including:\n- Varying dropout probabilities, sampling from a uniform distribution\n- Different layer output sizes\n- Different optimization algorithms to use\n- Varying choices of activation functions\n- Conditionally adding layers depending on a choice\n- Swapping whole sets of layers\n\n\n```python\nfrom __future__ import print_function\nimport numpy as np\n\nfrom hyperopt import Trials, STATUS_OK, tpe\nfrom keras.datasets import mnist\nfrom keras.layers.core import Dense, Dropout, Activation\nfrom keras.models import Sequential\nfrom keras.utils import np_utils\n\nfrom hyperas import optim\nfrom hyperas.distributions import choice, uniform\n\n\ndef data():\n    \"\"\"\n    Data providing function:\n\n    This function is separated from create_model() so that hyperopt\n    won't reload data for each evaluation run.\n    \"\"\"\n    (x_train, y_train), (x_test, y_test) = mnist.load_data()\n    x_train = x_train.reshape(60000, 784)\n    x_test = x_test.reshape(10000, 784)\n    x_train = x_train.astype('float32')\n    x_test = x_test.astype('float32')\n    x_train \u002F= 255\n    x_test \u002F= 255\n    nb_classes = 10\n    y_train = np_utils.to_categorical(y_train, nb_classes)\n    y_test = np_utils.to_categorical(y_test, nb_classes)\n    return x_train, y_train, x_test, y_test\n\n\ndef create_model(x_train, y_train, x_test, y_test):\n    \"\"\"\n    Model providing function:\n\n    Create Keras model with double curly brackets dropped-in as needed.\n    Return value has to be a valid python dictionary with two customary keys:\n        - loss: Specify a numeric evaluation metric to be minimized\n        - status: Just use STATUS_OK and see hyperopt documentation if not feasible\n    The last one is optional, though recommended, namely:\n        - model: specify the model just created so that we can later use it again.\n    \"\"\"\n    model = Sequential()\n    model.add(Dense(512, input_shape=(784,)))\n    model.add(Activation('relu'))\n    model.add(Dropout({{uniform(0, 1)}}))\n    model.add(Dense({{choice([256, 512, 1024])}}))\n    model.add(Activation({{choice(['relu', 'sigmoid'])}}))\n    model.add(Dropout({{uniform(0, 1)}}))\n\n    # If we choose 'four', add an additional fourth layer\n    if {{choice(['three', 'four'])}} == 'four':\n        model.add(Dense(100))\n\n        # We can also choose between complete sets of layers\n\n        model.add({{choice([Dropout(0.5), Activation('linear')])}})\n        model.add(Activation('relu'))\n\n    model.add(Dense(10))\n    model.add(Activation('softmax'))\n\n    model.compile(loss='categorical_crossentropy', metrics=['accuracy'],\n                  optimizer={{choice(['rmsprop', 'adam', 'sgd'])}})\n\n    result = model.fit(x_train, y_train,\n              batch_size={{choice([64, 128])}},\n              epochs=2,\n              verbose=2,\n              validation_split=0.1)\n    #get the highest validation accuracy of the training epochs\n    validation_acc = np.amax(result.history['val_acc']) \n    print('Best validation acc of epoch:', validation_acc)\n    return {'loss': -validation_acc, 'status': STATUS_OK, 'model': model}\n\n\nif __name__ == '__main__':\n    best_run, best_model = optim.minimize(model=create_model,\n                                          data=data,\n                                          algo=tpe.suggest,\n                                          max_evals=5,\n                                          trials=Trials())\n    X_train, Y_train, X_test, Y_test = data()\n    print(\"Evalutation of best performing model:\")\n    print(best_model.evaluate(X_test, Y_test))\n    print(\"Best performing model chosen hyper-parameters:\")\n    print(best_run)\n```\n\n## FAQ\n\nHere is a list of a few popular errors\n\n### `TypeError: require string label`\n\nYou're probably trying to execute the model creation code, with the templates, directly in python.\nThat fails simply because python cannot run the templating in the braces, e.g. `{{uniform..}}`.\nThe `def create_model(...)` function is in fact not a valid python function anymore.\n\nYou need to wrap your code in a `def create_model(...): ...` function,\nand then call it from `optim.minimize(model=create_model,...` like in the example.\n\nThe reason for this is that hyperas works by doing template replacement\nof everything in the `{{...}}` into a separate temporary file,\nand then running the model with the replaced braces (think jinja templating).\n\nThis is the basis of how hyperas simplifies usage of hyperopt by being a \"very simple wrapper\".\n\n\n### `TypeError: 'generator' object is not subscriptable`\n\nThis is currently a [known issue](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F125).\n\nJust `pip install networkx==1.11`\n\n\n### `NameError: global name 'X_train' is not defined`\n\nMaybe you forgot to return the `x_train` argument in the `def create_model(x_train...)` call\nfrom the `def data(): ...` function.\n\nYou are not restricted to the same list of arguments as in the example.\nAny arguments you return from `data()` will be passed to `create_model()`\n\n### notebook adjustment\n\nIf you find error like [\"No such file or directory\"](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F83) or [OSError, Err22](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F149), you may need add `notebook_name='simple_notebook'`(assume your current notebook name is `simple_notebook`) in `optim.minimize` function like this:\n\n```python\nbest_run, best_model = optim.minimize(model=model,\n                                      data=data,\n                                      algo=tpe.suggest,\n                                      max_evals=5,\n                                      trials=Trials(),\n                                      notebook_name='simple_notebook')\n```\n\n### How does hyperas work?\n\nAll we do is parse the `data` and `model` templates and translate them into proper `hyperopt` by reconstructing the `space` object that's then passed to `fmin`. Most of the relevant code is found in [optim.py](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fblob\u002Fmaster\u002Fhyperas\u002Foptim.py) and [utils.py](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fblob\u002Fmaster\u002Fhyperas\u002Futils.py).\n\n### How to read the output of a hyperas model?\n\nHyperas translates your script into `hyperopt` compliant code, see [here](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F140) for some guidance on how to interpret the result.\n\n### How to pass arguments to data?\n\nSuppose you want your data function take an argument, specify it like this using positional arguments only (not keyword arguments):\n\n```python\nimport pickle\ndef data(fname):\n    with open(fname,'rb') as fh:\n        return pickle.load(fh)\n```\nNote that your arguments must be implemented such that `repr` can show them in their entirety (such as strings and numbers).\nIf you want more complex objects, use the passed arguments to build them inside the `data` function.\n\nAnd when you run your trials, pass a tuple of arguments to be substituted in as `data_args`:\n\n```python\nbest_run, best_model = optim.minimize(\n    model=model,\n    data=data,\n    algo=tpe.suggest,\n    max_evals=64,\n    trials=Trials(),\n    data_args=('my_file.pkl',)\n)\n``` \n\n### What if I need more flexibility loading data and adapting my model?\n\nHyperas is a convenience wrapper around Hyperopt that has some limitations. If it's not _convenient_ to use in your situation, simply don't use it -- and choose Hyperopt instead. All you can do with Hyperas you can also do with Hyperopt, it's just a different way of defining your model. If you want to squeeze some flexibility out of Hyperas anyway, take a look [here](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F141).\n\n### Running hyperas in parallel?\n\nYou can use hyperas to run multiple models in parallel with the use of mongodb (which you'll need to install and setup users for).\n Here's a short example using MNIST:\n\n1. Copy and modify [`examples\u002Fmnist_distributed.py`](examples\u002Fmnist_distributed.py) (bump up `max_evals` if you like):\n2. Run `python mnist_distributed.py`. It will create a `temp_model.py` file. Copy this file to any machines that will be evaluating models.\n     It will then begin waiting for evaluation results\n3. On your other machines (make sure they have a python installed with all your dependencies, ideally with the same versions) run:\n    ```bash\n    export PYTHONPATH=\u002Fpath\u002Fto\u002Ftemp_model.py\n    hyperopt-mongo-worker --exp-key='mnist_test' --mongo='mongo:\u002F\u002Fusername:pass@mongodb.host:27017\u002Fjobs'\n    ```\n4. Once `max_evals` have been completed, you should get an output with your best model. You can also look through \n    your mongodb and examine the results, to get the best model out and run it, do:\n    \n    ```python\n    from pymongo import MongoClient\n    from keras.models import load_model\n    import tempfile\n    c = MongoClient('mongodb:\u002F\u002Fusername:pass@mongodb.host:27017\u002Fjobs')\n    best_model = c['jobs']['jobs'].find_one({'exp_key': 'mnist_test'}, sort=[('result.loss', -1)])\n    temp_name = tempfile.gettempdir()+'\u002F'+next(tempfile._get_candidate_names()) + '.h5'\n    with open(temp_name, 'wb') as outfile:\n        outfile.write(best_model['result']['model_serial'])\n    model = load_model(temp_name)\n    ```\n","# Hyperas [![构建状态](https:\u002F\u002Ftravis-ci.org\u002Fmaxpumperla\u002Fhyperas.svg?branch=master)](https:\u002F\u002Ftravis-ci.org\u002Fmaxpumperla\u002Fhyperas)  [![PyPI版本](https:\u002F\u002Fbadge.fury.io\u002Fpy\u002Fhyperas.svg)](https:\u002F\u002Fbadge.fury.io\u002Fpy\u002Fhyperas)\nHyperas 将 Keras 的快速实验与 Hyperopt 的超参数优化结合在一起。\n它使你无需学习 Hyperopt 的语法，就能充分利用 Hyperopt 的强大功能。\n相反，你可以像往常一样定义你的 Keras 模型，只需使用简单的模板语法来指定要调优的超参数范围。\n\n## 安装\n```python\npip install hyperas\n```\n\n## 快速入门\n\n假设你已经生成了如下数据：\n\n```python\ndef data():\n    x_train = np.zeros(100)\n    x_test = np.zeros(100)\n    y_train = np.zeros(100)\n    y_test = np.zeros(100)\n    return x_train, y_train, x_test, y_test\n```\n\n并且有一个现有的 Keras 模型，如下所示：\n\n```python\ndef create_model(x_train, y_train, x_test, y_test):\n    model = Sequential()\n    model.add(Dense(512, input_shape=(784,)))\n    model.add(Activation('relu'))\n    model.add(Dropout(0.2))\n    model.add(Dense(512))\n    model.add(Activation('relu'))\n    model.add(Dropout(0.2))\n    model.add(Dense(10))\n    model.add(Activation('softmax'))\n\n    # ... 模型训练\n\n    return model\n```\n\n\n为了对这个模型进行超参数优化，\n只需将你想优化的参数用双大括号括起来，\n并选择一个用于运行算法的分布。\n\n在上面的例子中，假设我们想优化两个 Dropout 层的最佳 Dropout 概率。\n如果我们选择在区间 `[0,1]` 上的均匀分布，\n那么对应的定义如下。请注意，在返回模型之前，为了进行优化，\n我们还需要定义对我们来说重要的模型评估指标。\n例如，在下面的例子中，我们以准确率作为优化目标。\n\n**注意**：在下面的代码中，我们使用 `'loss': -accuracy`，即准确率的负值。这是因为 Hyperopt 在底层总是会最小化你提供的任何指标。如果你希望真正最小化某个指标，比如均方误差或其他损失函数，则应保持正号（例如 `'loss': mse`）。\n\n```python\nfrom hyperas.distributions import uniform\n\ndef create_model(x_train, y_train, x_test, y_test):\n    model = Sequential()\n    model.add(Dense(512, input_shape=(784,)))\n    model.add(Activation('relu'))\n    model.add(Dropout({{uniform(0, 1)}}))\n    model.add(Dense(512))\n    model.add(Activation('relu'))\n    model.add(Dropout({{uniform(0, 1)}}))\n    model.add(Dense(10))\n    model.add(Activation('softmax'))\n\n    # ... 模型训练\n\n    score = model.evaluate(x_test, y_test, verbose=0)\n    accuracy = score[1]\n    return {'loss': -accuracy, 'status': STATUS_OK, 'model': model}\n```\n\n最后一步是实际运行优化，具体操作如下：\n\n```python\nbest_run = optim.minimize(model=create_model,\n                          data=data,\n                          algo=tpe.suggest,\n                          max_evals=10,\n                          trials=Trials())\n```\n在这个例子中，我们最多进行 10 次评估，并使用 Hyperopt 中的 TPE 算法来进行优化。\n\n更多详细信息，请参阅下方的“完整示例”。\n\n## 完整示例\n**注意:** 重要的是将你的数据和模型封装到函数中，如下面所示，然后将它们作为参数传递给优化器。```data()``` 返回 ```create_model()``` 所需的数据。上述示例的扩展版本在一个脚本中如下所示。这个示例展示了 hyperas 的许多潜在用法，包括：\n- 在均匀分布中采样以调整 dropout 概率\n- 不同的层输出大小\n- 不同的优化算法\n- 不同的激活函数选择\n- 根据选择有条件地添加层\n- 替换整组层\n\n\n```python\nfrom __future__ import print_function\nimport numpy as np\n\nfrom hyperopt import Trials, STATUS_OK, tpe\nfrom keras.datasets import mnist\nfrom keras.layers.core import Dense, Dropout, Activation\nfrom keras.models import Sequential\nfrom keras.utils import np_utils\n\nfrom hyperas import optim\nfrom hyperas.distributions import choice, uniform\n\n\ndef data():\n    \"\"\"\n    数据提供函数：\n\n    将此函数与 create_model() 分离，以便 hyperopt 不会在每次评估时重新加载数据。\n    \"\"\"\n    (x_train, y_train), (x_test, y_test) = mnist.load_data()\n    x_train = x_train.reshape(60000, 784)\n    x_test = x_test.reshape(10000, 784)\n    x_train = x_train.astype('float32')\n    x_test = x_test.astype('float32')\n    x_train \u002F= 255\n    x_test \u002F= 255\n    nb_classes = 10\n    y_train = np_utils.to_categorical(y_train, nb_classes)\n    y_test = np_utils.to_categorical(y_test, nb_classes)\n    return x_train, y_train, x_test, y_test\n\n\ndef create_model(x_train, y_train, x_test, y_test):\n    \"\"\"\n    模型提供函数：\n\n    创建 Keras 模型，其中双大括号根据需要被替换。返回值必须是一个有效的 Python 字典，包含两个常用键：\n        - loss: 指定要最小化的数值评估指标\n        - status: 如果可行，只需使用 STATUS_OK；否则请参阅 hyperopt 文档\n    最后一个键是可选的，但建议包含：\n        - model: 指定刚刚创建的模型，以便我们稍后可以再次使用它。\n    \"\"\"\n    model = Sequential()\n    model.add(Dense(512, input_shape=(784,)))\n    model.add(Activation('relu'))\n    model.add(Dropout({{uniform(0, 1)}}))\n    model.add(Dense({{choice([256, 512, 1024])}}))\n    model.add(Activation({{choice(['relu', 'sigmoid'])}}))\n    model.add(Dropout({{uniform(0, 1)}}))\n\n    # 如果我们选择 'four'，则添加额外的第四层\n    if {{choice(['three', 'four'])}} == 'four':\n        model.add(Dense(100))\n\n        # 我们也可以在整组层之间进行选择\n\n        model.add({{choice([Dropout(0.5), Activation('linear')])}})\n        model.add(Activation('relu'))\n\n    model.add(Dense(10))\n    model.add(Activation('softmax'))\n\n    model.compile(loss='categorical_crossentropy', metrics=['accuracy'],\n                  optimizer={{choice(['rmsprop', 'adam', 'sgd'])}})\n\n    result = model.fit(x_train, y_train,\n              batch_size={{choice([64, 128])}},\n              epochs=2,\n              verbose=2,\n              validation_split=0.1)\n    # 获取训练期间最高的验证准确率\n    validation_acc = np.amax(result.history['val_acc']) \n    print('最佳验证准确率:', validation_acc)\n    return {'loss': -validation_acc, 'status': STATUS_OK, 'model': model}\n\n\nif __name__ == '__main__':\n    best_run, best_model = optim.minimize(model=create_model,\n                                          data=data,\n                                          algo=tpe.suggest,\n                                          max_evals=5,\n                                          trials=Trials())\n    X_train, Y_train, X_test, Y_test = data()\n    print(\"最佳模型评估结果：\")\n    print(best_model.evaluate(X_test, Y_test))\n    print(\"最佳模型所选超参数：\")\n    print(best_run)\n```\n\n## 常见问题解答\n\n以下是一些常见错误的列表\n\n### `TypeError: 需要字符串标签`\n\n你可能正在尝试直接在 Python 中执行带有模板的模型创建代码。这会失败，因为 Python 无法运行大括号中的模板语法，例如 `{{uniform..}}`。实际上，`def create_model(...)` 函数已经不再是有效的 Python 函数了。\n\n你需要将代码包裹在 `def create_model(...): ...` 函数中，然后像示例中那样从 `optim.minimize(model=create_model,...` 调用它。\n\n原因是 hyperas 通过将 `{{...}}` 中的所有内容替换为一个单独的临时文件来工作，然后运行替换后的模型（类似于 jinja 模板）。这就是 hyperas 作为“非常简单的封装”简化 hyperopt 使用方式的基础。\n\n\n### `TypeError: 'generator' 对象不可下标访问`\n\n这是一个[已知问题](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F125)。\n\n只需运行 `pip install networkx==1.11` 即可解决。\n\n\n### `NameError: 全局名称 'X_train' 未定义`\n\n也许你在 `def create_model(x_train...)` 调用中忘记从 `def data(): ...` 函数返回 `x_train` 参数了。\n\n你并不局限于示例中的相同参数列表。任何从 `data()` 返回的参数都会传递给 `create_model()`。\n\n### 笔记本调整\n\n如果你遇到类似 [\"没有这样的文件或目录\"](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F83) 或 [OSError, Err22](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F149) 的错误，你可能需要在 `optim.minimize` 函数中添加 `notebook_name='simple_notebook'`（假设你当前的笔记本名称是 `simple_notebook`），如下所示：\n\n```python\nbest_run, best_model = optim.minimize(model=model,\n                                      data=data,\n                                      algo=tpe.suggest,\n                                      max_evals=5,\n                                      trials=Trials(),\n                                      notebook_name='simple_notebook')\n```\n\n### hyperas 是如何工作的？\n\n我们所做的就是解析 `data` 和 `model` 模板，并将它们转换为符合 `hyperopt` 格式的代码，通过重建 `space` 对象将其传递给 `fmin`。相关代码主要位于 [optim.py](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fblob\u002Fmaster\u002Fhyperas\u002Foptim.py) 和 [utils.py](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fblob\u002Fmaster\u002Fhyperas\u002Futils.py) 中。\n\n### 如何解读 hyperas 模型的输出？\n\nhyperas 会将你的脚本转换为符合 `hyperopt` 标准的代码，有关如何解释结果的指导，请参阅 [这里](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F140)。\n\n### 如何向数据函数传递参数？\n\n假设你希望你的数据函数接受一个参数，可以仅使用位置参数（而非关键字参数）来定义它：\n\n```python\nimport pickle\ndef data(fname):\n    with open(fname, 'rb') as fh:\n        return pickle.load(fh)\n```\n\n请注意，你的参数必须能够被 `repr` 完整地表示出来（例如字符串和数字）。如果需要更复杂的对象，可以在 `data` 函数内部利用传入的参数来构建它们。\n\n在运行试验时，将要替换的参数以元组形式传入 `data_args`：\n\n```python\nbest_run, best_model = optim.minimize(\n    model=model,\n    data=data,\n    algo=tpe.suggest,\n    max_evals=64,\n    trials=Trials(),\n    data_args=('my_file.pkl',)\n)\n``` \n\n### 如果我需要更灵活地加载数据并调整模型怎么办？\n\nHyperas 是 Hyperopt 的一个便捷封装，但它也有一些局限性。如果你觉得它在当前场景下并不“便捷”，那就不要使用它，直接选择 Hyperopt 即可。使用 Hyperas 能做到的一切，用 Hyperopt 也能实现，只是定义模型的方式有所不同。如果你想从 Hyperas 中榨取更多灵活性，可以查看 [这里](https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F141)。\n\n### 如何并行运行 Hyperas？\n\n你可以借助 MongoDB（需要先安装并配置用户）来使用 Hyperas 并行运行多个模型。以下是一个基于 MNIST 数据集的简短示例：\n\n1. 复制并修改 [`examples\u002Fmnist_distributed.py`](examples\u002Fmnist_distributed.py) 文件（如果需要，可以适当增加 `max_evals` 值）：\n2. 运行 `python mnist_distributed.py`。该脚本会生成一个 `temp_model.py` 文件，并将其复制到所有参与模型评估的机器上。随后，主程序会开始等待评估结果。\n3. 在其他机器上（确保已安装 Python 及所有依赖包，最好版本一致），执行以下命令：\n    ```bash\n    export PYTHONPATH=\u002Fpath\u002Fto\u002Ftemp_model.py\n    hyperopt-mongo-worker --exp-key='mnist_test' --mongo='mongo:\u002F\u002Fusername:pass@mongodb.host:27017\u002Fjobs'\n    ```\n4. 当达到 `max_evals` 次评估后，你应该会得到最佳模型的输出。此外，你也可以通过 MongoDB 查看所有结果，从中找出最佳模型并运行它，具体步骤如下：\n\n    ```python\n    from pymongo import MongoClient\n    from keras.models import load_model\n    import tempfile\n    c = MongoClient('mongodb:\u002F\u002Fusername:pass@mongodb.host:27017\u002Fjobs')\n    best_model = c['jobs']['jobs'].find_one({'exp_key': 'mnist_test'}, sort=[('result.loss', -1)])\n    temp_name = tempfile.gettempdir() + '\u002F' + next(tempfile._get_candidate_names()) + '.h5'\n    with open(temp_name, 'wb') as outfile:\n        outfile.write(best_model['result']['model_serial'])\n    model = load_model(temp_name)\n    ```","# Hyperas 快速上手指南\n\nHyperas 是一个将 Keras 深度学习框架与 Hyperopt 超参数优化库结合的轻量级工具。它允许你使用简单的模板语法（双大括号）在标准的 Keras 模型代码中定义超参数搜索空间，无需学习复杂的 Hyperopt 语法即可快速进行模型调优。\n\n## 环境准备\n\n*   **操作系统**：Linux, macOS 或 Windows\n*   **Python 版本**：建议 Python 3.6+\n*   **前置依赖**：\n    *   `Keras` (支持 TensorFlow 后端)\n    *   `Hyperopt`\n    *   `NumPy`\n    *   `NetworkX` (注意：若遇到 `'generator' object is not subscriptable` 错误，需安装特定版本 `networkx==1.11`)\n\n## 安装步骤\n\n推荐使用 pip 进行安装。国内用户可指定清华或阿里镜像源以加速下载。\n\n```bash\n# 使用默认源安装\npip install hyperas\n\n# 或使用国内镜像源加速安装（推荐）\npip install hyperas -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n## 基本使用\n\n使用 Hyperas 只需三个步骤：定义数据加载函数、定义带模板语法的模型函数、运行优化器。\n\n### 1. 定义数据与模型\n\n在 `create_model` 函数中，使用 `{{distribution(...)}}` 语法包裹需要优化的超参数。\n\n```python\nimport numpy as np\nfrom keras.models import Sequential\nfrom keras.layers import Dense, Activation, Dropout\nfrom keras.utils import np_utils\nfrom keras.datasets import mnist\n\nfrom hyperas import optim\nfrom hyperas.distributions import choice, uniform\nfrom hyperopt import Trials, STATUS_OK, tpe\n\ndef data():\n    \"\"\"\n    数据加载函数\n    返回的数据将自动传递给 create_model 函数\n    \"\"\"\n    (x_train, y_train), (x_test, y_test) = mnist.load_data()\n    x_train = x_train.reshape(60000, 784)\n    x_test = x_test.reshape(10000, 784)\n    x_train = x_train.astype('float32')\n    x_test = x_test.astype('float32')\n    x_train \u002F= 255\n    x_test \u002F= 255\n    \n    nb_classes = 10\n    y_train = np_utils.to_categorical(y_train, nb_classes)\n    y_test = np_utils.to_categorical(y_test, nb_classes)\n    \n    return x_train, y_train, x_test, y_test\n\ndef create_model(x_train, y_train, x_test, y_test):\n    \"\"\"\n    模型构建函数\n    使用 {{ }} 定义超参数搜索空间\n    \"\"\"\n    model = Sequential()\n    model.add(Dense(512, input_shape=(784,)))\n    model.add(Activation('relu'))\n    \n    # 优化 Dropout 概率，范围 0 到 1\n    model.add(Dropout({{uniform(0, 1)}}))\n    \n    model.add(Dense({{choice([256, 512, 1024])}})) # 优化神经元数量\n    model.add(Activation({{choice(['relu', 'sigmoid'])}})) # 优化激活函数\n    \n    model.add(Dropout({{uniform(0, 1)}}))\n    model.add(Dense(10))\n    model.add(Activation('softmax'))\n\n    # 优化优化器选择\n    model.compile(loss='categorical_crossentropy', metrics=['accuracy'],\n                  optimizer={{choice(['rmsprop', 'adam', 'sgd'])}})\n\n    result = model.fit(x_train, y_train,\n              batch_size={{choice([64, 128])}}, # 优化 Batch Size\n              epochs=2,\n              verbose=0,\n              validation_split=0.1)\n    \n    # 获取验证集最高准确率\n    validation_acc = np.amax(result.history['val_acc'])\n    \n    # 注意：hyperopt 默认最小化目标函数，因此返回负的准确率\n    return {'loss': -validation_acc, 'status': STATUS_OK, 'model': model}\n\nif __name__ == '__main__':\n    # 执行超参数优化\n    best_run, best_model = optim.minimize(model=create_model,\n                                          data=data,\n                                          algo=tpe.suggest,\n                                          max_evals=5, # 最大评估次数\n                                          trials=Trials())\n    \n    print(\"最佳超参数组合:\")\n    print(best_run)\n```\n\n### 2. 运行优化\n\n直接运行上述脚本即可。Hyperas 会自动解析模板，生成临时文件并调用 Hyperopt 进行搜索。\n\n*   **关键参数说明**：\n    *   `model`: 包含模板语法的模型构建函数。\n    *   `data`: 数据加载函数。\n    *   `algo`: 优化算法，常用 `tpe.suggest`。\n    *   `max_evals`: 尝试的超参数组合数量。\n    *   `trials`: 用于存储实验结果的对象。\n\n### 3. 查看结果\n\n程序运行结束后，`best_run` 字典将包含最优的超参数配置，`best_model` 则是使用该配置训练出的最佳 Keras 模型对象，可直接用于评估或预测。","某电商数据团队正在构建用户流失预测模型，急需通过调整神经网络结构来提升准确率。\n\n### 没有 hyperas 时\n- **手动试错效率低**：工程师需反复修改代码中的 Dropout 比率或层数，每次调整都要重新运行脚本，耗时费力。\n- **搜索策略盲目**：缺乏系统性的参数搜索算法，只能凭经验猜测参数范围，极易错过全局最优解。\n- **代码耦合度高**：超参数搜索逻辑与 Keras 模型定义混杂在一起，导致代码冗长且难以维护。\n- **学习门槛较高**：若要使用强大的 Hyperopt 库，必须专门学习其复杂的语法和回调机制，增加了开发成本。\n\n### 使用 hyperas 后\n- **模板化定义参数**：只需在 Keras 代码中用双花括号 `{{uniform(0, 1)}}` 标记待优化参数，即可自动启动搜索，无需重写模型逻辑。\n- **智能算法加持**：直接调用 TPE 等先进算法自动探索参数空间，用更少的实验次数找到比人工调优更佳的模型配置。\n- **关注点分离**：将数据加载、模型构建与优化执行清晰分离，代码结构简洁，便于团队协作和后续迭代。\n- **零语法负担**：完全复用熟悉的 Keras 编写习惯，无需学习 Hyperopt 底层语法，让数据科学家专注于业务逻辑。\n\nhyperas 通过将复杂的超参数优化过程简化为几行模板代码，让开发者能以最低成本获得显著的模型性能提升。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmaxpumperla_hyperas_3c372b3f.png","maxpumperla","Max Pumperla","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fmaxpumperla_e6f90a7c.png",null,"Manyfold Labs","remote","max.pumperla@googlemail.com","https:\u002F\u002Fmaxpumperla.com","https:\u002F\u002Fgithub.com\u002Fmaxpumperla",[82,86],{"name":83,"color":84,"percentage":85},"Python","#3572A5",91.3,{"name":87,"color":88,"percentage":89},"TeX","#3D6117",8.7,2177,317,"2026-04-10T16:10:37","MIT","未说明",{"notes":96,"python":94,"dependencies":97},"该工具是 Keras 和 Hyperopt 的封装器，通过模板语法（双花括号）定义超参数范围。若在 Jupyter Notebook 中运行遇到文件找不到错误，需在 optim.minimize 函数中添加 notebook_name 参数。若遇到 'generator object is not subscriptable' 错误，需将 networkx 版本降级为 1.11。支持通过 MongoDB 进行分布式并行训练。",[98,99,100,101],"keras","hyperopt","numpy","networkx==1.11 (用于解决特定已知问题)",[14],[99,98,104],"hyperparameter-optimization","2026-03-27T02:49:30.150509","2026-04-13T00:21:48.788348",[108,113,118,123,128,133],{"id":109,"question_zh":110,"answer_zh":111,"source_url":112},31104,"运行示例代码时遇到 'TypeError: require string label' 错误怎么办？","该错误通常与环境配置或代码执行方式有关。建议按照以下步骤重新设置环境并运行：\n1. 克隆仓库：git clone https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\n2. 进入目录并创建虚拟环境：cd hyperas && python3 -m venv .\u002Fvenv\n3. 激活环境：source venv\u002Fbin\u002Factivate (Windows 使用 venv\\Scripts\\activate)\n4. 安装依赖：pip install -e . && pip install tensorflow\n5. 进入 examples 目录，根据需要修改 simple.py (例如将 epochs 改为 1)\n6. 运行脚本：python simple.py\n注意：请确保使用 Python 3 环境，避免在 Jupyter Notebook 中直接运行包含模板语法的代码行，最好作为完整脚本执行。","https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F106",{"id":114,"question_zh":115,"answer_zh":116,"source_url":117},31105,"遇到 'object of type NoneType has no len()' 或 'IndentationError' 错误如何解决？","这通常是因为 data() 函数定义后的缩进问题导致的。Hyperas 需要解析源代码，如果 def data(): 函数下方没有正确缩进的代码块，或者缩进不一致，就会引发此类错误。\n解决方案：\n检查你的 data() 函数，确保其内部代码有正确的缩进。例如：\ndef data():\n    # 确保下一行有缩进\n    X_train, Y_train = load_data()\n    return X_train, Y_train\n不要留空块，也不要混用 Tab 和空格。","https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F57",{"id":119,"question_zh":120,"answer_zh":121,"source_url":122},31106,"在 Spyder IDE 中运行时出现 'NameError: name autoload_pylab_o is not defined' 错误？","这是由于 Spyder 的 IPython 内核配置与 Hyperas 生成的临时文件冲突导致的。Hyperas 会生成临时 Python 文件进行优化，而 Spyder 的某些预加载变量在这些临时文件中未定义。\n解决方案：\n不要在 Spyder IDE 内部直接运行优化代码。请打开终端（CMD 或 Shell），直接通过命令行执行脚本：\npython your_script.py\n避免使用 IDE 的 \"Run file\" 功能，直接使用系统 Python 解释器运行可避开此问题。","https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F24",{"id":124,"question_zh":125,"answer_zh":126,"source_url":127},31107,"如何在非 Sequential 模型（如函数式 API 或多输入模型）中使用 Hyperas？","Hyperas 完全支持 Keras 的函数式 API 和非 Sequential 模型。你只需要在 model() 函数中正常构建模型即可。\n关键点：\n1. 确保 model() 函数返回一个字典，包含 'loss' 和 'status'，例如：return {'loss': -acc, 'status': STATUS_OK}\n2. 在定义层时使用双花括号语法 {{uniform(0, 1)}} 来包裹超参数。\n3. 对于多输入模型，确保 data() 函数返回的数据结构与模型输入匹配（例如列表或字典）。\n参考 Issue #185 中的 Siamese 网络案例，展示了如何在复杂架构中使用 choice 和 uniform 进行超参数搜索。","https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F1",{"id":129,"question_zh":130,"answer_zh":131,"source_url":132},31108,"如何在 Siamese 网络或复杂自定义架构中优化超参数？","在 Siamese 网络等复杂架构中，你可以像在普通模型中一样使用 Hyperas 的模板语法。\n具体做法：\n1. 在创建子网络（base network）或主模型时，直接在层参数中使用 {{choice([...])}} 或 {{uniform(min, max)}}。\n例如：Dense({{choice([512, 1024, 2048])}}, activation='relu')\n2. 确保整个模型构建过程包含在 model() 函数中，并且正确编译和拟合。\n3. 如果涉及随机种子，建议在函数内部固定种子以保证复现性。\n维护者建议可以将此类复杂案例整理为示例代码提交到项目的 examples 文件夹中，以便社区参考。","https:\u002F\u002Fgithub.com\u002Fmaxpumperla\u002Fhyperas\u002Fissues\u002F185",{"id":134,"question_zh":135,"answer_zh":136,"source_url":127},31109,"LSTM 模型报错 'Layer is not connected. Did you forget to set input_shape?' 是怎么回事？","这个错误通常发生在旧版本 Keras（如 0.3.2）中，当 LSTM 层没有正确接收输入形状时。\n解决方案：\n1. 升级 Keras 到较新版本，新版中 input_shape 的处理更加灵活。\n2. 如果必须使用旧版，请确保在添加 LSTM 层时明确指定 input_shape 或 input_dim。\n例如：model.add(LSTM(input_dim=388, output_dim=300, ...))\n3. 确保在使用 Hyperas 模板语法时，没有破坏模型的连接性。双花括号 {{...}} 内的内容会在预处理阶段被替换，请检查替换后的代码逻辑是否通顺。",[]]