[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-jedld--tensor_stream":3,"tool-jedld--tensor_stream":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 真正成长为懂上",159267,2,"2026-04-17T11:29:14",[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":67,"readme_en":68,"readme_zh":69,"quickstart_zh":70,"use_case_zh":71,"hero_image_url":72,"owner_login":73,"owner_name":74,"owner_avatar_url":75,"owner_bio":76,"owner_company":77,"owner_location":78,"owner_email":77,"owner_twitter":77,"owner_website":77,"owner_url":79,"languages":80,"stars":96,"forks":97,"last_commit_at":98,"license":99,"difficulty_score":32,"env_os":100,"env_gpu":101,"env_ram":100,"env_deps":102,"category_tags":108,"github_topics":109,"view_count":32,"oss_zip_url":77,"oss_zip_packed_at":77,"status":17,"created_at":112,"updated_at":113,"faqs":114,"releases":140},8537,"jedld\u002Ftensor_stream","tensor_stream","A ground-up and standalone reimplementation of TensorFlow for ruby. Comes with a pure ruby and OpenCL opcode evaluator","TensorStream 是一个专为 Ruby 开发者打造的开源机器学习框架，旨在让 Ruby 社区也能轻松构建和运行复杂的机器学习模型。它从零开始重新实现了 TensorFlow 的核心功能，解决了以往 Ruby 在深度学习领域缺乏原生、高效工具支持的痛点，让用户无需依赖 Python 环境或复杂的 Docker 配置即可开展工作。\n\n该工具特别适合熟悉 Ruby 语言的软件工程师、数据科学家以及希望将 AI 模型直接集成到现有 Ruby 应用中的开发者。其核心亮点在于独特的“混合部署”架构：支持纯 Ruby 和 OpenCL 两种后端。用户可以利用 OpenCL 后端调用 GPU 进行高效的模型训练，随后将训练好的模型无缝切换至纯 Ruby 后端，在任何能运行 Ruby 的设备（包括 JRuby、TruffleRuby 等环境）上轻松部署推理，真正实现了“一次定义，随处运行”。\n\nTensorStream 高度兼容 TensorFlow 的操作逻辑，支持自动微分和自定义算子扩展，语法简洁直观。无论是进行线性回归实验，还是处理需要硬件加速的深度学习任务，TensorStream 都能","TensorStream 是一个专为 Ruby 开发者打造的开源机器学习框架，旨在让 Ruby 社区也能轻松构建和运行复杂的机器学习模型。它从零开始重新实现了 TensorFlow 的核心功能，解决了以往 Ruby 在深度学习领域缺乏原生、高效工具支持的痛点，让用户无需依赖 Python 环境或复杂的 Docker 配置即可开展工作。\n\n该工具特别适合熟悉 Ruby 语言的软件工程师、数据科学家以及希望将 AI 模型直接集成到现有 Ruby 应用中的开发者。其核心亮点在于独特的“混合部署”架构：支持纯 Ruby 和 OpenCL 两种后端。用户可以利用 OpenCL 后端调用 GPU 进行高效的模型训练，随后将训练好的模型无缝切换至纯 Ruby 后端，在任何能运行 Ruby 的设备（包括 JRuby、TruffleRuby 等环境）上轻松部署推理，真正实现了“一次定义，随处运行”。\n\nTensorStream 高度兼容 TensorFlow 的操作逻辑，支持自动微分和自定义算子扩展，语法简洁直观。无论是进行线性回归实验，还是处理需要硬件加速的深度学习任务，TensorStream 都能提供灵活且高效的解决方案，是 Ruby 生态中连接算法研究与工程落地的有力桥梁。","[![Gem Version](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Ftensor_stream.svg)](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Ftensor_stream)[![Gem Version](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Ftensor_stream-opencl.svg)](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Ftensor_stream-opencl)[![CircleCI](https:\u002F\u002Fcircleci.com\u002Fgh\u002Fjedld\u002Ftensor_stream.svg?style=svg)](https:\u002F\u002Fcircleci.com\u002Fgh\u002Fjedld\u002Ftensor_stream) [![Join the chat at https:\u002F\u002Fgitter.im\u002Ftensor_stream\u002FLobby](https:\u002F\u002Fbadges.gitter.im\u002Ftensor_stream\u002FLobby.svg)](https:\u002F\u002Fgitter.im\u002Ftensor_stream\u002FLobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\n# TensorStream\n\nTensorStream is an opensource framework for machine learning for ruby, its goal is to allow machine learning models to be easily built and run them in various hardware like GPUs and CPUs. It is heavily based on TensorFlow with the goal of being able to easily port its higher level libraries and model examples. As such it is also based on data flow graphs wherein you define computations and data flows between those computations in order to achieve the desired output.\n\nTensorStream is designed to support various backends with a Pure Ruby and OpenCL implementation. These implementations are designed to work together, you can perform training on an OpenCL implementation (where you have a GPU) and then run the resulting trained model on a Pure Ruby implementation where you can deploy anywhere that you can run ruby on. TensorStream has been tested to run on most ruby implementations like MRI, JRuby and TruffleRuby.\n\n## Goals & Features\n\n- Easy to use - Improve model readability\n- Replicates most of the commonly used low-level tensorflow ops (tf.add, tf.constant, tf.placeholder, tf.matmul, tf.sin etc...)\n- Supports auto-differentiation using formal derivation\n- Extensible - use your own opcode evaluator (OpenCL and Pure ruby currently supported)\n- wide support - Run on most ruby implementations as well as hardware acceleration on OpenCL supported hardware\n\n## Compatibility\n\nTensorStream comes with a pure ruby and OpenCL implementation out of the box. The pure ruby implementation\nis known to work with most ruby implementations including TruffleRuby, JRuby as well as jit enabled versions of mri (ruby-2.6.0).\n\nOpenCL is supported only on mri implementations of ruby. This can be enabled by adding OpenCL evaluator gem (Make sure you have OpenCL drivers installed correctly on your system):\n\n```Gemfile\ngem 'tensor_stream-opencl'\n```\n\nand then (without bundler)\n\n```ruby\nrequire 'tensor_stream\u002Fopencl'\n```\n\nOpenCL is basically a requirement for deep learning and image processing tasks as the ruby implementation is too slow even with jit speedups using latest ruby implementations.\n\nOpenCL kernels used by tensorstream can be found at tensor_stream\u002Flib\u002Fevaluator\u002Fopencl\u002Fkernels. These are non specific and should work with any device that supports OpenCL including intel GPUs and CPUs, as well as GPUs from Nvidia and AMD.\n\n## Installation\n\nInstallation is easy, no need to mess with docker, python, clang or other shennanigans, works with both mri and jruby out of the box.\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'tensor_stream'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install tensor_stream\n\n## Usage\n\nUsage is similar to how you would use TensorFlow except with ruby syntax.\nThere are also enhancements to the syntax to make it as consice as possible.\n\nLinear regression sample:\n\n```ruby\nrequire 'tensor_stream'\n\ntf = TensorStream\n\nlearning_rate = 0.01\ntraining_epochs = 1000\ndisplay_step = 50\n\ntrain_x = [3.3, 4.4, 5.5, 6.71, 6.93, 4.168, 9.779, 6.182, 7.59, 2.167,\n           7.042, 10.791, 5.313, 7.997, 5.654, 9.27, 3.1]\n\ntrain_y = [1.7, 2.76, 2.09, 3.19, 1.694, 1.573, 3.366, 2.596, 2.53, 1.221,\n           2.827, 3.465, 1.65, 2.904, 2.42, 2.94, 1.3]\n\nn_samples = train_x.size\n\nx_value = Float.placeholder\ny_value = Float.placeholder\n\n# Set model weights\nweight = rand.t.var name: \"weight\"\n\nbias = rand.t.var name: \"bias\"\n\n# Construct a linear model\npred = x_value * weight + bias\n\n# Mean squared error\ncost = ((pred - y_value)**2).reduce \u002F (2 * n_samples)\n\n# Other optimizers --\n#\n# optimizer = TensorStream::Train::MomentumOptimizer.new(learning_rate, momentum, use_nesterov: true).minimize(cost)\n# optimizer = TensorStream::Train::AdamOptimizer.new(learning_rate).minimize(cost)\n# optimizer = TensorStream::Train::AdadeltaOptimizer.new(1.0).minimize(cost)\n# optimizer = TensorStream::Train::AdagradOptimizer.new(0.01).minimize(cost)\n# optimizer = TensorStream::Train::RMSPropOptimizer.new(0.01, centered: true).minimize(cost)\noptimizer = TensorStream::Train::GradientDescentOptimizer.new(learning_rate).minimize(cost)\n\n# Initialize the variables (i.e. assign their default value)\ninit = tf.global_variables_initializer\n\ntf.session do |sess|\n  start_time = Time.now\n  sess.run(init)\n\n  (0..training_epochs).each do |epoch|\n    train_x.zip(train_y).each do |x, y|\n      sess.run(optimizer, feed_dict: { x_value => x, y_value => y })\n    end\n\n    if (epoch + 1) % display_step == 0\n      c = sess.run(cost, feed_dict: { x_value => train_x, y_value => train_y })\n      puts(\"Epoch:\", '%04d' % (epoch + 1), \"cost=\", c, \\\n           \"W=\", sess.run(weight), \"b=\", sess.run(bias))\n    end\n  end\n\n  puts \"Optimization Finished!\"\n  training_cost = sess.run(cost, feed_dict: { x_value => train_x, y_value => train_y })\n  puts \"Training cost=\", training_cost, \"W=\", sess.run(weight), \"b=\", sess.run(bias), '\\n'\n  puts \"time elapsed \", Time.now.to_i - start_time.to_i\nend\n```\n\nYou can take a look at spec\u002Ftensor_stream\u002Foperation_spec.rb for a list of supported ops and various examples and test cases used. Of course these contain only a\nsliver of what TensorFlow can do, so feel free to file a PR to add requested\nops and test cases.\n\nOther working samples can also be seen under tensor_stream\u002Fsamples.\n\nSamples that are used for development and are still being made to work can be found under test_samples\n\n## Python to Ruby guide\n\nNot all ops are available. Available ops are defined in lib\u002Ftensor_stream\u002Fops.rb, corresponding gradients are found at lib\u002Ftensor_stream\u002Fmath_gradients.\n\nThere are also certain differences with regards to naming conventions, and named parameters:\n\n# Variables and Constants\n\nTo make referencing python examples easier it is recommended to use \"tf\" as the TensorStream namespace\n\nAt the beginning\n```ruby\ntf = TensorStream # recommended to use tf since most sample models on the net use this\nts = TensorStream # use this if you plan to use TensorStream only features, so other devs will know about that\n```\n\nNote the difference in named and optional parameters\n\nPython\n\n```python\nw = ts.Variable(0, name='weights')\nw = ts.Variable(0, 'weights')\n```\n\nRuby\n\n```ruby\nw = ts.variable(0, name: 'weights')\nc = ts.constant(1.0)\n\n# concise way when initializing using a constant\nw = 0.t.var name: 'weights'\nc = 1.0.t\n```\n\nCalling .t to Integer, Array and Float types converts it into a tensor\n\n# Shapes\n\nPython\n```python\nx = tf.placeholder(tf.float32, shape=(1024, 1024))\nx = tf.placeholder(tf.float32, shape=(None, 1024))\n```\n\nruby supports symbols for specifying data types, nil can be used for None\n\nRuby\n```ruby\nx = ts.placeholder(:float32, shape: [1024, 1024])\nx = ts.placeholder(:float32, shape: [nil, 1024])\n\n# Another a bit more terse way\nx = Float.placeholder shape: [1024, 1024]\ny = Float.placeholder shape: [nil, 1024]\n```\n\nFor debugging, each operation or tensor supports the to_math method\n\n```ruby\nX = ts.placeholder(\"float\")\nY = ts.placeholder(\"float\")\nW = ts.variable(rand, name: \"weight\")\nb = ts.variable(rand, name: \"bias\")\npred = X * W + b\ncost = ts.reduce_sum(ts.pow(pred - Y, 2)) \u002F ( 2 * 10)\ncost.to_math # \"(reduce_sum(|((((Placeholder: * weight) + bias) - Placeholder_2:)^2)|) \u002F 20.0)\"\n```\n\nbreakpoints can also be set, block will be evaluated during computation\n\n```ruby\na = ts.constant([2,2])\nb = ts.constant([3,3])\n\nf = ts.matmul(a, b).breakpoint! { |tensor, a, b, result_value| binding.pry }\n\nts.session.run(f)\n```\n\n### OpenCL\n\nFor OpenCL support, make sure that the required OpenCL drivers for your hardware are correctly installed on your system.\nAlso OpenCL only supports ruby-mri at the moment.\n\nTo use, include the following gem in your project:\n\n```Gemfile\ngem 'tensor_stream-opencl'\n```\n\nTo use the opencl evaluator instead of the ruby evaluator simply require it (if using rails this should be loaded automatically).\n\n```ruby\nrequire 'tensor_stream\u002Fopencl'\n```\n\nAdding the OpenCL evaluator should expose additional devices available to tensor_stream\n\n```ruby\nts.list_local_devices\n# [\"job:localhost\u002Fts:ruby:cpu\", \"job:localhost\u002Fts:opencl:apple:0\", \"job:localhost\u002Fts:opencl:apple:1\"]\n```\nHere we see 1 \"ruby\" cpu device and 2 opencl \"apple\" devices (Intel CPU, Intel Iris GPU)\n\nBy default TensorStream will determine using the given evaluators the best possible\nplacement for each tensor operation\n\n```ruby\nrequire 'tensor_stream\u002Fopencl'\n\n# set session to use the opencl evaluator\nsess = ts.session\n\nsess.run(....) # do stuff\n\n```\n\nYou can manually place operations using ts.device e.g:\n\n```ruby\nts = TensorStream\n# Creates a graph. place in the first OpenCL CPU device\n\na, b = ts.device('\u002Fcpu:0') do\n  a = ts.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape: [2, 3], name: 'a')\n  b = ts.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape: [3, 2], name: 'b')\n  [a, b]\nend\n\nc = ts.device('\u002Fdevice:GPU:0') do\n  ts.matmul(a, b)\nend\n\n# Creates a session with log_device_placement set to True.\nsess = ts.session(log_device_placement: true)\n# Runs the op.\nprint(sess.run(c))\n\n# a : apple:0\n# b : apple:0\n# a_1 : apple:0\n# b_1 : apple:0\n# matmul:0 : apple:1\n# [[22.0, 28.0], [49.0, 64.0]] => nil\n```\n\nTo force the ruby evaluator even with the OpenCL evaluator loaded you can use:\n\n```ruby\nts.device('\u002Fts:ruby:cpu') do\n    # put ops here\nend\n```\n\nNote that the OpenCL evaluator provides speedup if you are using large tensors, tensors that are only using scalars like the linear regression sample will actually be slower.\n\nsamples\u002Fnearest_neighbor.rb contains a sample that uses opencl.\n\nOpenCL support is maintained as a separate project at:\n\nhttps:\u002F\u002Fgithub.com\u002Fjedld\u002Ftensor_stream-opencl\n\n## Export Import Models from tensorflow\n\nExperimental support for parsing and exporting pbtext files are supported:\n\nExporting\n\n```ruby\na = ts.constant([1.0, 1.0])\nb = ts.constant([1.5, 1.5])\nf = a + b\n\nFile.write('my_model.pbtext', f.graph.as_graph_def)\n```\n\nImporting (Experimental)\n\nNote that not all tensorflow ops are supported, warnings will be showed\nif a certain operation is not supported yet.\n\n\n```ruby\n  pbtext = File.read(File.join('linear_regression.pbtxt'))\n\n  # create a graph from pbtext file\n  graph = TensorStream::Graph.parse_from_string(pbtext)\n\n  # reference a tensor by name from the created graph,\n  # for example you have a tensor named out\n  tensor = graph.get_tensor_by_name(\"out\")\n\n  # set graph as default and do operations on it\n  graph.as_default do\n    sess = ts.session\n    expect(tr(sess.run(tensor))).to eq([[1.0, 1.0], [1.0, 1.0]])\n  end\n\n```\n\n# Visualization\n\ntensorstream does not support tensorboard yet, but a graphml generator is included:\n\n```ruby\ntf = TensorStream\na = tf.constant(1.0)\nb = tf.constant(2.0)\nresult = a + b\nsess = tf.session\nsess.run(result)\n\nFile.write('gradients.graphml', TensorStream::Graphml.new.get_string(result)) # dump graph only\nFile.write('gradients.graphml', TensorStream::Graphml.new.get_string(result, sess)) # dump with values from session\n```\n\nthe resulting graphml is designed to work with yED, after loading the graph change layout to \"Flowchart\" for best results\n\n## Exporting to TensorFlow\n\nStill in alpha but tensorstream supports TensorFlows as_graph_def serialization method:\n\n```ruby\ntf = TensorStream\na = tf.constant(1.0)\nb = tf.constant(2.0)\nresult = a + b\nFile.write(\"model.pbtext\", result.graph.as_graph_def)\n```\n\n## Performance notes\n\nComparative performance with respect to other ruby libraries have not yet been performed. However it is\nnotable that TruffleRuby and ruby-2.6.0 performs considerably better with respect\nto previous versions of ruby(\u003C 2.6)\n\nBenchmarks running samples\u002Flinear_regression.rb with tensor_stream 1.0.0 on an AMD(R) Ryzen(TM) 3 1300X CPU\n\n\nruby 2.5\n\n```\n$ ruby -v\nruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]\n$ ruby samples\u002Flinear_regression.rb\n296 seconds 3000 epochs\n```\n\nruby 2.6.0\n\n```\n$ ruby -v\nruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux]\n$ ruby samples\u002Flinear_regression.rb\n232 seconds 10000 epochs\n\nruby --jit samples\u002Flinear_regression.rb\n222 seconds 10000 epochs\n```\n\ntruffleruby\n```\n$ ruby -v\ntruffleruby 1.0.0-rc10, like ruby 2.4.4, GraalVM CE Native [x86_64-linux]\n246 seconds 10000 epochs\n```\n\njruby\n```\n$ ruby -v\njruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.191-b12 on 1.8.0_191-8u191-b12-0ubuntu0.18.04.1-b12 +jit [linux-x86_64]\n205 seconds 10000 epochs\n```\n\nFor training large networks that works on images, the opencl evaluator is the only way to go.\n\n## Roadmap\n\n- Docs\n- Complete low-level op support\n- SciRuby evaluator\n- Opencl evaluator\n- TensorFlow savemodel compatibility\n\n## Issues\n\n- This is an early preview release and many things still don't work\n- Performance is not great, at least until the opencl and\u002For sciruby backends are complete\n- However if you really need an op supported please feel free to file a pull request with the corresponding failing test (see spec\u002Foperation_spec.rb)\n\n## Development\n\nAfter checking out the repo, run `bin\u002Fsetup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin\u002Fconsole` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https:\u002F\u002Frubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https:\u002F\u002Fgithub.com\u002F[USERNAME]\u002Ftensor_stream. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http:\u002F\u002Fcontributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http:\u002F\u002Fopensource.org\u002Flicenses\u002FMIT).","[![Gem Version](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Ftensor_stream.svg)](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Ftensor_stream)[![Gem Version](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Ftensor_stream-opencl.svg)](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Ftensor_stream-opencl)[![CircleCI](https:\u002F\u002Fcircleci.com\u002Fgh\u002Fjedld\u002Ftensor_stream.svg?style=svg)](https:\u002F\u002Fcircleci.com\u002Fgh\u002Fjedld\u002Ftensor_stream) [![加入聊天 https:\u002F\u002Fgitter.im\u002Ftensor_stream\u002FLobby](https:\u002F\u002Fbadges.gitter.im\u002Ftensor_stream\u002FLobby.svg)](https:\u002F\u002Fgitter.im\u002Ftensor_stream\u002FLobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\n# TensorStream\n\nTensorStream 是一个面向 Ruby 的开源机器学习框架，旨在让机器学习模型的构建和在不同硬件（如 GPU 和 CPU）上的运行变得更加简单。它深度借鉴了 TensorFlow 的设计理念，目标是能够轻松移植其高层库和模型示例。因此，TensorStream 也基于数据流图，通过定义计算及其之间的数据流动来实现预期的输出。\n\nTensorStream 设计为支持多种后端，包括纯 Ruby 实现和 OpenCL 实现。这些实现可以协同工作：你可以在具有 GPU 的 OpenCL 后端上进行训练，然后将训练好的模型部署到任何可以运行 Ruby 的环境中，使用纯 Ruby 后端执行推理。TensorStream 已经在大多数 Ruby 实现上进行了测试，例如 MRI、JRuby 和 TruffleRuby。\n\n## 目标与特性\n\n- 易于使用 - 提升模型的可读性\n- 复刻了 TensorFlow 中常用的大部分低层操作（tf.add、tf.constant、tf.placeholder、tf.matmul、tf.sin 等）\n- 支持基于形式导数的自动微分\n- 可扩展 - 使用自定义的运算符求值器（目前支持 OpenCL 和纯 Ruby）\n- 广泛兼容 - 可在大多数 Ruby 实现上运行，并在支持 OpenCL 的硬件上实现加速\n\n## 兼容性\n\nTensorStream 默认提供了纯 Ruby 和 OpenCL 两种实现。纯 Ruby 实现已知可在大多数 Ruby 实现上运行，包括 TruffleRuby、JRuby 以及启用了 JIT 的 MRI 版本（Ruby 2.6.0）。\n\nOpenCL 仅支持 MRI 版本的 Ruby。可以通过添加 OpenCL 求值器 gem 来启用（请确保系统已正确安装 OpenCL 驱动程序）：\n\n```Gemfile\ngem 'tensor_stream-opencl'\n```\n\n然后（无需 Bundler）：\n\n```ruby\nrequire 'tensor_stream\u002Fopencl'\n```\n\n对于深度学习和图像处理任务，OpenCL 几乎是必需的，因为即使使用最新版本的 Ruby 并启用 JIT 加速，Ruby 实现的速度仍然太慢。\n\nTensorStream 使用的 OpenCL 内核位于 tensor_stream\u002Flib\u002Fevaluator\u002Fopencl\u002Fkernels。这些内核不特定于任何设备，应能在任何支持 OpenCL 的设备上运行，包括 Intel 的 GPU 和 CPU，以及 NVIDIA 和 AMD 的 GPU。\n\n## 安装\n\n安装非常简单，无需折腾 Docker、Python、Clang 等工具，MRI 和 JRuby 均可开箱即用。\n\n将以下行添加到你的应用 Gemfile 中：\n\n```ruby\ngem 'tensor_stream'\n```\n\n然后执行：\n\n    $ bundle\n\n或者直接安装：\n\n    $ gem install tensor_stream\n\n## 使用\n\n使用方式类似于 TensorFlow，只是采用了 Ruby 语法。此外，还对语法进行了优化，使其尽可能简洁。\n\n线性回归示例：\n\n```ruby\nrequire 'tensor_stream'\n\ntf = TensorStream\n\nlearning_rate = 0.01\ntraining_epochs = 1000\ndisplay_step = 50\n\ntrain_x = [3.3, 4.4, 5.5, 6.71, 6.93, 4.168, 9.779, 6.182, 7.59, 2.167,\n           7.042, 10.791, 5.313, 7.997, 5.654, 9.27, 3.1]\n\ntrain_y = [1.7, 2.76, 2.09, 3.19, 1.694, 1.573, 3.366, 2.596, 2.53, 1.221,\n           2.827, 3.465, 1.65, 2.904, 2.42, 2.94, 1.3]\n\nn_samples = train_x.size\n\nx_value = Float.placeholder\ny_value = Float.placeholder\n\n# 设置模型权重\nweight = rand.t.var name: \"weight\"\n\nbias = rand.t.var name: \"bias\"\n\n# 构建线性模型\npred = x_value * weight + bias\n\n# 均方误差\ncost = ((pred - y_value)**2).reduce \u002F (2 * n_samples)\n\n# 其他优化器 --\n#\n# optimizer = TensorStream::Train::MomentumOptimizer.new(learning_rate, momentum, use_nesterov: true).minimize(cost)\n# optimizer = TensorStream::Train::AdamOptimizer.new(learning_rate).minimize(cost)\n# optimizer = TensorStream::Train::AdadeltaOptimizer.new(1.0).minimize(cost)\n# optimizer = TensorStream::Train::AdagradOptimizer.new(0.01).minimize(cost)\n# optimizer = TensorStream::Train::RMSPropOptimizer.new(0.01, centered: true).minimize(cost)\noptimizer = TensorStream::Train::GradientDescentOptimizer.new(learning_rate).minimize(cost)\n\n# 初始化变量（即为其设置默认值）\ninit = tf.global_variables_initializer\n\ntf.session do |sess|\n  start_time = Time.now\n  sess.run(init)\n\n  (0..training_epochs).each do |epoch|\n    train_x.zip(train_y).each do |x, y|\n      sess.run(optimizer, feed_dict: { x_value => x, y_value => y })\n    end\n\n    if (epoch + 1) % display_step == 0\n      c = sess.run(cost, feed_dict: { x_value => train_x, y_value => train_y })\n      puts(\"Epoch:\", '%04d' % (epoch + 1), \"cost=\", c, \\\n           \"W=\", sess.run(weight), \"b=\", sess.run(bias))\n    end\n  end\n\n  puts \"Optimization Finished!\"\n  training_cost = sess.run(cost, feed_dict: { x_value => train_x, y_value => train_y })\n  puts \"Training cost=\", training_cost, \"W=\", sess.run(weight), \"b=\", sess.run(bias), '\\n'\n  puts \"time elapsed \", Time.now.to_i - start_time.to_i\nend\n```\n\n你可以在 spec\u002Ftensor_stream\u002Foperation_spec.rb 中查看支持的操作列表以及各种示例和测试用例。当然，这些内容只是 TensorFlow 能力的一小部分，欢迎提交 PR 添加所需的操作和测试用例。\n\n其他可用的示例也可以在 tensor_stream\u002Fsamples 中找到。\n\n用于开发且仍在调试中的示例则位于 test_samples 目录下。\n\n## Python 到 Ruby 指南\n\n并非所有操作都可用。可用的操作定义在 lib\u002Ftensor_stream\u002Fops.rb 中，对应的梯度则位于 lib\u002Ftensor_stream\u002Fmath_gradients。\n\n命名规范和命名参数方面也有一些差异：\n\n# 变量与常量\n\n为了更方便参考 Python 示例，建议将 TensorStream 的命名空间设为 “tf”。\n\n在开头：\n\n```ruby\ntf = TensorStream # 推荐使用 tf，因为网络上的大多数示例模型都使用这个命名空间\nts = TensorStream # 如果你只打算使用 TensorStream 的特定功能，可以使用 ts，以便其他开发者了解你的意图\n```\n\n注意命名参数和可选参数的区别：\n\nPython\n\n```python\nw = ts.Variable(0, name='weights')\nw = ts.Variable(0, 'weights')\n```\n\nRuby\n\n```ruby\nw = ts.variable(0, name: 'weights')\nc = ts.constant(1.0)\n\n# 使用常量初始化时的简洁写法\nw = 0.t.var name: 'weights'\nc = 1.0.t\n```\n\n对 Integer、Array 和 Float 类型调用 .t 方法会将其转换为张量。\n\n# 形状\n\nPython\n```python\nx = tf.placeholder(tf.float32, shape=(1024, 1024))\nx = tf.placeholder(tf.float32, shape=(None, 1024))\n```\n\nRuby 支持使用符号来指定数据类型，`nil` 可以用于表示 `None`。\n\nRuby\n```ruby\nx = ts.placeholder(:float32, shape: [1024, 1024])\nx = ts.placeholder(:float32, shape: [nil, 1024])\n\n# 另一种更简洁的方式\nx = Float.placeholder shape: [1024, 1024]\ny = Float.placeholder shape: [nil, 1024]\n```\n\n为了调试，每个操作或张量都支持 `to_math` 方法。\n\n```ruby\nX = ts.placeholder(\"float\")\nY = ts.placeholder(\"float\")\nW = ts.variable(rand, name: \"weight\")\nb = ts.variable(rand, name: \"bias\")\npred = X * W + b\ncost = ts.reduce_sum(ts.pow(pred - Y, 2)) \u002F ( 2 * 10)\ncost.to_math # \"(reduce_sum(|((((Placeholder: * weight) + bias) - Placeholder_2:)^2)|) \u002F 20.0)\"\n```\n\n还可以设置断点，块会在计算过程中被评估。\n\n```ruby\na = ts.constant([2,2])\nb = ts.constant([3,3])\n\nf = ts.matmul(a, b).breakpoint! { |tensor, a, b, result_value| binding.pry }\n\nts.session.run(f)\n```\n\n### OpenCL\n\n要使用 OpenCL 支持，请确保您的硬件已正确安装所需的 OpenCL 驱动程序。此外，目前 OpenCL 仅支持 Ruby MRI。\n\n要使用，只需在项目中包含以下 gem：\n\n```Gemfile\ngem 'tensor_stream-opencl'\n```\n\n要使用 OpenCL 求解器而不是 Ruby 求解器，只需将其引入即可（如果使用 Rails，它应该会自动加载）。\n\n```ruby\nrequire 'tensor_stream\u002Fopencl'\n```\n\n添加 OpenCL 求解器后，TensorStream 将会显示额外的可用设备。\n\n```ruby\nts.list_local_devices\n# [\"job:localhost\u002Fts:ruby:cpu\", \"job:localhost\u002Fts:opencl:apple:0\", \"job:localhost\u002Fts:opencl:apple:1\"]\n```\n\n这里我们看到 1 个 “ruby” CPU 设备和 2 个 OpenCL “apple” 设备（Intel CPU、Intel Iris GPU）。\n\n默认情况下，TensorStream 会根据给定的求解器为每个张量操作选择最佳的执行位置。\n\n```ruby\nrequire 'tensor_stream\u002Fopencl'\n\n# 设置会话使用 OpenCL 求解器\nsess = ts.session\n\nsess.run(....) # 执行一些操作\n\n```\n\n您也可以手动使用 `ts.device` 来放置操作，例如：\n\n```ruby\nts = TensorStream\n# 创建一个图，并将其放置在第一个 OpenCL CPU 设备上\n\na, b = ts.device('\u002Fcpu:0') do\n  a = ts.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape: [2, 3], name: 'a')\n  b = ts.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape: [3, 2], name: 'b')\n  [a, b]\nend\n\nc = ts.device('\u002Fdevice:GPU:0') do\n  ts.matmul(a, b)\nend\n\n# 创建一个启用 log_device_placement 的会话。\nsess = ts.session(log_device_placement: true)\n# 运行该操作。\nprint(sess.run(c))\n\n# a : apple:0\n# b : apple:0\n# a_1 : apple:0\n# b_1 : apple:0\n# matmul:0 : apple:1\n# [[22.0, 28.0], [49.0, 64.0]] => nil\n```\n\n即使加载了 OpenCL 求解器，如果您想强制使用 Ruby 求解器，可以这样做：\n\n```ruby\nts.device('\u002Fts:ruby:cpu') do\n    # 在这里放置操作\nend\n```\n\n需要注意的是，OpenCL 求解器在处理大型张量时会带来速度提升，而对于只涉及标量的操作（如线性回归示例），实际上可能会更慢。\n\nsamples\u002Fnearest_neighbor.rb 包含一个使用 OpenCL 的示例。\n\nOpenCL 支持作为独立项目维护在以下地址：\n\nhttps:\u002F\u002Fgithub.com\u002Fjedld\u002Ftensor_stream-opencl\n\n## 从 TensorFlow 导出和导入模型\n\n目前支持解析和导出 pbtext 文件的实验性功能：\n\n导出\n\n```ruby\na = ts.constant([1.0, 1.0])\nb = ts.constant([1.5, 1.5])\nf = a + b\n\nFile.write('my_model.pbtext', f.graph.as_graph_def)\n```\n\n导入（实验性）\n\n请注意，并非所有 TensorFlow 操作都受支持；如果某些操作尚未支持，将会显示警告。\n\n```ruby\n  pbtext = File.read(File.join('linear_regression.pbtxt'))\n\n  # 从 pbtext 文件创建图\n  graph = TensorStream::Graph.parse_from_string(pbtext)\n\n  # 通过名称引用图中的张量，例如有一个名为 out 的张量\n  tensor = graph.get_tensor_by_name(\"out\")\n\n  # 将图设为默认图并在此基础上进行操作\n  graph.as_default do\n    sess = ts.session\n    expect(tr(sess.run(tensor))).to eq([[1.0, 1.0], [1.0, 1.0]])\n  end\n\n```\n\n# 可视化\n\nTensorStream 目前还不支持 TensorBoard，但包含了一个 GraphML 生成器：\n\n```ruby\ntf = TensorStream\na = tf.constant(1.0)\nb = tf.constant(2.0)\nresult = a + b\nsess = tf.session\nsess.run(result)\n\nFile.write('gradients.graphml', TensorStream::Graphml.new.get_string(result)) # 只转储图\nFile.write('gradients.graphml', TensorStream::Graphml.new.get_string(result, sess)) # 同时转储会话中的值\n```\n\n生成的 GraphML 文件设计用于与 yED 配合使用。加载图后，将布局更改为“流程图”以获得最佳效果。\n\n## 导出到 TensorFlow\n\n目前仍处于 Alpha 阶段，但 TensorStream 支持 TensorFlow 的 as_graph_def 序列化方法：\n\n```ruby\ntf = TensorStream\na = tf.constant(1.0)\nb = tf.constant(2.0)\nresult = a + b\nFile.write(\"model.pbtext\", result.graph.as_graph_def)\n```\n\n## 性能说明\n\n与其他 Ruby 库相比，性能尚未进行比较。然而，值得注意的是，TruffleRuby 和 Ruby 2.6.0 在性能上明显优于之前的 Ruby 版本（\u003C 2.6）。\n\n使用 AMD(R) Ryzen(TM) 3 1300X CPU，在运行 samples\u002Flinear_regression.rb 样本时，TensorStream 1.0.0 的基准测试结果如下：\n\nRuby 2.5\n\n```\n$ ruby -v\nruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]\n$ ruby samples\u002Flinear_regression.rb\n296 秒，3000 次迭代\n```\n\nRuby 2.6.0\n\n```\n$ ruby -v\nruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux]\n$ ruby samples\u002Flinear_regression.rb\n232 秒，10000 次迭代\n\nruby --jit samples\u002Flinear_regression.rb\n222 秒，10000 次迭代\n```\n\nTruffleruby\n\n```\n$ ruby -v\ntruffleruby 1.0.0-rc10，类似 ruby 2.4.4，GraalVM CE Native [x86_64-linux]\n246 秒，10000 次迭代\n```\n\nJRuby\n\n```\n$ ruby -v\njruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.191-b12 on 1.8.0_191-8u191-b12-0ubuntu0.18.04.1-b12 +jit [linux-x86_64]\n205 秒，10000 次迭代\n```\n\n对于基于图像的大型网络训练，OpenCL 求解器是唯一可行的选择。\n\n## 路线图\n\n- 文档\n- 完整的低级操作支持\n- SciRuby 求解器\n- OpenCL 求解器\n- TensorFlow savemodel 兼容性\n\n## 问题\n\n- 这是一个早期预览版本，许多功能仍未完善。\n- 性能尚不理想，至少在 OpenCL 和\u002F或 SciRuby 后端完成之前是如此。\n- 不过，如果您确实需要某个操作的支持，请随时提交包含相应失败测试的拉取请求（参见 spec\u002Foperation_spec.rb）。\n\n## 开发\n\n检出仓库后，运行 `bin\u002Fsetup` 安装依赖。然后，运行 `rake spec` 来执行测试。你还可以运行 `bin\u002Fconsole` 启动一个交互式提示符，以便进行实验。\n\n要将此 gem 安装到本地机器上，请运行 `bundle exec rake install`。要发布新版本，先更新 `version.rb` 中的版本号，然后运行 `bundle exec rake release`，它会为该版本创建一个 Git 标签，推送 Git 提交和标签，并将 `.gem` 文件发布到 [rubygems.org](https:\u002F\u002Frubygems.org)。\n\n## 贡献\n\n欢迎在 GitHub 上通过 https:\u002F\u002Fgithub.com\u002F[USERNAME]\u002Ftensor_stream 提交 bug 报告和拉取请求。本项目旨在成为一个安全、友好的协作空间，贡献者应遵守 [Contributor Covenant](http:\u002F\u002Fcontributor-covenant.org) 行为准则。\n\n## 许可证\n\n该 gem 以开源形式提供，遵循 [MIT 许可证](http:\u002F\u002Fopensource.org\u002Flicenses\u002FMIT) 的条款。","# TensorStream 快速上手指南\n\nTensorStream 是一个专为 Ruby 设计的开源机器学习框架。它基于数据流图理念，语法高度兼容 TensorFlow，支持纯 Ruby 和 OpenCL 后端。你可以利用 GPU 进行模型训练，并将训练好的模型部署到任何支持 Ruby 的环境中运行。\n\n## 环境准备\n\n### 系统要求\n- **Ruby 版本**：支持 MRI (推荐 2.6.0+)、JRuby 和 TruffleRuby。\n- **操作系统**：Linux, macOS, Windows。\n\n### 前置依赖\n- **基础模式（CPU）**：无需额外依赖，安装 Ruby 即可。\n- **加速模式（GPU\u002FOpenCL）**：\n  - 仅支持 **MRI Ruby**。\n  - 必须正确安装对应硬件的 **OpenCL 驱动程序**（支持 Intel CPU\u002FGPU, Nvidia GPU, AMD GPU）。\n  - 需安装 `tensor_stream-opencl` gem。\n\n## 安装步骤\n\n### 1. 安装核心库\n将以下行添加到项目的 `Gemfile` 中：\n\n```ruby\ngem 'tensor_stream'\n```\n\n然后执行安装命令：\n\n```bash\nbundle\n```\n\n或者直接使用 gem 安装：\n\n```bash\ngem install tensor_stream\n```\n\n### 2. （可选）安装 OpenCL 加速支持\n如果你需要使用 GPU 加速或处理深度学习任务，请额外安装 OpenCL 扩展：\n\n```ruby\n# 在 Gemfile 中添加\ngem 'tensor_stream-opencl'\n```\n\n执行安装：\n\n```bash\nbundle\n```\n\n*注意：国内开发者若遇到 gem 源下载缓慢，可临时切换至国内镜像源：*\n```bash\ngem sources --add https:\u002F\u002Fgems.ruby-china.com\u002F --remove https:\u002F\u002Frubygems.org\u002F\ngem sources -l # 确认列表只有 ruby-china 源\n```\n\n## 基本使用\n\nTensorStream 的用法与 TensorFlow 类似，但采用 Ruby 语法风格。以下是一个完整的**线性回归**示例，展示了如何定义占位符、变量、构建计算图、选择优化器并执行训练。\n\n```ruby\nrequire 'tensor_stream'\n\n# 推荐使用 tf 作为命名空间，以便参考 Python 版 TensorFlow 文档\ntf = TensorStream\n\nlearning_rate = 0.01\ntraining_epochs = 1000\ndisplay_step = 50\n\n# 训练数据\ntrain_x = [3.3, 4.4, 5.5, 6.71, 6.93, 4.168, 9.779, 6.182, 7.59, 2.167,\n           7.042, 10.791, 5.313, 7.997, 5.654, 9.27, 3.1]\n\ntrain_y = [1.7, 2.76, 2.09, 3.19, 1.694, 1.573, 3.366, 2.596, 2.53, 1.221,\n           2.827, 3.465, 1.65, 2.904, 2.42, 2.94, 1.3]\n\nn_samples = train_x.size\n\n# 定义占位符 (Placeholder)\nx_value = Float.placeholder\ny_value = Float.placeholder\n\n# 定义模型权重和偏置 (Variables)\nweight = rand.t.var name: \"weight\"\nbias = rand.t.var name: \"bias\"\n\n# 构建线性模型: pred = x * weight + bias\npred = x_value * weight + bias\n\n# 定义损失函数：均方误差 (Mean Squared Error)\ncost = ((pred - y_value)**2).reduce \u002F (2 * n_samples)\n\n# 定义优化器 (梯度下降)\noptimizer = TensorStream::Train::GradientDescentOptimizer.new(learning_rate).minimize(cost)\n\n# 初始化变量\ninit = tf.global_variables_initializer\n\n# 创建会话并运行\ntf.session do |sess|\n  start_time = Time.now\n  sess.run(init)\n\n  (0..training_epochs).each do |epoch|\n    # 逐个样本进行训练\n    train_x.zip(train_y).each do |x, y|\n      sess.run(optimizer, feed_dict: { x_value => x, y_value => y })\n    end\n\n    # 每隔一定步数打印日志\n    if (epoch + 1) % display_step == 0\n      c = sess.run(cost, feed_dict: { x_value => train_x, y_value => train_y })\n      puts(\"Epoch:\", '%04d' % (epoch + 1), \"cost=\", c, \\\n           \"W=\", sess.run(weight), \"b=\", sess.run(bias))\n    end\n  end\n\n  puts \"Optimization Finished!\"\n  training_cost = sess.run(cost, feed_dict: { x_value => train_x, y_value => train_y })\n  puts \"Training cost=\", training_cost, \"W=\", sess.run(weight), \"b=\", sess.run(bias)\n  puts \"time elapsed \", Time.now.to_i - start_time.to_i\nend\n```\n\n### 启用 OpenCL 加速\n若已安装 `tensor_stream-opencl`，只需在代码开头引入即可自动启用 GPU 加速（针对大张量运算）：\n\n```ruby\nrequire 'tensor_stream\u002Fopencl'\n\n# 查看可用设备\nputs TensorStream.list_local_devices\n# 输出示例：[\"job:localhost\u002Fts:ruby:cpu\", \"job:localhost\u002Fts:opencl:apple:0\"]\n\n# 后续代码无需修改，框架会自动将合适的操作调度到 OpenCL 设备\nts = TensorStream\nsess = ts.session\n# ... 执行训练或推理 ...\n```","一家专注于电商数据分析的初创团队，希望利用现有的 Ruby on Rails 技术栈快速构建商品销量预测模型，以避免引入复杂的 Python 环境。\n\n### 没有 tensor_stream 时\n- **技术栈割裂**：数据预处理和业务逻辑用 Ruby 编写，但训练模型必须调用 Python 的 TensorFlow，导致系统架构复杂，需维护两套运行环境。\n- **部署门槛高**：生产环境部署困难，服务器必须安装 Python、clang 及各类深度学习依赖库，甚至需要配置 Docker 容器来隔离环境。\n- **硬件加速受限**：纯 Ruby 实现计算速度极慢，无法利用 GPU 进行加速，而配置跨语言调用的 GPU 资源不仅开发成本高且稳定性差。\n- **迭代效率低**：算法工程师与后端开发人员协作困难，模型从实验到上线的周期长，难以响应快速变化的业务需求。\n\n### 使用 tensor_stream 后\n- **原生无缝集成**：直接在 Ruby 代码中定义数据流图和神经网络层，无需切换语言或进程，实现了从数据清洗到模型训练的端到端开发。\n- **极简部署体验**：仅需通过 Gemfile 安装即可运行，彻底摆脱了对 Python、Docker 或复杂编译环境的依赖，模型可随 Rails 应用轻松部署至任意支持 Ruby 的服务器。\n- **灵活硬件加速**：开发阶段利用 OpenCL 后端在 GPU 上高效训练模型，上线后自动切换至纯 Ruby 后端进行推理，既保证了训练速度又确保了部署的通用性。\n- **研发效能提升**：团队成员无需学习新语言，利用熟悉的 Ruby 语法即可完成深度学习任务，大幅缩短了从原型验证到产品落地的时间。\n\ntensor_stream 让 Ruby 开发者能在不跳出舒适区的前提下，原生享受深度学习带来的算力红利，真正实现了“一次编写，随处运行”。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fjedld_tensor_stream_2d039c40.png","jedld","Joseph Emmanuel Dayo","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fjedld_942f7e8d.jpg","Artificial Intelligence Researcher, Ruby on Rails, Android Developer (Apps and Device Porting), ",null,"Manila, Philippines","https:\u002F\u002Fgithub.com\u002Fjedld",[81,85,89,92],{"name":82,"color":83,"percentage":84},"Ruby","#701516",99.6,{"name":86,"color":87,"percentage":88},"Dockerfile","#384d54",0.2,{"name":90,"color":91,"percentage":88},"HTML","#e34c26",{"name":93,"color":94,"percentage":95},"Shell","#89e051",0,506,16,"2026-01-12T05:12:14","MIT","未说明","非必需。若需深度学习或图像处理加速，需支持 OpenCL 的设备（如 Intel GPU\u002FCPU, NVIDIA GPU, AMD GPU）。纯 Ruby 实现仅使用 CPU 且速度较慢。",{"notes":103,"python":104,"dependencies":105},"该工具是基于 Ruby 的机器学习框架，无需 Python、Docker 或 Clang。OpenCL 加速功能仅在 MRI Ruby 实现上受支持，且需系统正确安装 OpenCL 驱动。对于标量运算，OpenCL 可能比纯 Ruby 实现更慢；它主要适用于大张量运算。","不需要 (基于 Ruby)",[106,107],"ruby (MRI, JRuby, TruffleRuby)","tensor_stream-opencl (可选，用于 GPU 加速)",[14],[110,111],"machine-learning","tensorflow","2026-03-27T02:49:30.150509","2026-04-18T00:45:31.443453",[115,120,125,130,135],{"id":116,"question_zh":117,"answer_zh":118,"source_url":119},38234,"运行示例代码时出现 'cannot load such file -- pry-byebug' 错误，该如何解决？","pry-byebug 仅用于调试，不应作为生产依赖。解决方法是确保在 Gemfile 中添加 'gem \"pry-byebug\"'，或者等待项目更新移除示例中的该依赖。维护者已在 0.9.10 版本中修复了此问题，建议升级版本或手动添加该 gem 以临时解决。","https:\u002F\u002Fgithub.com\u002Fjedld\u002Ftensor_stream\u002Fissues\u002F4",{"id":121,"question_zh":122,"answer_zh":123,"source_url":124},38235,"使用 matmul 函数时报错 'Const rank must be greater than 1' 是什么意思？","matmul（矩阵乘法）要求输入至少是秩为 2 的张量（即二维数组），且形状必须兼容。例如，若要进行矩阵乘法，代码应写为：\nrequire 'tensor_stream'\nts = TensorStream\na = ts.constant([[2,2]])\nb = ts.constant([[3],[3]])\nf = ts.matmul(a,b, name: 'abc')\nts.session.run(f)\n请确保传入的是二维数组而非一维数组。","https:\u002F\u002Fgithub.com\u002Fjedld\u002Ftensor_stream\u002Fissues\u002F5",{"id":126,"question_zh":127,"answer_zh":128,"source_url":129},38236,"运行 RNN 示例 (rnn.rb) 时遇到 'TensorStream::Operation can't be coerced into Integer' 错误怎么办？","这是一个已知的代码缺陷，维护者已在 master 分支和最新发布的版本中修复了该问题。请拉取最新代码或升级到最新版本即可解决。","https:\u002F\u002Fgithub.com\u002Fjedld\u002Ftensor_stream\u002Fissues\u002F8",{"id":131,"question_zh":132,"answer_zh":133,"source_url":134},38237,"如何将 TensorStream 项目添加到 Ruby 机器学习社区资源列表中？","您可以联系列表维护者（如 arbox），他们通常会将项目列入清单。为了更好地连接其他 Ruby ML 项目，建议在您的仓库中添加 'rubyml' 主题标签（topic\u002Ftag），并在 README 中包含 Awesome Badge。该项目已被列入 machine-learning-with-ruby 列表并在 Reddit 和 RubyFlow 上推广。","https:\u002F\u002Fgithub.com\u002Fjedld\u002Ftensor_stream\u002Fissues\u002F2",{"id":136,"question_zh":137,"answer_zh":138,"source_url":139},38238,"在哪里可以找到 TensorStream 在 Ruby 工具箱（Ruby Toolbox）中的条目？","TensorStream 已被添加到 Ruby Toolbox 目录中。您可以通过相关 Pull Request 查看或直接访问 Ruby Toolbox 网站搜索 'tensor_stream' 来找到该项目条目。","https:\u002F\u002Fgithub.com\u002Fjedld\u002Ftensor_stream\u002Fissues\u002F6",[]]