[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-adambielski--siamese-triplet":3,"tool-adambielski--siamese-triplet":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 真正成长为懂上",150037,2,"2026-04-10T23:33:47",[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":79,"owner_website":80,"owner_url":81,"languages":82,"stars":87,"forks":88,"last_commit_at":89,"license":90,"difficulty_score":32,"env_os":91,"env_gpu":92,"env_ram":92,"env_deps":93,"category_tags":98,"github_topics":99,"view_count":32,"oss_zip_url":78,"oss_zip_packed_at":78,"status":17,"created_at":109,"updated_at":110,"faqs":111,"releases":146},6431,"adambielski\u002Fsiamese-triplet","siamese-triplet","Siamese and triplet networks with online pair\u002Ftriplet mining in PyTorch","siamese-triplet 是一个基于 PyTorch 的开源工具，专注于实现孪生网络（Siamese Networks）和三元组网络（Triplet Networks），旨在学习高质量的图像嵌入表示。它核心解决了如何将图像映射到紧凑的欧几里得空间的问题，使得在该空间中，距离远近能直接反映图像间的相似度。这种能力对于分类任务，尤其是数据稀缺的“少样本学习”场景至关重要。\n\n该工具特别适合 AI 研究人员和深度学习开发者使用，尤其是那些需要自定义度量学习策略或探索特征嵌入技术的专业人士。其独特的技术亮点在于支持“在线挖掘”（Online Mining）机制：在训练过程中，它能动态地从每个迷你批次中自动筛选出最具价值的正负样本对或三元组（如困难负样本），从而显著提升模型区分细微差异的能力。此外，siamese-triplet 提供了模块化的代码结构，内置了多种损失函数（如对比损失、三元组损失）及灵活的采样策略，并附带完整的 MNIST 实验示例，帮助用户快速上手并可视化验证嵌入效果，是进行度量学习研究与开发的实用基石。","# Siamese and triplet learning with online pair\u002Ftriplet mining\n\nPyTorch implementation of siamese and triplet networks for learning embeddings.\n\nSiamese and triplet networks are useful to learn mappings from image to a compact Euclidean space where distances correspond to a measure of similarity [2]. Embeddings trained in such way can be used as features vectors for classification or few-shot learning tasks.\n\n# Installation\n\nRequires [pytorch](http:\u002F\u002Fpytorch.org\u002F) 0.4 with torchvision 0.2.1\n\nFor pytorch 0.3 compatibility checkout tag torch-0.3.1\n\n# Code structure\n\n- **datasets.py**\n  - *SiameseMNIST* class - wrapper for a MNIST-like dataset, returning random positive and negative pairs\n  - *TripletMNIST* class - wrapper for a MNIST-like dataset, returning random triplets (anchor, positive and negative)\n  - *BalancedBatchSampler* class - BatchSampler for data loader, randomly chooses *n_classes* and *n_samples* from each class based on labels\n- **networks.py**\n  - *EmbeddingNet* - base network for encoding images into embedding vector\n  - *ClassificationNet* - wrapper for an embedding network, adds a fully connected layer and log softmax for classification\n  - *SiameseNet* - wrapper for an embedding network, processes pairs of inputs\n  - *TripletNet* - wrapper for an embedding network, processes triplets of inputs\n- **losses.py**\n  - *ContrastiveLoss* - contrastive loss for pairs of embeddings and pair target (same\u002Fdifferent)\n  - *TripletLoss* - triplet loss for triplets of embeddings\n  - *OnlineContrastiveLoss* - contrastive loss for a mini-batch of embeddings. Uses a *PairSelector* object to find positive and negative pairs within a mini-batch using ground truth class labels and computes contrastive loss for these pairs\n  - *OnlineTripletLoss* - triplet loss for a mini-batch of embeddings. Uses a *TripletSelector* object to find triplets within a mini-batch using ground truth class labels and computes triplet loss\n- **trainer.py**\n  - *fit* - unified function for training a network with different number of inputs and different types of loss functions\n- **metrics.py**\n  - Sample metrics that can be used with *fit* function from *trainer.py*\n- **utils.py**\n  - *PairSelector* - abstract class defining objects generating pairs based on embeddings and ground truth class labels. Can be used with *OnlineContrastiveLoss*.\n    - *AllPositivePairSelector, HardNegativePairSelector* - PairSelector implementations\n  - *TripletSelector* - abstract class defining objects generating triplets based on embeddings and ground truth class labels. Can be used with *OnlineTripletLoss*.\n    - *AllTripletSelector*, *HardestNegativeTripletSelector*, *RandomNegativeTripletSelector*, *SemihardNegativeTripletSelector* - TripletSelector implementations\n\n# Examples - MNIST\n\nWe'll train embeddings on MNIST dataset. Experiments were run in [jupyter notebook](Experiments_MNIST.ipynb).\n\nWe'll go through learning supervised feature embeddings using different loss functions on MNIST dataset. This is just for visualization purposes, thus we'll be using 2-dimensional embeddings which isn't the best choice in practice.\n\nFor every experiment the same embedding network is used (32 conv 5x5 -> PReLU -> MaxPool 2x2 -> 64 conv 5x5 -> PReLU -> MaxPool 2x2 -> Dense 256 -> PReLU -> Dense 256 -> PReLU -> Dense 2) and we don't perform any hyperparameter search.\n\n## Baseline - classification with softmax\n\nWe add a fully-connected layer with the number of classes and train the network for classification with softmax and cross-entropy. The network trains to ~99% accuracy. We extract 2 dimensional embeddings from penultimate layer:\n\nTrain set:\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_6d5ce2a61984.png)\n\nTest set:\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_3714850c8945.png)\n\nWhile the embeddings look separable (which is what we trained them for), they don't have good metric properties. They might not be the best choice as a descriptor for new classes.\n\n## Siamese network\n\nNow we'll train a siamese network that takes a pair of images and trains the embeddings so that the distance between them is minimized if they're from the same class and is greater than some margin value if they represent different classes.\nWe'll minimize a contrastive loss function [1]:\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_ba81080ff52c.png)\n\n*SiameseMNIST* class samples random positive and negative pairs that are then fed to Siamese Network.\n\nAfter 20 epochs of training here are the embeddings we get for training set:\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_1b93eb6945fe.png)\n\nTest set:\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_4016107a03fd.png)\n\nThe learned embeddings are clustered much better within class.\n\n## Triplet network\n\nWe'll train a triplet network, that takes an anchor, a positive (of same class as an anchor) and negative (of different class than an anchor) examples. The objective is to learn embeddings such that the anchor is closer to the positive example than it is to the negative example by some margin value.\n\n![alt text](images\u002Fanchor_negative_positive.png \"Source: FaceNet\")\nSource: *Schroff, Florian, Dmitry Kalenichenko, and James Philbin. [Facenet: A unified embedding for face recognition and clustering.](https:\u002F\u002Farxiv.org\u002Fabs\u002F1503.03832) CVPR 2015.*\n\n**Triplet loss**:   ![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_ef0ad08aa45e.png)\n\n*TripletMNIST* class samples a positive and negative example for every possible anchor.\n\nAfter 20 epochs of training here are the embeddings we get for training set:\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_f12b9cb98bb5.png)\n\nTest set:\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_8770e8ef72d2.png)\n\nThe learned embeddings are not as close to each other within class as in case of siamese network, but that's not what we optimized them for. We wanted the embeddings to be closer to other embeddings from the same class than from the other classes and we can see that's where the training is going to.\n\n## Online pair\u002Ftriplet selection - negative mining\n\nThere are couple of problems with siamese and triplet networks:\n1. The **number of possible pairs\u002Ftriplets** grows **quadratically\u002Fcubically** with the number of examples. It's infeasible to process them all and the training converges slowly.\n2. We generate pairs\u002Ftriplets *randomly*. As the training continues, more and more pairs\u002Ftriplets are **easy** to deal with (their loss value is very small or even 0), *preventing the network from training*. We need to provide the network with **hard examples**.\n3. Each image that is fed to the network is used only for computation of contrastive\u002Ftriplet loss for only one pair\u002Ftriplet. The computation is somewhat wasted; once the embedding is computed, it could be reused for many pairs\u002Ftriplets.\n\nTo deal with these issues efficiently, we'll feed a network with standard mini-batches as we did for classification. The loss function will be responsible for selection of hard pairs and triplets within mini-batch. If we feed the network with 16 images per 10 classes, we can process up to 159\\*160\u002F2 = 12720 pairs and 10\\*16\\*15\u002F2\\*(9\\*16) = 172800 triplets, compared to 80 pairs and 53 triplets in previous implementation.\n\nUsually it's not the best idea to process all possible pairs or triplets within a mini-batch. We can find some strategies on how to select triplets in [2] and [3].\n\n### Online pair selection\n\nWe'll feed a network with mini-batches, as we did for classification network. This time we'll use a special BatchSampler that will sample *n_classes* and *n_samples* within each class, resulting in mini batches of size *n_classes\\*n_samples*.\n\nFor each mini batch positive and negative pairs will be selected using provided labels.\n\nMNIST is a rather easy dataset and the embeddings from the randomly selected pairs were quite good already, we don't see much improvement here.\n\n**Train embeddings:**\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_25571d21226c.png)\n\n**Test embeddings:**\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_0f443ec0ded6.png)\n\n### Online triplet selection\n\nWe'll feed a network with mini-batches just like with online pair selection. There are couple of strategies we can use for triplet selection given labels and predicted embeddings:\n\n- All possible triplets (might be too many)\n- Hardest negative for each positive pair (will result in the same negative for each anchor)\n- Random hard negative for each positive pair (consider only triplets with positive triplet loss value)\n- Semi-hard negative for each positive pair (similar to [2])\n\nThe strategy for triplet selection must be chosen carefully. A bad strategy might lead to inefficient training or, even worse, to model collapsing (all embeddings ending up having the same values).\n\nHere's what we got with random hard negatives for each positive pair.\n\n**Training set:**\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_1c32c29819f2.png)\n\n**Test set:**\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_81db05b63c9d.png)\n\n# FashionMNIST\n\nSimilar experiments were conducted for [FashionMNIST](https:\u002F\u002Fgithub.com\u002Fzalandoresearch\u002Ffashion-mnist) dataset where advantages of online negative mining are slightly more visible. The exact same network architecture with only 2-dimensional embeddings was used, which is probably not complex enough for learning good embeddings.\nMore complex datasets with higher number classses should benefit even more from online mining.\n\n## Baseline - classification\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_744495428260.png)\n\n## Siamese vs online contrastive loss with negative mining\n\nSiamese network with randomly selected pairs\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_2aa828a257f5.png)\n\nOnline contrastive loss with negative mining\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_fd253572405f.png)\n\n## Triplet vs online triplet loss with negative mining\n\nTriplet network with random triplets\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_7ab8ea09bb69.png)\n\nOnline triplet loss with negative mining\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_6f23f7ade50c.png)\n\n# TODO\n\n- [ ] Optimize triplet selection\n- [ ] Evaluate with a metric that is comparable between approaches\n- [ ] Evaluate in one-shot setting when classes from test set are not in train set\n- [ ] Show online triplet selection example on more difficult datasets\n\n# References\n\n[1] Raia Hadsell, Sumit Chopra, Yann LeCun, [Dimensionality reduction by learning an invariant mapping](http:\u002F\u002Fyann.lecun.com\u002Fexdb\u002Fpublis\u002Fpdf\u002Fhadsell-chopra-lecun-06.pdf), CVPR 2006\n\n[2] Schroff, Florian, Dmitry Kalenichenko, and James Philbin. [Facenet: A unified embedding for face recognition and clustering.](https:\u002F\u002Farxiv.org\u002Fabs\u002F1503.03832) CVPR 2015\n\n[3] Alexander Hermans, Lucas Beyer, Bastian Leibe, [In Defense of the Triplet Loss for Person Re-Identification](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1703.07737), 2017\n\n[4] Brandon Amos, Bartosz Ludwiczuk, Mahadev Satyanarayanan, [OpenFace: A general-purpose face recognition library with mobile applications](http:\u002F\u002Freports-archive.adm.cs.cmu.edu\u002Fanon\u002F2016\u002FCMU-CS-16-118.pdf), 2016\n\n[5] Yi Sun, Xiaogang Wang, Xiaoou Tang, [Deep Learning Face Representation by Joint Identification-Verification](http:\u002F\u002Fpapers.nips.cc\u002Fpaper\u002F5416-deep-learning-face-representation-by-joint-identification-verification), NIPS 2014\n","# 基于在线成对\u002F三元组挖掘的暹罗网络和三元组网络学习\n\n用于学习嵌入表示的暹罗网络和三元组网络的 PyTorch 实现。\n\n暹罗网络和三元组网络可用于学习从图像到紧凑欧几里得空间的映射，其中距离对应于相似度度量[2]。以这种方式训练得到的嵌入可以作为分类或少样本学习任务的特征向量使用。\n\n# 安装\n\n需要 [PyTorch](http:\u002F\u002Fpytorch.org\u002F) 0.4 和 torchvision 0.2.1。\n\n若需兼容 PyTorch 0.3，请检出标签 torch-0.3.1。\n\n# 代码结构\n\n- **datasets.py**\n  - *SiameseMNIST* 类 - MNIST 类似数据集的包装器，返回随机的正负样本对。\n  - *TripletMNIST* 类 - MNIST 类似数据集的包装器，返回随机三元组（锚点、正样本和负样本）。\n  - *BalancedBatchSampler* 类 - 数据加载器的批采样器，根据标签从每个类别中随机选择 *n_classes* 个类别和 *n_samples* 个样本。\n- **networks.py**\n  - *EmbeddingNet* - 用于将图像编码为嵌入向量的基础网络。\n  - *ClassificationNet* - 嵌入网络的包装器，添加全连接层和 log softmax 用于分类。\n  - *SiameseNet* - 嵌入网络的包装器，处理输入的成对样本。\n  - *TripletNet* - 嵌入网络的包装器，处理输入的三元组样本。\n- **losses.py**\n  - *ContrastiveLoss* - 针对嵌入对及其目标（相同\u002F不同）的对比损失。\n  - *TripletLoss* - 针对嵌入三元组的三元组损失。\n  - *OnlineContrastiveLoss* - 针对一小批嵌入的对比损失。使用 *PairSelector* 对象根据真实类别标签在小批量中查找正负样本对，并计算这些样本对的对比损失。\n  - *OnlineTripletLoss* - 针对一小批嵌入的三元组损失。使用 *TripletSelector* 对象根据真实类别标签在小批量中查找三元组，并计算三元组损失。\n- **trainer.py**\n  - *fit* - 用于训练具有不同输入数量和不同类型损失函数的网络的统一函数。\n- **metrics.py**\n  - 可与 *trainer.py* 中的 *fit* 函数一起使用的示例指标。\n- **utils.py**\n  - *PairSelector* - 定义基于嵌入和真实类别标签生成样本对的抽象类。可与 *OnlineContrastiveLoss* 一起使用。\n    - *AllPositivePairSelector, HardNegativePairSelector* - PairSelector 的具体实现。\n  - *TripletSelector* - 定义基于嵌入和真实类别标签生成三元组的抽象类。可与 *OnlineTripletLoss* 一起使用。\n    - *AllTripletSelector*, *HardestNegativeTripletSelector*, *RandomNegativeTripletSelector*, *SemihardNegativeTripletSelector* - TripletSelector 的具体实现。\n\n# 示例 - MNIST\n\n我们将在 MNIST 数据集上训练嵌入。实验是在 [jupyter notebook](Experiments_MNIST.ipynb) 中进行的。\n\n我们将通过 MNIST 数据集，使用不同的损失函数来学习监督式特征嵌入。这里仅用于可视化目的，因此我们使用的是二维嵌入，这在实际应用中并不是最佳选择。\n\n对于每个实验，我们都使用相同的嵌入网络（32 个 5x5 卷积 -> PReLU -> 2x2 最大池化 -> 64 个 5x5 卷积 -> PReLU -> 2x2 最大池化 -> 全连接 256 -> PReLU -> 全连接 256 -> PReLU -> 全连接 2），并且没有进行超参数搜索。\n\n## 基线 - 使用 softmax 的分类\n\n我们添加一个与类别数相等的全连接层，并使用 softmax 和交叉熵损失训练网络进行分类。网络最终达到约 99% 的准确率。我们从倒数第二层提取 2 维嵌入：\n\n训练集：\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_6d5ce2a61984.png)\n\n测试集：\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_3714850c8945.png)\n\n虽然这些嵌入看起来是可分的（这也是我们训练它们的目的），但它们并不具备良好的度量特性。因此，它们可能不适合作为新类别的描述符。\n\n## 暹罗网络\n\n现在我们将训练一个暹罗网络，该网络接收一对图像，并训练嵌入使得来自同一类别的图像之间的距离尽可能小，而来自不同类别的图像之间的距离则大于某个边界值。\n\n我们将最小化对比损失函数 [1]：\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_ba81080ff52c.png)\n\n*SiameseMNIST* 类会随机采样正负样本对，然后将其输入暹罗网络。\n\n经过 20 个 epoch 的训练后，我们在训练集上得到了以下嵌入：\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_1b93eb6945fe.png)\n\n测试集：\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_4016107a03fd.png)\n\n训练得到的嵌入在同类内部聚类得更好。\n\n## 三元组网络\n\n我们将训练一个三元组网络，该网络接收一个锚点样本、一个与其同属一类的正样本以及一个属于不同类别的负样本。目标是学习一种嵌入，使得锚点样本与正样本的距离比与负样本的距离更近，并且两者之间存在一定的边界值。\n\n![alt text](images\u002Fanchor_negative_positive.png \"来源: FaceNet\")\n来源: *Schroff, Florian, Dmitry Kalenichenko, and James Philbin. [Facenet: A unified embedding for face recognition and clustering.](https:\u002F\u002Farxiv.org\u002Fabs\u002F1503.03832) CVPR 2015.*\n\n**三元组损失**:   ![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_ef0ad08aa45e.png)\n\n*TripletMNIST* 类会为每一个可能的锚点样本随机采样正负样本。\n\n经过 20 个 epoch 的训练后，我们在训练集上得到了以下嵌入：\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_f12b9cb98bb5.png)\n\n测试集：\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_8770e8ef72d2.png)\n\n训练得到的嵌入在同类内部并不像暹罗网络那样紧密，但这并不是我们优化的目标。我们希望嵌入与同类别中的其他嵌入相比，与不同类别的嵌入距离更远，而从结果来看，训练确实朝着这个方向发展。\n\n## 在线对\u002F三元组选择——负样本挖掘\n\n暹罗网络和三元组网络存在几个问题：\n1. **可能的对\u002F三元组数量**会随着样本数量的增加而呈**二次方\u002F三次方增长**。处理所有这些对\u002F三元组是不现实的，且训练收敛速度很慢。\n2. 先前我们是*随机*生成对\u002F三元组的。随着训练的进行，越来越多的对\u002F三元组变得*容易*（损失值非常小甚至为0），这*阻碍了网络的学习*。我们需要为网络提供**难样本**。\n3. 每张输入到网络中的图像仅用于计算一个对或三元组的对比损失\u002F三元组损失。这种计算有些浪费；一旦嵌入被计算出来，它本可以被复用于许多对\u002F三元组。\n\n为了高效地解决这些问题，我们将像分类任务那样向网络输入标准的小批量数据。损失函数将负责在小批量内选择难样本对和三元组。如果我们每批次输入16张来自10个类别的图像，那么可以处理多达159×160\u002F2 = 12,720个对，以及10×16×15\u002F2×(9×16) = 172,800个三元组，相比之下，在之前的实现中只能处理80个对和53个三元组。\n\n通常情况下，处理小批量内的所有可能对或三元组并不是最佳方案。关于如何选择三元组，可以在文献[2]和[3]中找到一些策略。\n\n### 在线对选择\n\n我们将像训练分类网络一样，向网络输入小批量数据。这一次，我们会使用一种特殊的BatchSampler，它会在每个类别中采样*n_classes*个类别和*n_samples*个样本，从而得到大小为*n_classes×n_samples*的小批量。\n\n对于每个小批量，将根据提供的标签选择正样本对和负样本对。\n\nMNIST数据集相对简单，从随机选择的样本对中得到的嵌入已经相当不错，因此在这里我们并没有看到明显的改进。\n\n**训练集嵌入：**\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_25571d21226c.png)\n\n**测试集嵌入：**\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_0f443ec0ded6.png)\n\n### 在线三元组选择\n\n我们将像在线对选择那样，向网络输入小批量数据。给定标签和预测的嵌入，我们可以采用几种不同的三元组选择策略：\n- 所有可能的三元组（可能会太多）\n- 每个正样本对中最难的负样本（会导致每个锚点对应相同的负样本）\n- 每个正样本对中随机选择的难负样本（只考虑三元组损失为正的情况）\n- 每个正样本对中半难的负样本（类似于文献[2]中的方法）\n\n三元组选择策略必须谨慎选择。如果策略不当，可能会导致训练效率低下，甚至更糟的是模型坍塌（所有嵌入最终都变为相同的值）。\n\n以下是针对每个正样本对随机选择难负样本的结果。\n\n**训练集：**\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_1c32c29819f2.png)\n\n**测试集：**\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_81db05b63c9d.png)\n\n# FashionMNIST\n\n类似的实验也在[FashionMNIST](https:\u002F\u002Fgithub.com\u002Fzalandoresearch\u002Ffashion-mnist)数据集上进行了，其中在线负样本挖掘的优势更加明显。我们使用了完全相同的网络架构，但嵌入维度仅为2维，这可能不足以学习到良好的嵌入表示。对于类别数更多、数据集更复杂的场景，采用在线挖掘的方法将会带来更大的收益。\n\n## 基线——分类任务\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_744495428260.png)\n\n## 暹罗网络与带负样本挖掘的在线对比损失\n\n暹罗网络，随机选择样本对\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_2aa828a257f5.png)\n\n带负样本挖掘的在线对比损失\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_fd253572405f.png)\n\n## 三元组网络与带负样本挖掘的在线三元组损失\n\n三元组网络，随机选择三元组\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_7ab8ea09bb69.png)\n\n带负样本挖掘的在线三元组损失\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_readme_6f23f7ade50c.png)\n\n# 待办事项\n\n- [ ] 优化三元组选择策略\n- [ ] 使用可比较不同方法的指标进行评估\n- [ ] 在测试集中包含训练集未出现的类别时，进行一次-shot设置下的评估\n- [ ] 展示在更复杂数据集上的在线三元组选择示例\n\n# 参考文献\n\n[1] Raia Hadsell, Sumit Chopra, Yann LeCun，《通过学习不变映射进行降维》（http:\u002F\u002Fyann.lecun.com\u002Fexdb\u002Fpublis\u002Fpdf\u002Fhadsell-chopra-lecun-06.pdf），CVPR 2006\n\n[2] Schroff, Florian, Dmitry Kalenichenko, and James Philbin，《FaceNet：用于人脸识别和聚类的统一嵌入》（https:\u002F\u002Farxiv.org\u002Fabs\u002F1503.03832），CVPR 2015\n\n[3] Alexander Hermans, Lucas Beyer, Bastian Leibe，《为行人再识别辩护：关于三元组损失的思考》（https:\u002F\u002Farxiv.org\u002Fpdf\u002F1703.07737），2017年\n\n[4] Brandon Amos, Bartosz Ludwiczuk, Mahadev Satyanarayanan，《OpenFace：一个通用的人脸识别库及其移动应用》（http:\u002F\u002Freports-archive.adm.cs.cmu.edu\u002Fanon\u002F2016\u002FCMU-CS-16-118.pdf），2016年\n\n[5] Yi Sun, Xiaogang Wang, Xiaoou Tang，《通过联合识别-验证进行深度学习人脸表征》（http:\u002F\u002Fpapers.nips.cc\u002Fpaper\u002F5416-deep-learning-face-representation-by-joint-identification-verification），NIPS 2014","# Siamese-Triplet 快速上手指南\n\n本指南基于 `siamese-triplet` 开源项目，帮助开发者快速搭建孪生网络（Siamese Network）和三元组网络（Triplet Network），用于学习图像的紧凑嵌入向量（Embeddings）。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**：Linux \u002F macOS \u002F Windows\n*   **Python 版本**：建议 Python 3.6+\n*   **核心依赖**：\n    *   PyTorch >= 0.4 (推荐最新稳定版)\n    *   torchvision >= 0.2.1\n*   **可选依赖**：Jupyter Notebook (用于运行示例实验)\n\n> **注意**：如果您使用的是较旧的 PyTorch 0.3 版本，请检出 `torch-0.3.1` 标签。\n\n## 安装步骤\n\n### 1. 克隆仓库\n首先从 GitHub 获取源代码：\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fadambielski\u002Fsiamese-triplet.git\ncd siamese-triplet\n```\n\n### 2. 安装依赖\n推荐使用国内镜像源加速安装 PyTorch 及相关依赖。以下命令使用清华源安装所需包：\n\n```bash\npip install torch torchvision -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n如果项目中包含 `requirements.txt`，也可以直接安装：\n\n```bash\npip install -r requirements.txt -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n## 基本使用\n\n该项目主要用于通过不同的损失函数（对比损失、三元组损失）在 MNIST 数据集上训练嵌入网络。以下是基于提供的代码结构进行简单使用的流程。\n\n### 1. 导入核心模块\n在您的 Python 脚本或 Jupyter Notebook 中，导入必要的类：\n\n```python\nfrom datasets import SiameseMNIST, TripletMNIST, BalancedBatchSampler\nfrom networks import EmbeddingNet, SiameseNet, TripletNet\nfrom losses import OnlineContrastiveLoss, OnlineTripletLoss\nfrom utils import AllTripletSelector, HardestNegativeTripletSelector\nfrom trainer import fit\n```\n\n### 2. 定义网络架构\n创建一个基础的嵌入网络（参考 README 中的 MNIST 示例架构）：\n\n```python\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nclass EmbeddingNet(nn.Module):\n    def __init__(self):\n        super(EmbeddingNet, self).__init__()\n        self.convnet = nn.Sequential(\n            nn.Conv2d(1, 32, 5), nn.PReLU(), nn.MaxPool2d(2, 2),\n            nn.Conv2d(32, 64, 5), nn.PReLU(), nn.MaxPool2d(2, 2)\n        )\n        self.fc = nn.Sequential(\n            nn.Linear(64 * 4 * 4, 256), nn.PReLU(),\n            nn.Linear(256, 256), nn.PReLU(),\n            nn.Linear(256, 2) # 输出 2 维向量以便可视化\n        )\n\n    def forward(self, x):\n        x = self.convnet(x)\n        x = x.view(x.size(0), -1)\n        x = self.fc(x)\n        return x\n```\n\n### 3. 包装网络与选择损失函数\n根据任务需求选择孪生网络或三元组网络，并配置在线挖掘（Online Mining）策略：\n\n**示例：使用三元组网络进行在线难例挖掘**\n\n```python\n# 实例化基础网络\nbase_network = EmbeddingNet()\n\n# 包装为三元组网络\ntriplet_net = TripletNet(base_network)\n\n# 定义损失函数：使用在线三元组选择器（例如：随机硬负样本）\nloss_fn = OnlineTripletLoss(margin=1.0, triplet_selector=RandomNegativeTripletSelector(margin=1.0))\n# 注意：需从 utils 导入具体的 Selector 类，如 RandomNegativeTripletSelector\n```\n\n### 4. 准备数据加载器\n使用 `BalancedBatchSampler` 确保每个批次中包含均衡的类别和样本，这对于在线挖掘至关重要：\n\n```python\nfrom torch.utils.data import DataLoader\n\n# 假设已加载 MNIST 数据集 train_dataset\nn_classes = 10\nn_samples = 16\n\nbatch_sampler = BalancedBatchSampler(train_dataset.targets, n_classes=n_classes, n_samples=n_samples)\ndata_loader = DataLoader(train_dataset, batch_sampler=batch_sampler)\n```\n\n### 5. 开始训练\n使用统一的 `fit` 函数启动训练：\n\n```python\n# 定义优化器\noptimizer = torch.optim.Adam(triplet_net.parameters(), lr=0.001)\n\n# 开始训练 (epochs, data_loader, model, loss_fn, optimizer, metrics)\nfit(epochs=20, \n    train_loader=data_loader, \n    model=triplet_net, \n    loss_fn=loss_fn, \n    optimizer=optimizer, \n    metrics=[]) \n```\n\n训练完成后，您可以提取 `base_network` 生成的嵌入向量，用于分类、聚类或少样本学习（Few-shot Learning）任务。详细的实验代码和可视化结果请参考项目中的 `Experiments_MNIST.ipynb`。","某电商初创公司的算法团队正致力于构建一个能识别新款商品相似度的推荐系统，但面临新上架商品缺乏历史点击数据的冷启动难题。\n\n### 没有 siamese-triplet 时\n- **依赖大量标注数据**：传统分类模型需要为每个新商品类别收集成百上千张标注图片才能训练，新品上线即“失明”，无法立即参与推荐。\n- **相似度度量不准**：直接使用预训练模型的通用特征向量，导致在欧氏空间中“视觉相似”的商品（如不同款式的白衬衫）距离过远，召回率极低。\n- **挖掘效率低下**：人工构造正负样本对耗时耗力，且难以动态筛选出那些“看似相似实则不同”的困难负样本，模型收敛慢且区分度差。\n- **泛化能力薄弱**：模型死记硬背已知类别的特征，一旦遇到未见过的新品类或细粒度差异（如领口微差），表现大幅下滑。\n\n### 使用 siamese-triplet 后\n- **实现小样本学习**：利用 siamese-triplet 构建孪生网络，仅需少量样本即可将商品映射到紧凑的嵌入空间，新品上架当天即可基于图像相似度进行精准推荐。\n- **优化距离度量**：通过 TripletLoss 强制拉近同款商品（Anchor-Positive）距离、推远不同款商品（Anchor-Negative）距离，确保空间距离直接反映视觉相似度。\n- **自动在线挖掘**：借助内置的 OnlineTripletLoss 和 HardNegativePairSelector，在训练批次中自动实时挖掘最具挑战性的困难样本，显著提升模型对细微差异的辨别力。\n- **强泛化特性**：学到的嵌入向量具有通用的度量属性，无需重新训练即可直接作为特征向量，服务于新品分类、以图搜图等多种下游任务。\n\nsiamese-triplet 通过将图像转化为具有严格度量性质的嵌入向量，让机器真正学会了“像人类一样比较异同”，彻底解决了小样本场景下的相似性匹配难题。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fadambielski_siamese-triplet_6d5ce2a6.png","adambielski","Adam Bielski","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fadambielski_d8be0e86.jpg","PhD Candidate @ University of Bern, Computer Vision Group\r\nAI \u002F ML \u002F DL \u002F CV","University of Bern","Bern",null,"bielskiadam","adambielski.github.io","https:\u002F\u002Fgithub.com\u002Fadambielski",[83],{"name":84,"color":85,"percentage":86},"Python","#3572A5",100,3169,633,"2026-04-02T08:36:50","BSD-3-Clause","","未说明",{"notes":94,"python":92,"dependencies":95},"该工具版本较旧，明确要求使用 PyTorch 0.4 和 torchvision 0.2.1。若需兼容 PyTorch 0.3，需检出 torch-0.3.1 标签。README 中未提及具体的操作系统、GPU 型号、显存大小或内存需求。示例实验基于 MNIST 数据集并使用 2 维嵌入进行可视化，实际应用中可能需要调整网络架构。",[96,97],"pytorch==0.4","torchvision==0.2.1",[14],[100,101,102,103,104,105,106,107,108],"machine-learning","deep-learning","siamese-network","triplet-loss","contrastive-loss","pytorch","embedding","triplet-network","learning-embeddings","2026-03-27T02:49:30.150509","2026-04-11T08:13:07.884543",[112,117,122,127,132,137,141],{"id":113,"question_zh":114,"answer_zh":115,"source_url":116},29092,"如何使用自己的数据集训练网络？","你需要完成以下步骤：\n1. 创建一个自定义的 Dataset 类，实现 `__len__` 和 `__getitem__(index)` 方法。`__getitem__` 应返回图像和标签的对组。\n2. 使用 BalancedBatchSampler，它需要传入数据集中所有标签的列表（顺序需与 Dataset 索引对应）。获取标签列表的低效方式是：`labels = [dataset[i][1] for i in range(len(dataset))]`，假设你的 `__getitem__` 返回的是 (image, label)。\n如果是使用在线三元组采样（online triplet sampling），则只需确保标签列表正确传递给采样器即可。","https:\u002F\u002Fgithub.com\u002Fadambielski\u002Fsiamese-triplet\u002Fissues\u002F12",{"id":118,"question_zh":119,"answer_zh":120,"source_url":121},29093,"为什么使用普通 ReLU 激活函数时模型无法训练？","普通 ReLU 会导致训练损失卡在 2.3（相当于随机猜测），原因可能是输出被限制在第一象限，对网络来说约束过强。解决方案包括：\n1. 将初始学习率降低至 1e-3，可使纯 ReLU 网络可训练，但收敛效果仍不如 PReLU。\n2. 在所有层使用普通 ReLU，仅在分类网络的最后一层非线性部分改用 PReLU，并使用默认初始化，这样能更快收敛并获得更好的嵌入效果。","https:\u002F\u002Fgithub.com\u002Fadambielski\u002Fsiamese-triplet\u002Fissues\u002F17",{"id":123,"question_zh":124,"answer_zh":125,"source_url":126},29094,"训练好的三元组网络如何在生产环境中使用？如何计算相似度？","三元组网络在训练时需要输入三个样本（Anchor, Positive, Negative），但在推理阶段不需要再输入三元组。实际使用时：\n1. 只使用嵌入网络（EmbeddingNet）将单个样本映射为嵌入向量。\n2. 通过计算两个嵌入向量之间的距离（如欧氏距离或余弦相似度）来判断相似性。\n3. 可设定一个阈值，若距离小于该阈值则认为属于同一类。\n注意：三元组损失本身不直接输出 [0,1] 的相似度分数，如需连续相似度值（如 0~5），需基于嵌入距离进行后处理映射。","https:\u002F\u002Fgithub.com\u002Fadambielski\u002Fsiamese-triplet\u002Fissues\u002F1",{"id":128,"question_zh":129,"answer_zh":130,"source_url":131},29095,"使用 OnlineTripletLoss 时出现 'forward() takes 3 positional arguments but 4 were given' 错误怎么办？","这是因为错误地使用了 TripletNetwork 而非 EmbeddingNet。正确做法是：\n- 当使用 OnlineTripletLoss 时，应使用 EmbeddingNet（单输入单输出），先对一批图像生成嵌入向量。\n- 然后利用标签和三元组选择器（triplet selector）在嵌入空间中动态构建三元组并计算损失。\n- TripletNetwork 适用于预采样三元组的场景，而 OnlineTripletLoss 需要在网络内部动态采样，因此必须配合 EmbeddingNet 使用。","https:\u002F\u002Fgithub.com\u002Fadambielski\u002Fsiamese-triplet\u002Fissues\u002F50",{"id":133,"question_zh":134,"answer_zh":135,"source_url":136},29096,"嵌入向量是否进行了归一化（||x||=1）？推荐使用哪种网络结构？","项目中实现了 EmbeddingNetL2 用于 L2 归一化（使 ||embed||=1），但默认笔记本中使用的是未归一化的 EmbeddingNet，因为可视化效果更好。尽管如此，使用归一化嵌入通常更有益。\n若使用 EmbeddingNetL2 遇到 inplace 操作导致的梯度计算错误（RuntimeError: ... modified by an inplace operation），请将代码中的 inplace 操作改为非 inplace 形式，例如将 `output \u002F= ...` 改为 `output = output \u002F ...`。","https:\u002F\u002Fgithub.com\u002Fadambielski\u002Fsiamese-triplet\u002Fissues\u002F51",{"id":138,"question_zh":139,"answer_zh":140,"source_url":136},29097,"对于 EmbeddingNetL2，推荐的 margin 值是多少？","margin 值理想情况下应通过交叉验证确定。作为起点，0.2 是一个合理的默认值，这与 FaceNet 论文中的设置一致。具体取值可能依赖于嵌入向量的维度，建议根据实际任务进行调整。",{"id":142,"question_zh":143,"answer_zh":144,"source_url":145},29098,"该项目是否支持具有数万类别的大规模数据集？","作者目前没有计划在该仓库中添加包含 10K~100K 类别的大型数据集示例。现有示例（如 MNIST）仅用于展示方法原理和使用方式。对于大规模数据集，用户可以参考此框架自行扩展，但需注意显存和计算资源限制（例如在单 GPU 上训练约 100K 样本、10K 类别的数据集是可行的）。","https:\u002F\u002Fgithub.com\u002Fadambielski\u002Fsiamese-triplet\u002Fissues\u002F48",[]]