[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-EdjeElectronics--TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10":3,"tool-EdjeElectronics--TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10":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 真正成长为懂上",159636,2,"2026-04-17T23:33:34",[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":86,"forks":87,"last_commit_at":88,"license":89,"difficulty_score":90,"env_os":91,"env_gpu":92,"env_ram":93,"env_deps":94,"category_tags":107,"github_topics":108,"view_count":32,"oss_zip_url":108,"oss_zip_packed_at":108,"status":17,"created_at":109,"updated_at":110,"faqs":111,"releases":140},8867,"EdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10","TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10","How to train a TensorFlow Object Detection Classifier for multiple object detection on Windows","TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10 是一份详尽的实战教程，旨在指导用户在 Windows 系统上利用 TensorFlow 对象检测 API 训练能够识别多种目标的自定义分类器。它主要解决了开发者在配置复杂的深度学习环境（如 Anaconda、CUDA 和 cuDNN）、准备标注数据以及执行模型训练流程时遇到的门槛高、步骤繁琐等痛点。\n\n这份资源特别适合希望在 Windows 平台上入门计算机视觉的开发者、学生及研究人员。即便你使用的是 Linux 系统，稍作调整也能参考使用。教程的独特亮点在于其“手把手”式的引导风格，不仅提供了完整的代码示例和用于测试的皮诺克牌（Pinochle）数据集，还涵盖了从环境搭建、数据标注、生成训练集到最终导出推理图并测试模型的全流程八个关键步骤。此外，作者还提供了配套的 YouTube 视频演示，并针对常见报错整理了附录，帮助用户更顺畅地完成从零到一的模型定制，轻松实现对自己感兴趣物体的智能识别。","# How To Train an Object Detection Classifier for Multiple Objects Using TensorFlow (GPU) on Windows 10\n\n## Brief Summary\n*Last updated: 6\u002F22\u002F2019 with TensorFlow v1.13.1*\n\nThis repository is a tutorial for how to use TensorFlow's Object Detection API to train an object detection classifier for multiple objects on Windows 10, 8, or 7. (It will also work on Linux-based OSes with some minor changes.) It was originally written using TensorFlow version 1.5, but will also work for newer versions of TensorFlow.\n\nTranslated versions of this guide are listed below. If you would like to contribute a translation in another language, please feel free! You can add it as a pull request and I will merge it when I get the chance.\n* [Korean translation](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10\u002Fblob\u002Fmaster\u002Ftranslate\u002FREADME_Korean.md) (thanks @cocopambag!)\n* [Chinese translation](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10\u002Fblob\u002Fmaster\u002Ftranslate\u002FREADME_Chinese.md) (thanks @Marco-Ray!)\n* [Vietnamese translation](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10\u002Fblob\u002Fmaster\u002Ftranslate\u002FREADME_Vietnamese.md) (thanks @winter2897!)\n\nI also made a YouTube video that walks through this tutorial. Any discrepancies between the video and this written tutorial are due to updates required for using newer versions of TensorFlow. \n\n**If there are differences between this written tutorial and the video, follow the written tutorial!**\n\n[![Link to my YouTube video!](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_201e6a37ea22.jpg)](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=Rgpfk6eYxJA)\n\nThis readme describes every step required to get going with your own object detection classifier: \n1. [Installing Anaconda, CUDA, and cuDNN](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#1-install-anaconda-cuda-and-cudnn)\n2. [Setting up the Object Detection directory structure and Anaconda Virtual Environment](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#2-set-up-tensorflow-directory-and-anaconda-virtual-environment)\n3. [Gathering and labeling pictures](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#3-gather-and-label-pictures)\n4. [Generating training data](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#4-generate-training-data)\n5. [Creating a label map and configuring training](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#5-create-label-map-and-configure-training)\n6. [Training](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#6-run-the-training)\n7. [Exporting the inference graph](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#7-export-inference-graph)\n8. [Testing and using your newly trained object detection classifier](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#8-use-your-newly-trained-object-detection-classifier)\n\n[Appendix: Common Errors](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#appendix-common-errors)\n\nThe repository provides all the files needed to train a \"Pinochle Deck\" playing card detector that can accurately detect nines, tens, jacks, queens, kings, and aces. The tutorial describes how to replace these files with your own files to train a detection classifier for whatever your heart desires. It also has Python scripts to test your classifier out on an image, video, or webcam feed.\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_0805cf0a43c7.jpg\">\n\u003C\u002Fp>\n\n## Introduction\nThe purpose of this tutorial is to explain how to train your own convolutional neural network object detection classifier for multiple objects, starting from scratch. At the end of this tutorial, you will have a program that can identify and draw boxes around specific objects in pictures, videos, or in a webcam feed.\n\nThere are several good tutorials available for how to use TensorFlow’s Object Detection API to train a classifier for a single object. However, these usually assume you are using a Linux operating system. If you’re like me, you might be a little hesitant to install Linux on your high-powered gaming PC that has the sweet graphics card you’re using to train a classifier. The Object Detection API seems to have been developed on a Linux-based OS. To set up TensorFlow to train a model on Windows, there are several workarounds that need to be used in place of commands that would work fine on Linux. Also, this tutorial provides instructions for training a classifier that can detect multiple objects, not just one.\n\nThe tutorial is written for Windows 10, and it will also work for Windows 7 and 8. The general procedure can also be used for Linux operating systems, but file paths and package installation commands will need to change accordingly. I used TensorFlow-GPU v1.5 while writing the initial version of this tutorial, but it will likely work for future versions of TensorFlow.\n\nTensorFlow-GPU allows your PC to use the video card to provide extra processing power while training, so it will be used for this tutorial. In my experience, using TensorFlow-GPU instead of regular TensorFlow reduces training time by a factor of about 8 (3 hours to train instead of 24 hours). The CPU-only version of TensorFlow can also be used for this tutorial, but it will take longer. If you use CPU-only TensorFlow, you do not need to install CUDA and cuDNN in Step 1. \n\n## Steps\n### 1. Install Anaconda, CUDA, and cuDNN\nAnaconda is a software toolkit that creates virtual Python environments so you can install and use Python libraries without worrying about creating version conflicts with existing installations. Anaconda works well on Windows, and enables you to use many Python libraries that normally would only work on a Linux system. It provides a simple method for installing TensorFlow (which we'll do in Step 2d). It also automatically installs the CUDA and cuDNN versions you need for using TensorFlow on a GPU.\n\nDownload Anaconda for Windows from [their webpage](https:\u002F\u002Fwww.anaconda.com\u002Fproducts\u002Findividual) (you have to scroll down a ways to get to the download links). Once it's downloaded, execute the installer file and work through the installation steps.\n\nIf you are using a version of TensorFlow older than TF v1.13, make sure you use the CUDA and cuDNN versions that are compatible with the TensorFlow version you are using. [Here](https:\u002F\u002Fwww.tensorflow.org\u002Finstall\u002Fsource#tested_build_configurations) is a table showing which version of TensorFlow requires which versions of CUDA and cuDNN. Anaconda will automatically install the correct version of CUDA and cuDNN for the version of TensorFlow you are using, so you shouldn't have to worry about this.\n\n### 2. Set up TensorFlow Directory and Anaconda Virtual Environment\nThe TensorFlow Object Detection API requires using the specific directory structure provided in its GitHub repository. It also requires several additional Python packages, specific additions to the PATH and PYTHONPATH variables, and a few extra setup commands to get everything set up to run or train an object detection model. \n\nThis portion of the tutorial goes over the full set up required. It is fairly meticulous, but follow the instructions closely, because improper setup can cause unwieldy errors down the road.\n\n#### 2a. Download TensorFlow Object Detection API repository from GitHub\nCreate a folder directly in C: and name it “tensorflow1”. This working directory will contain the full TensorFlow object detection framework, as well as your training images, training data, trained classifier, configuration files, and everything else needed for the object detection classifier.\n\nDownload the full TensorFlow object detection repository located at https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels by clicking the “Clone or Download” button and downloading the zip file. Open the downloaded zip file and extract the “models-master” folder directly into the C:\\tensorflow1 directory you just created. Rename “models-master” to just “models”.\n\n**Note: The TensorFlow models repository's code (which contains the object detection API) is continuously updated by the developers. Sometimes they make changes that break functionality with old versions of TensorFlow. It is always best to use the latest version of TensorFlow and download the latest models repository. If you are not using the latest version, clone or download the commit for the version you are using as listed in the table below.**\n\n If you are using an older version of TensorFlow, here is a table showing which GitHub commit of the repository you should use. I generated this by going to the release branches for the models repository and getting the commit before the last commit for the branch. (They remove the research folder as the last commit before they create the official version release.)\n\n| TensorFlow version | GitHub Models Repository Commit |\n|--------------------|---------------------------------|\n|TF v1.7             |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fadfd5a3aca41638aa9fb297c5095f33d64446d8f |\n|TF v1.8             |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fabd504235f3c2eed891571d62f0a424e54a2dabc |\n|TF v1.9             |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fd530ac540b0103caa194b4824af353f1b073553b |\n|TF v1.10            |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fb07b494e3514553633b132178b4c448f994d59df |\n|TF v1.11            |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002F23b5b4227dfa1b23d7c21f0dfaf0951b16671f43 |\n|TF v1.12            |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fr1.12.0 |\n|TF v1.13            |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fr1.13.0 |\n|Latest version      |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels |\n\nThis tutorial was originally done using TensorFlow v1.5 and this [GitHub commit](https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002F079d67d9a0b3407e8d074a200780f3835413ef99) of the TensorFlow Object Detection API. If portions of this tutorial do not work, it may be necessary to install TensorFlow v1.5 and use this exact commit rather than the most up-to-date version.\n\n#### 2b. Download the Faster-RCNN-Inception-V2-COCO model from TensorFlow's model \nTensorFlow provides several object detection models (pre-trained classifiers with specific neural network architectures) in its [model zoo](https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Fblob\u002Fmaster\u002Fresearch\u002Fobject_detection\u002Fg3doc\u002Ftf1_detection_zoo.md). Some models (such as the SSD-MobileNet model) have an architecture that allows for faster detection but with less accuracy, while some models (such as the Faster-RCNN model) give slower detection but with more accuracy. I initially started with the SSD-MobileNet-V1 model, but it didn’t do a very good job identifying the cards in my images. I re-trained my detector on the Faster-RCNN-Inception-V2 model, and the detection worked considerably better, but with a noticeably slower speed.\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_8d590361ffad.jpg\">\n\u003C\u002Fp>\n\nYou can choose which model to train your objection detection classifier on. If you are planning on using the object detector on a device with low computational power (such as a smart phone or Raspberry Pi), use the SDD-MobileNet model. If you will be running your detector on a decently powered laptop or desktop PC, use one of the RCNN models. \n\nThis tutorial will use the Faster-RCNN-Inception-V2 model. [Download the model here.](http:\u002F\u002Fdownload.tensorflow.org\u002Fmodels\u002Fobject_detection\u002Ffaster_rcnn_inception_v2_coco_2018_01_28.tar.gz) Open the downloaded faster_rcnn_inception_v2_coco_2018_01_28.tar.gz file with a file archiver such as WinZip or 7-Zip and extract the faster_rcnn_inception_v2_coco_2018_01_28 folder to the C:\\tensorflow1\\models\\research\\object_detection folder. (Note: The model date and version will likely change in the future, but it should still work with this tutorial.)\n\n#### 2c. Download this tutorial's repository from GitHub\nDownload the full repository located on this page (scroll to the top and click Clone or Download) and extract all the contents directly into the C:\\tensorflow1\\models\\research\\object_detection directory. (You can overwrite the existing \"README.md\" file.) This establishes a specific directory structure that will be used for the rest of the tutorial. \n\nAt this point, here is what your \\object_detection folder should look like:\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_57d90ebb6609.jpg\">\n\u003C\u002Fp>\n\nThis repository contains the images, annotation data, .csv files, and TFRecords needed to train a \"Pinochle Deck\" playing card detector. You can use these images and data to practice making your own Pinochle Card Detector. It also contains Python scripts that are used to generate the training data. It has scripts to test out the object detection classifier on images, videos, or a webcam feed. You can ignore the \\doc folder and its files; they are just there to hold the images used for this readme.\n\nIf you want to practice training your own \"Pinochle Deck\" card detector, you can leave all the files as they are. You can follow along with this tutorial to see how each of the files were generated, and then run the training. You will still need to generate the TFRecord files (train.record and test.record) as described in Step 4. \n\nYou can also download the frozen inference graph for my trained Pinochle Deck card detector [from this Dropbox link](https:\u002F\u002Fwww.dropbox.com\u002Fs\u002Fva9ob6wcucusse1\u002Finference_graph.zip?dl=0) and extract the contents to \\object_detection\\inference_graph. This inference graph will work \"out of the box\". You can test it after all the setup instructions in Step 2a - 2f have been completed by running the Object_detection_image.py (or video or webcam) script.\n\nIf you want to train your own object detector, delete the following files (do not delete the folders):\n- All files in \\object_detection\\images\\train and \\object_detection\\images\\test\n- The “test_labels.csv” and “train_labels.csv” files in \\object_detection\\images\n- All files in \\object_detection\\training\n-\tAll files in \\object_detection\\inference_graph\n\nNow, you are ready to start from scratch in training your own object detector. This tutorial will assume that all the files listed above were deleted, and will go on to explain how to generate the files for your own training dataset.\n\n#### 2d. Set up new Anaconda virtual environment\nNext, we'll work on setting up a virtual environment in Anaconda for tensorflow-gpu. From the Start menu in Windows, search for the Anaconda Prompt utility, right click on it, and click “Run as Administrator”. If Windows asks you if you would like to allow it to make changes to your computer, click Yes.\n\nIn the command terminal that pops up, create a new virtual environment called “tensorflow1” by issuing the following command:\n```\nC:\\> conda create -n tensorflow1 pip python=3.5\n```\nThen, activate the environment and update pip by issuing:\n```\nC:\\> activate tensorflow1\n\n(tensorflow1) C:\\>python -m pip install --upgrade pip\n```\nInstall tensorflow-gpu in this environment by issuing:\n```\n(tensorflow1) C:\\> pip install --ignore-installed --upgrade tensorflow-gpu\n```\n\nSince we're using Anaconda, installing tensorflow-gpu will also automatically download and install the correct versions of CUDA and cuDNN.\n\n(Note: You can also use the CPU-only version of TensorFow, but it will run much slower. If you want to use the CPU-only version, just use \"tensorflow\" instead of \"tensorflow-gpu\" in the previous command.)\n\nInstall the other necessary packages by issuing the following commands:\n```\n(tensorflow1) C:\\> conda install -c anaconda protobuf\n(tensorflow1) C:\\> pip install pillow\n(tensorflow1) C:\\> pip install lxml\n(tensorflow1) C:\\> pip install Cython\n(tensorflow1) C:\\> pip install contextlib2\n(tensorflow1) C:\\> pip install jupyter\n(tensorflow1) C:\\> pip install matplotlib\n(tensorflow1) C:\\> pip install pandas\n(tensorflow1) C:\\> pip install opencv-python\n```\n(Note: The ‘pandas’ and ‘opencv-python’ packages are not needed by TensorFlow, but they are used in the Python scripts to generate TFRecords and to work with images, videos, and webcam feeds.)\n\n#### 2e. Configure PYTHONPATH environment variable\nA PYTHONPATH variable must be created that points to the \\models, \\models\\research, and \\models\\research\\slim directories. Do this by issuing the following commands (from any directory):\n```\n(tensorflow1) C:\\> set PYTHONPATH=C:\\tensorflow1\\models;C:\\tensorflow1\\models\\research;C:\\tensorflow1\\models\\research\\slim\n```\n(Note: Every time the \"tensorflow1\" virtual environment is exited, the PYTHONPATH variable is reset and needs to be set up again. You can use \"echo %PYTHONPATH% to see if it has been set or not.)\n\n#### 2f. Compile Protobufs and run setup.py\nNext, compile the Protobuf files, which are used by TensorFlow to configure model and training parameters. Unfortunately, the short protoc compilation command posted on TensorFlow’s Object Detection API [installation page](https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Fblob\u002Fmaster\u002Fresearch\u002Fobject_detection\u002Fg3doc\u002Finstallation.md) does not work on Windows. Every  .proto file in the \\object_detection\\protos directory must be called out individually by the command.\n\nIn the Anaconda Command Prompt, change directories to the \\models\\research directory:\n```\n(tensorflow1) C:\\> cd C:\\tensorflow1\\models\\research\n```\n\nThen copy and paste the following command into the command line and press Enter:\n```\nprotoc --python_out=. .\\object_detection\\protos\\anchor_generator.proto .\\object_detection\\protos\\argmax_matcher.proto .\\object_detection\\protos\\bipartite_matcher.proto .\\object_detection\\protos\\box_coder.proto .\\object_detection\\protos\\box_predictor.proto .\\object_detection\\protos\\eval.proto .\\object_detection\\protos\\faster_rcnn.proto .\\object_detection\\protos\\faster_rcnn_box_coder.proto .\\object_detection\\protos\\grid_anchor_generator.proto .\\object_detection\\protos\\hyperparams.proto .\\object_detection\\protos\\image_resizer.proto .\\object_detection\\protos\\input_reader.proto .\\object_detection\\protos\\losses.proto .\\object_detection\\protos\\matcher.proto .\\object_detection\\protos\\mean_stddev_box_coder.proto .\\object_detection\\protos\\model.proto .\\object_detection\\protos\\optimizer.proto .\\object_detection\\protos\\pipeline.proto .\\object_detection\\protos\\post_processing.proto .\\object_detection\\protos\\preprocessor.proto .\\object_detection\\protos\\region_similarity_calculator.proto .\\object_detection\\protos\\square_box_coder.proto .\\object_detection\\protos\\ssd.proto .\\object_detection\\protos\\ssd_anchor_generator.proto .\\object_detection\\protos\\string_int_label_map.proto .\\object_detection\\protos\\train.proto .\\object_detection\\protos\\keypoint_box_coder.proto .\\object_detection\\protos\\multiscale_anchor_generator.proto .\\object_detection\\protos\\graph_rewriter.proto .\\object_detection\\protos\\calibration.proto .\\object_detection\\protos\\flexible_grid_anchor_generator.proto\n```\nThis creates a name_pb2.py file from every name.proto file in the \\object_detection\\protos folder.\n\n**(Note: TensorFlow occassionally adds new .proto files to the \\protos folder. If you get an error saying ImportError: cannot import name 'something_something_pb2' , you may need to update the protoc command to include the new .proto files.)**\n\nFinally, run the following commands from the C:\\tensorflow1\\models\\research directory:\n```\n(tensorflow1) C:\\tensorflow1\\models\\research> python setup.py build\n(tensorflow1) C:\\tensorflow1\\models\\research> python setup.py install\n```\n\n#### 2g. Test TensorFlow setup to verify it works\nThe TensorFlow Object Detection API is now all set up to use pre-trained models for object detection, or to train a new one. You can test it out and verify your installation is working by launching the object_detection_tutorial.ipynb script with Jupyter. From the \\object_detection directory, issue this command:\n```\n(tensorflow1) C:\\tensorflow1\\models\\research\\object_detection> jupyter notebook object_detection_tutorial.ipynb\n```\nThis opens the script in your default web browser and allows you to step through the code one section at a time. You can step through each section by clicking the “Run” button in the upper toolbar. The section is done running when the “In [ * ]” text next to the section populates with a number (e.g. “In [1]”). \n\n(Note: part of the script downloads the ssd_mobilenet_v1 model from GitHub, which is about 74MB. This means it will take some time to complete the section, so be patient.)\n\nOnce you have stepped all the way through the script, you should see two labeled images at the bottom section the page. If you see this, then everything is working properly! If not, the bottom section will report any errors encountered. See the [Appendix](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#appendix-common-errors) for a list of errors I encountered while setting this up.\n\n**Note: If you run the full Jupyter Notebook without getting any errors, but the labeled pictures still don't appear, try this: go in to object_detection\u002Futils\u002Fvisualization_utils.py and comment out the import statements around lines 29 and 30 that include matplotlib. Then, try re-running the Jupyter notebook.**\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_3150e6f30a05.jpg\">\n\u003C\u002Fp>\n\n### 3. Gather and Label Pictures\nNow that the TensorFlow Object Detection API is all set up and ready to go, we need to provide the images it will use to train a new detection classifier.\n\n#### 3a. Gather Pictures\nTensorFlow needs hundreds of images of an object to train a good detection classifier. To train a robust classifier, the training images should have random objects in the image along with the desired objects, and should have a variety of backgrounds and lighting conditions. There should be some images where the desired object is partially obscured, overlapped with something else, or only halfway in the picture. \n\nFor my Pinochle Card Detection classifier, I have six different objects I want to detect (the card ranks nine, ten, jack, queen, king, and ace – I am not trying to detect suit, just rank). I used my iPhone to take about 40 pictures of each card on its own, with various other non-desired objects in the pictures. Then, I took about another 100 pictures with multiple cards in the picture. I know I want to be able to detect the cards when they’re overlapping, so I made sure to have the cards be overlapped in many images.\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_22ed589707ae.jpg\">\n\u003C\u002Fp>\n\nYou can use your phone to take pictures of the objects or download images of the objects from Google Image Search. I recommend having at least 200 pictures overall. I used 311 pictures to train my card detector.\n\nMake sure the images aren’t too large. They should be less than 200KB each, and their resolution shouldn’t be more than 720x1280. The larger the images are, the longer it will take to train the classifier. You can use the resizer.py script in this repository to reduce the size of the images.\n\nAfter you have all the pictures you need, move 20% of them to the \\object_detection\\images\\test directory, and 80% of them to the \\object_detection\\images\\train directory. Make sure there are a variety of pictures in both the \\test and \\train directories.\n\n#### 3b. Label Pictures\nHere comes the fun part! With all the pictures gathered, it’s time to label the desired objects in every picture. LabelImg is a great tool for labeling images, and its GitHub page has very clear instructions on how to install and use it.\n\n[LabelImg GitHub link](https:\u002F\u002Fgithub.com\u002Ftzutalin\u002FlabelImg)\n\n[LabelImg download link](https:\u002F\u002Fwww.dropbox.com\u002Fs\u002Ftq7zfrcwl44vxan\u002Fwindows_v1.6.0.zip?dl=1)\n\nDownload and install LabelImg, point it to your \\images\\train directory, and then draw a box around each object in each image. Repeat the process for all the images in the \\images\\test directory. This will take a while! \n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_ed5c4ae1ad56.jpg\">\n\u003C\u002Fp>\n\nLabelImg saves a .xml file containing the label data for each image. These .xml files will be used to generate TFRecords, which are one of the inputs to the TensorFlow trainer. Once you have labeled and saved each image, there will be one .xml file for each image in the \\test and \\train directories.\n\n### 4. Generate Training Data\nWith the images labeled, it’s time to generate the TFRecords that serve as input data to the TensorFlow training model. This tutorial uses the xml_to_csv.py and generate_tfrecord.py scripts from [Dat Tran’s Raccoon Detector dataset](https:\u002F\u002Fgithub.com\u002Fdatitran\u002Fraccoon_dataset), with some slight modifications to work with our directory structure.\n\nFirst, the image .xml data will be used to create .csv files containing all the data for the train and test images. From the \\object_detection folder, issue the following command in the Anaconda command prompt:\n```\n(tensorflow1) C:\\tensorflow1\\models\\research\\object_detection> python xml_to_csv.py\n```\nThis creates a train_labels.csv and test_labels.csv file in the \\object_detection\\images folder. \n\nNext, open the generate_tfrecord.py file in a text editor. Replace the label map starting at line 31 with your own label map, where each object is assigned an ID number. This same number assignment will be used when configuring the labelmap.pbtxt file in Step 5b. \n\nFor example, say you are training a classifier to detect basketballs, shirts, and shoes. You will replace the following code in generate_tfrecord.py:\n```\n# TO-DO replace this with label map\ndef class_text_to_int(row_label):\n    if row_label == 'nine':\n        return 1\n    elif row_label == 'ten':\n        return 2\n    elif row_label == 'jack':\n        return 3\n    elif row_label == 'queen':\n        return 4\n    elif row_label == 'king':\n        return 5\n    elif row_label == 'ace':\n        return 6\n    else:\n        None\n```\nWith this:\n```\n# TO-DO replace this with label map\ndef class_text_to_int(row_label):\n    if row_label == 'basketball':\n        return 1\n    elif row_label == 'shirt':\n        return 2\n    elif row_label == 'shoe':\n        return 3\n    else:\n        None\n```\nThen, generate the TFRecord files by issuing these commands from the \\object_detection folder:\n```\npython generate_tfrecord.py --csv_input=images\\train_labels.csv --image_dir=images\\train --output_path=train.record\npython generate_tfrecord.py --csv_input=images\\test_labels.csv --image_dir=images\\test --output_path=test.record\n```\nThese generate a train.record and a test.record file in \\object_detection. These will be used to train the new object detection classifier.\n\n### 5. Create Label Map and Configure Training\nThe last thing to do before training is to create a label map and edit the training configuration file.\n\n#### 5a. Label map\nThe label map tells the trainer what each object is by defining a mapping of class names to class ID numbers. Use a text editor to create a new file and save it as labelmap.pbtxt in the C:\\tensorflow1\\models\\research\\object_detection\\training folder. (Make sure the file type is .pbtxt, not .txt !) In the text editor, copy or type in the label map in the format below (the example below is the label map for my Pinochle Deck Card Detector):\n```\nitem {\n  id: 1\n  name: 'nine'\n}\n\nitem {\n  id: 2\n  name: 'ten'\n}\n\nitem {\n  id: 3\n  name: 'jack'\n}\n\nitem {\n  id: 4\n  name: 'queen'\n}\n\nitem {\n  id: 5\n  name: 'king'\n}\n\nitem {\n  id: 6\n  name: 'ace'\n}\n```\nThe label map ID numbers should be the same as what is defined in the generate_tfrecord.py file. For the basketball, shirt, and shoe detector example mentioned in Step 4, the labelmap.pbtxt file will look like:\n```\nitem {\n  id: 1\n  name: 'basketball'\n}\n\nitem {\n  id: 2\n  name: 'shirt'\n}\n\nitem {\n  id: 3\n  name: 'shoe'\n}\n```\n\n#### 5b. Configure training\nFinally, the object detection training pipeline must be configured. It defines which model and what parameters will be used for training. This is the last step before running training!\n\nNavigate to C:\\tensorflow1\\models\\research\\object_detection\\samples\\configs and copy the faster_rcnn_inception_v2_pets.config file into the \\object_detection\\training directory. Then, open the file with a text editor. There are several changes to make to the .config file, mainly changing the number of classes and examples, and adding the file paths to the training data.\n\nMake the following changes to the faster_rcnn_inception_v2_pets.config file. Note: The paths must be entered with single forward slashes (NOT backslashes), or TensorFlow will give a file path error when trying to train the model! Also, the paths must be in double quotation marks ( \" ), not single quotation marks ( ' ).\n\n- Line 9. Change num_classes to the number of different objects you want the classifier to detect. For the above basketball, shirt, and shoe detector, it would be num_classes : 3 .\n- Line 106. Change fine_tune_checkpoint to:\n  - fine_tune_checkpoint : \"C:\u002Ftensorflow1\u002Fmodels\u002Fresearch\u002Fobject_detection\u002Ffaster_rcnn_inception_v2_coco_2018_01_28\u002Fmodel.ckpt\"\n\n- Lines 123 and 125. In the train_input_reader section, change input_path and label_map_path to:\n  - input_path : \"C:\u002Ftensorflow1\u002Fmodels\u002Fresearch\u002Fobject_detection\u002Ftrain.record\"\n  - label_map_path: \"C:\u002Ftensorflow1\u002Fmodels\u002Fresearch\u002Fobject_detection\u002Ftraining\u002Flabelmap.pbtxt\"\n\n- Line 130. Change num_examples to the number of images you have in the \\images\\test directory.\n\n- Lines 135 and 137. In the eval_input_reader section, change input_path and label_map_path to:\n  - input_path : \"C:\u002Ftensorflow1\u002Fmodels\u002Fresearch\u002Fobject_detection\u002Ftest.record\"\n  - label_map_path: \"C:\u002Ftensorflow1\u002Fmodels\u002Fresearch\u002Fobject_detection\u002Ftraining\u002Flabelmap.pbtxt\"\n\nSave the file after the changes have been made. That’s it! The training job is all configured and ready to go!\n\n### 6. Run the Training\n**UPDATE 9\u002F26\u002F18:** \n*As of version 1.9, TensorFlow has deprecated the \"train.py\" file and replaced it with \"model_main.py\" file. I haven't been able to get model_main.py to work correctly yet (I run in to errors related to pycocotools). Fortunately, the train.py file is still available in the \u002Fobject_detection\u002Flegacy folder. Simply move train.py from \u002Fobject_detection\u002Flegacy into the \u002Fobject_detection folder and then continue following the steps below.*\n\nHere we go! From the \\object_detection directory, issue the following command to begin training:\n```\npython train.py --logtostderr --train_dir=training\u002F --pipeline_config_path=training\u002Ffaster_rcnn_inception_v2_pets.config\n```\nIf everything has been set up correctly, TensorFlow will initialize the training. The initialization can take up to 30 seconds before the actual training begins. When training begins, it will look like this:\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_0a3cc4f61c06.jpg\">\n\u003C\u002Fp>\n\nEach step of training reports the loss. It will start high and get lower and lower as training progresses. For my training on the Faster-RCNN-Inception-V2 model, it started at about 3.0 and quickly dropped below 0.8. I recommend allowing your model to train until the loss consistently drops below 0.05, which will take about 40,000 steps, or about 2 hours (depending on how powerful your CPU and GPU are). Note: The loss numbers will be different if a different model is used. MobileNet-SSD starts with a loss of about 20, and should be trained until the loss is consistently under 2.\n\nYou can view the progress of the training job by using TensorBoard. To do this, open a new instance of Anaconda Prompt, activate the tensorflow1 virtual environment, change to the C:\\tensorflow1\\models\\research\\object_detection directory, and issue the following command:\n```\n(tensorflow1) C:\\tensorflow1\\models\\research\\object_detection>tensorboard --logdir=training\n```\nThis will create a webpage on your local machine at YourPCName:6006, which can be viewed through a web browser. The TensorBoard page provides information and graphs that show how the training is progressing. One important graph is the Loss graph, which shows the overall loss of the classifier over time.\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_adec072ade83.jpg\">\n\u003C\u002Fp>\n\nThe training routine periodically saves checkpoints about every five minutes. You can terminate the training by pressing Ctrl+C while in the command prompt window. I typically wait until just after a checkpoint has been saved to terminate the training. You can terminate training and start it later, and it will restart from the last saved checkpoint. The checkpoint at the highest number of steps will be used to generate the frozen inference graph.\n\n### 7. Export Inference Graph\nNow that training is complete, the last step is to generate the frozen inference graph (.pb file). From the \\object_detection folder, issue the following command, where “XXXX” in “model.ckpt-XXXX” should be replaced with the highest-numbered .ckpt file in the training folder:\n```\npython export_inference_graph.py --input_type image_tensor --pipeline_config_path training\u002Ffaster_rcnn_inception_v2_pets.config --trained_checkpoint_prefix training\u002Fmodel.ckpt-XXXX --output_directory inference_graph\n```\nThis creates a frozen_inference_graph.pb file in the \\object_detection\\inference_graph folder. The .pb file contains the object detection classifier.\n\n### 8. Use Your Newly Trained Object Detection Classifier!\nThe object detection classifier is all ready to go! I’ve written Python scripts to test it out on an image, video, or webcam feed.\n\nBefore running the Python scripts, you need to modify the NUM_CLASSES variable in the script to equal the number of classes you want to detect. (For my Pinochle Card Detector, there are six cards I want to detect, so NUM_CLASSES = 6.)\n\nTo test your object detector, move a picture of the object or objects into the \\object_detection folder, and change the IMAGE_NAME variable in the Object_detection_image.py to match the file name of the picture. Alternatively, you can use a video of the objects (using Object_detection_video.py), or just plug in a USB webcam and point it at the objects (using Object_detection_webcam.py).\n\nTo run any of the scripts, type “idle” in the Anaconda Command Prompt (with the “tensorflow1” virtual environment activated) and press ENTER. This will open IDLE, and from there, you can open any of the scripts and run them.\n\nIf everything is working properly, the object detector will initialize for about 10 seconds and then display a window showing any objects it’s detected in the image!\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_73f68242d557.jpg\">\n\u003C\u002Fp>\n\nIf you encounter errors, please check out the Appendix: it has a list of errors that I ran in to while setting up my object detection classifier. You can also trying Googling the error. There is usually useful information on Stack Exchange or in TensorFlow’s Issues on GitHub.\n\n## Appendix: Common Errors\nIt appears that the TensorFlow Object Detection API was developed on a Linux-based operating system, and most of the directions given by the documentation are for a Linux OS. Trying to get a Linux-developed software library to work on Windows can be challenging. There are many little snags that I ran in to while trying to set up tensorflow-gpu to train an object detection classifier on Windows 10. This Appendix is a list of errors I ran in to, and their resolutions.\n\n#### 1. ModuleNotFoundError: No module named 'deployment' or No module named 'nets'\n\nThis error occurs when you try to run object_detection_tutorial.ipynb or train.py and you don’t have the PATH and PYTHONPATH environment variables set up correctly. Exit the virtual environment by closing and re-opening the Anaconda Prompt window. Then, issue “activate tensorflow1” to re-enter the environment, and then issue the commands given in Step 2e. \n\nYou can use “echo %PATH%” and “echo %PYTHONPATH%” to check the environment variables and make sure they are set up correctly.\n\nAlso, make sure you have run these commands from the \\models\\research directory:\n```\nsetup.py build\nsetup.py install\n```\n\n#### 2. ImportError: cannot import name 'preprocessor_pb2'\n\n#### ImportError: cannot import name 'string_int_label_map_pb2'\n\n#### (or similar errors with other pb2 files)\n\nThis occurs when the protobuf files (in this case, preprocessor.proto) have not been compiled. Re-run the protoc command given in Step 2f. Check the \\object_detection\\protos folder to make sure there is a name_pb2.py file for every name.proto file.\n\n#### 3. object_detection\u002Fprotos\u002F.proto: No such file or directory\n\nThis occurs when you try to run the\n```\n“protoc object_detection\u002Fprotos\u002F*.proto --python_out=.”\n```\ncommand given on the TensorFlow Object Detection API installation page. Sorry, it doesn’t work on Windows! Copy and paste the full command given in Step 2f instead. There’s probably a more graceful way to do it, but I don’t know what it is.\n\n#### 4. Unsuccessful TensorSliceReader constructor: Failed to get \"file path\" … The filename, directory name, or volume label syntax is incorrect.\n  \nThis error occurs when the filepaths in the training configuration file (faster_rcnn_inception_v2_pets.config or similar) have not been entered with backslashes instead of forward slashes. Open the .config file and make sure all file paths are given in the following format:\n```\n“C:\u002Fpath\u002Fto\u002Fmodel.file”\n```\n\n#### 5. ValueError: Tried to convert 't' to a tensor and failed. Error: Argument must be a dense tensor: range(0, 3) - got shape [3], but wanted [].\n\nThe issue is with models\u002Fresearch\u002Fobject_detection\u002Futils\u002Flearning_schedules.py Currently it is\n```\nrate_index = tf.reduce_max(tf.where(tf.greater_equal(global_step, boundaries),\n                                      range(num_boundaries),\n                                      [0] * num_boundaries))\n```\nWrap list() around the range() like this:\n\n```\nrate_index = tf.reduce_max(tf.where(tf.greater_equal(global_step, boundaries),\n                                     list(range(num_boundaries)),\n                                      [0] * num_boundaries))\n```\n\n[Ref: Tensorflow Issue#3705](https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Fissues\u002F3705#issuecomment-375563179)\n\n#### 6. ImportError: DLL load failed: The specified procedure could not be found.   (or other DLL-related errors)\nThis error occurs because the CUDA and cuDNN versions you have installed are not compatible with the version of TensorFlow you are using. The easiest way to resolve this error is to use Anaconda's cudatoolkit package rather than manually installing CUDA and cuDNN. If you ran into these errors, try creating a new Anaconda virtual environment:\n```\nconda create -n tensorflow2 pip python=3.5\n```\nThen, once inside the environment, install TensorFlow using CONDA rather than PIP:\n```\nconda install tensorflow-gpu\n```\nThen restart this guide from Step 2 (but you can skip the part where you install TensorFlow in Step 2d).\n\n#### 7. In Step 2g, the Jupyter Notebook runs all the way through with no errors, but no pictures are displayed at the end.\nIf you run the full Jupyter Notebook without getting any errors, but the labeled pictures still don't appear, try this: go in to object_detection\u002Futils\u002Fvisualization_utils.py and comment out the import statements around lines 29 and 30 that include matplotlib. Then, try re-running the Jupyter notebook. (The visualization_utils.py script changes quite a bit, so it might not be exactly line 29 and 30.)\n","# 如何在 Windows 10 上使用 TensorFlow（GPU）训练多目标物体检测分类器\n\n## 简要概述\n*最后更新：2019年6月22日，TensorFlow v1.13.1*\n\n本仓库是一个教程，介绍如何在 Windows 10、8 或 7 上使用 TensorFlow 的物体检测 API 来训练一个多目标物体检测分类器。（稍作修改后也可在基于 Linux 的操作系统上运行。）该教程最初是基于 TensorFlow 1.5 编写的，但同样适用于较新版本的 TensorFlow。\n\n本指南的翻译版本如下所示。如果您希望贡献其他语言的翻译，请随时提出！您可以将其作为拉取请求提交，我将在方便时合并。\n* [韩语翻译](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10\u002Fblob\u002Fmaster\u002Ftranslate\u002FREADME_Korean.md)（感谢 @cocopambag!）\n* [中文翻译](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10\u002Fblob\u002Fmaster\u002Ftranslate\u002FREADME_Chinese.md)（感谢 @Marco-Ray!）\n* [越南语翻译](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10\u002Fblob\u002Fmaster\u002Ftranslate\u002FREADME_Vietnamese.md)（感谢 @winter2897!）\n\n我还制作了一段 YouTube 视频来演示本教程。视频与本文档之间的任何差异都是由于使用较新版本 TensorFlow 所需的更新造成的。\n\n**如果本文档与视频存在差异，请以本文档为准！**\n\n[![我的 YouTube 视频链接！](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_201e6a37ea22.jpg)](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=Rgpfk6eYxJA)\n\n本自述文件详细描述了启动您自己的物体检测分类器所需的每一步：\n1. [安装 Anaconda、CUDA 和 cuDNN](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#1-install-anaconda-cuda-and-cudnn)\n2. [设置物体检测目录结构和 Anaconda 虚拟环境](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#2-set-up-tensorflow-directory-and-anaconda-virtual-environment)\n3. [收集并标注图片](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#3-gather-and-label-pictures)\n4. [生成训练数据](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#4-generate-training-data)\n5. [创建标签映射并配置训练](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#5-create-label-map-and-configure-training)\n6. [训练模型](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#6-run-the-training)\n7. [导出推理图](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#7-export-inference-graph)\n8. [测试并使用您新训练的物体检测分类器](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#8-use-your-newly-trained-object-detection-classifier)\n\n[附录：常见错误](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#appendix-common-errors)\n\n该仓库提供了训练一个“皮诺克尔牌组”扑克牌检测器所需的所有文件，该检测器能够准确识别九、十、J、Q、K 和 A。本教程说明如何用您自己的文件替换这些示例文件，从而训练出满足您需求的物体检测分类器。此外，还包含用于在图像、视频或网络摄像头流中测试分类器的 Python 脚本。\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_0805cf0a43c7.jpg\">\n\u003C\u002Fp>\n\n## 引言\n本教程旨在从零开始讲解如何训练您自己的卷积神经网络多目标物体检测分类器。完成本教程后，您将拥有一个能够在图片、视频或网络摄像头流中识别特定物体并为其绘制边界框的程序。\n\n目前已有许多优秀的教程介绍了如何使用 TensorFlow 的物体检测 API 训练单目标分类器。然而，这些教程通常假设用户使用的是 Linux 操作系统。如果您像我一样，可能不太愿意在配备高性能显卡的游戏电脑上安装 Linux，而这块显卡正是用来训练分类器的。物体检测 API 似乎是在基于 Linux 的操作系统上开发的。要在 Windows 上设置 TensorFlow 来训练模型，需要采用一些变通方法来替代在 Linux 上可以直接使用的命令。此外，本教程还提供了训练可检测多个目标的分类器的指导，而不仅仅是单个目标。\n\n本教程专为 Windows 10 编写，但也适用于 Windows 7 和 8。其总体流程同样可用于 Linux 操作系统，但相应的文件路径和软件包安装命令需要进行调整。我在编写本教程的初始版本时使用的是 TensorFlow-GPU 1.5，但它应该也能兼容未来的 TensorFlow 版本。\n\nTensorFlow-GPU 允许您的计算机利用显卡提供额外的计算能力来进行训练，因此本教程将使用它。根据我的经验，使用 TensorFlow-GPU 而不是普通 TensorFlow 可以将训练时间缩短约 8 倍（从 24 小时缩短到 3 小时）。当然，也可以使用仅 CPU 的 TensorFlow 版本来完成本教程，但训练时间会更长。如果您选择仅使用 CPU 的 TensorFlow，则无需在步骤 1 中安装 CUDA 和 cuDNN。\n\n## 步骤\n\n### 1. 安装 Anaconda、CUDA 和 cuDNN\nAnaconda 是一个软件工具包，用于创建 Python 虚拟环境，这样你就可以安装和使用 Python 库，而无需担心与现有安装产生版本冲突。Anaconda 在 Windows 上运行良好，并且使你能够使用许多通常只在 Linux 系统上才能运行的 Python 库。它提供了一种简单的方法来安装 TensorFlow（我们将在第 2d 步中完成）。此外，它还会自动安装你在 GPU 上使用 TensorFlow 所需的 CUDA 和 cuDNN 版本。\n\n从 [他们的官网](https:\u002F\u002Fwww.anaconda.com\u002Fproducts\u002Findividual) 下载适用于 Windows 的 Anaconda（你需要向下滚动一段距离才能找到下载链接）。下载完成后，运行安装程序并按照步骤完成安装。\n\n如果你使用的是 TF v1.13 之前的 TensorFlow 版本，请确保使用的 CUDA 和 cuDNN 版本与你所用的 TensorFlow 版本兼容。[这里](https:\u002F\u002Fwww.tensorflow.org\u002Finstall\u002Fsource#tested_build_configurations) 提供了一个表格，显示了不同版本的 TensorFlow 需要哪些版本的 CUDA 和 cuDNN。Anaconda 会为你使用的 TensorFlow 版本自动安装正确的 CUDA 和 cuDNN 版本，因此你无需为此操心。\n\n### 2. 设置 TensorFlow 目录和 Anaconda 虚拟环境\nTensorFlow 对象检测 API 要求使用其 GitHub 仓库中提供的特定目录结构。它还需要一些额外的 Python 包、对 PATH 和 PYTHONPATH 环境变量的特定设置，以及一些额外的配置命令，才能将所有内容正确设置好，以便运行或训练对象检测模型。\n\n本教程的这一部分将详细介绍完整的设置过程。虽然步骤较为繁琐，但请务必严格按照说明操作，因为设置不当可能会在后续过程中引发难以解决的错误。\n\n#### 2a. 从 GitHub 下载 TensorFlow 对象检测 API 仓库\n在 C: 盘根目录下创建一个名为 “tensorflow1” 的文件夹。这个工作目录将包含完整的 TensorFlow 对象检测框架，以及你的训练图像、训练数据、已训练的分类器、配置文件等对象检测分类器所需的一切内容。\n\n访问 https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels 下载完整的 TensorFlow 对象检测仓库，点击“Clone or Download”按钮并下载 zip 文件。解压下载的 zip 文件，将其中的 “models-master” 文件夹直接提取到你刚刚创建的 C:\\tensorflow1 目录中，并将 “models-master” 重命名为 “models”。\n\n**注意：TensorFlow 模型仓库的代码（包含对象检测 API）由开发者持续更新。有时他们会进行一些更改，导致与旧版 TensorFlow 不兼容。因此，最好始终使用最新版本的 TensorFlow，并下载最新的模型仓库。如果你使用的是较旧版本，请根据下表克隆或下载对应版本的提交记录。**\n\n如果你使用的是较旧版本的 TensorFlow，以下表格列出了你应该使用的 GitHub 提交记录。我通过进入模型仓库的发布分支，获取该分支在正式发布前的倒数第二个提交生成了此表格。（他们在创建正式版本发布之前，会移除 research 文件夹作为最后一个提交。）\n\n| TensorFlow 版本 | GitHub 模型仓库提交 |\n|--------------------|---------------------------------|\n|TF v1.7             |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fadfd5a3aca41638aa9fb297c5095f33d64446d8f |\n|TF v1.8             |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fabd504235f3c2eed891571d62f0a424e54a2dabc |\n|TF v1.9             |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fd530ac540b0103caa194b4824af353f1b073553b |\n|TF v1.10            |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fb07b494e3514553633b132178b4c448f994d59df |\n|TF v1.11            |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002F23b5b4227dfa1b23d7c21f0dfaf0951b16671f43 |\n|TF v1.12            |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fr1.12.0 |\n|TF v1.13            |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002Fr1.13.0 |\n|最新版本      |https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels |\n\n本教程最初是使用 TensorFlow v1.5 和 TensorFlow 对象检测 API 的 [此 GitHub 提交](https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Ftree\u002F079d67d9a0b3407e8d074a200780f3835413ef99) 完成的。如果本教程中的某些部分无法正常工作，可能需要安装 TensorFlow v1.5 并使用该确切的提交记录，而不是最新版本。\n\n#### 2b. 从 TensorFlow 模型库下载 Faster-RCNN-Inception-V2-COCO 模型\nTensorFlow 在其 [模型库](https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Fblob\u002Fmaster\u002Fresearch\u002Fobject_detection\u002Fg3doc\u002Ftf1_detection_zoo.md) 中提供了多种对象检测模型（带有特定神经网络架构的预训练分类器）。有些模型（如 SSD-MobileNet 模型）具有更快检测速度但准确率较低的架构，而另一些模型（如 Faster-RCNN 模型）则检测速度较慢但准确率更高。我最初使用的是 SSD-MobileNet-V1 模型，但它在我的图像中对卡片的识别效果并不理想。随后我使用 Faster-RCNN-Inception-V2 模型重新训练了检测器，结果检测效果显著提升，但速度明显变慢。\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_8d590361ffad.jpg\">\n\u003C\u002Fp>\n\n你可以选择使用哪种模型来训练你的对象检测分类器。如果你计划在计算能力较低的设备上（如智能手机或 Raspberry Pi）使用对象检测器，则应选择 SDD-MobileNet 模型；如果你将在性能较好的笔记本电脑或台式机上运行检测器，则可以选择 RCNN 系列模型。\n\n本教程将使用 Faster-RCNN-Inception-V2 模型。[在此下载该模型。](http:\u002F\u002Fdownload.tensorflow.org\u002Fmodels\u002Fobject_detection\u002Ffaster_rcnn_inception_v2_coco_2018_01_28.tar.gz) 使用 WinZip 或 7-Zip 等文件解压工具打开下载的 faster_rcnn_inception_v2_coco_2018_01_28.tar.gz 文件，将 faster_rcnn_inception_v2_coco_2018_01_28 文件夹提取到 C:\\tensorflow1\\models\\research\\object_detection 目录中。（注意：该模型的日期和版本未来可能会发生变化，但应该仍然适用于本教程。）\n\n#### 2c. 从 GitHub 下载本教程的仓库\n下载本页面上的完整仓库（滚动到顶部并点击 Clone or Download），将所有内容直接提取到 C:\\tensorflow1\\models\\research\\object_detection 目录中。（可以覆盖现有的 “README.md” 文件。）这将建立一个特定的目录结构，供本教程后续步骤使用。\n\n此时，你的 \\object_detection 目录应如下所示：\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_57d90ebb6609.jpg\">\n\u003C\u002Fp>\n\n此仓库包含训练“皮诺克尔牌组”扑克牌检测器所需的图像、标注数据、.csv文件以及TFRecords。您可以使用这些图像和数据来练习构建您自己的皮诺克尔牌检测器。此外，仓库还包含用于生成训练数据的Python脚本，以及可在图像、视频或网络摄像头流上测试目标检测分类器的脚本。您可以忽略\\doc文件夹及其内容；它们仅用于存放本README中使用的图片。\n\n如果您想练习训练自己的“皮诺克尔牌组”牌检测器，可以保持所有文件不变。您可以按照本教程了解每个文件是如何生成的，然后开始训练。不过，您仍需按照步骤4中的说明生成TFRecord文件（train.record和test.record）。\n\n您也可以从以下Dropbox链接下载我训练好的皮诺克尔牌检测器的冻结推理图[https:\u002F\u002Fwww.dropbox.com\u002Fs\u002Fva9ob6wcucusse1\u002Finference_graph.zip?dl=0]，并将内容解压到\\object_detection\\inference_graph目录下。该推理图可直接使用。在完成步骤2a至2f的所有设置后，您可以通过运行Object_detection_image.py（或视频、网络摄像头）脚本来测试它。\n\n如果您希望训练自己的目标检测模型，请删除以下文件（请勿删除文件夹）：\n- \\object_detection\\images\\train和\\object_detection\\images\\test中的所有文件\n- \\object_detection\\images中的“test_labels.csv”和“train_labels.csv”文件\n- \\object_detection\\training中的所有文件\n- \\object_detection\\inference_graph中的所有文件\n\n现在，您已准备好从头开始训练自己的目标检测模型。本教程将假设上述所有文件已被删除，并继续说明如何为您的训练数据集生成所需文件。\n\n#### 2d. 设置新的Anaconda虚拟环境\n接下来，我们将在Anaconda中为tensorflow-gpu设置一个虚拟环境。在Windows的开始菜单中搜索“Anaconda Prompt”工具，右键单击并选择“以管理员身份运行”。如果Windows提示您是否允许更改计算机设置，请点击“是”。\n\n在弹出的命令行终端中，通过以下命令创建名为“tensorflow1”的新虚拟环境：\n```\nC:\\> conda create -n tensorflow1 pip python=3.5\n```\n然后激活该环境并更新pip：\n```\nC:\\> activate tensorflow1\n\n(tensorflow1) C:\\>python -m pip install --upgrade pip\n```\n在该环境中安装tensorflow-gpu：\n```\n(tensorflow1) C:\\> pip install --ignore-installed --upgrade tensorflow-gpu\n```\n\n由于我们使用的是Anaconda，安装tensorflow-gpu时会自动下载并安装正确版本的CUDA和cuDNN。\n\n（注：您也可以使用仅支持CPU的TensorFlow版本，但其运行速度会慢得多。如果要使用CPU版本，只需在上述命令中将“tensorflow-gpu”替换为“tensorflow”即可。）\n\n安装其他必要的软件包：\n```\n(tensorflow1) C:\\> conda install -c anaconda protobuf\n(tensorflow1) C:\\> pip install pillow\n(tensorflow1) C:\\> pip install lxml\n(tensorflow1) C:\\> pip install Cython\n(tensorflow1) C:\\> pip install contextlib2\n(tensorflow1) C:\\> pip install jupyter\n(tensorflow1) C:\\> pip install matplotlib\n(tensorflow1) C:\\> pip install pandas\n(tensorflow1) C:\\> pip install opencv-python\n```\n\n（注：pandas和opencv-python这两个包并非TensorFlow所必需，但在生成TFRecords以及处理图像、视频和网络摄像头流的Python脚本中会用到。）\n\n#### 2e. 配置PYTHONPATH环境变量\n必须创建一个指向\\models、\\models\\research和\\models\\research\\slim目录的PYTHONPATH变量。为此，请从任意目录执行以下命令：\n```\n(tensorflow1) C:\\> set PYTHONPATH=C:\\tensorflow1\\models;C:\\tensorflow1\\models\\research;C:\\tensorflow1\\models\\research\\slim\n```\n\n（注：每次退出“tensorflow1”虚拟环境时，PYTHONPATH变量都会重置，需要重新设置。您可以用“echo %PYTHONPATH%”来检查是否已成功设置。）\n\n#### 2f. 编译Protobuf文件并运行setup.py\n接下来，编译TensorFlow用于配置模型和训练参数的Protobuf文件。遗憾的是，TensorFlow对象检测API[安装页面](https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Fblob\u002Fmaster\u002Fresearch\u002Fobject_detection\u002Fg3doc\u002Finstallation.md)上提供的简短protoc编译命令在Windows上无法正常工作。必须逐个调用\\object_detection\\protos目录下的每个.proto文件。\n\n在Anaconda命令提示符中，切换到\\models\\research目录：\n```\n(tensorflow1) C:\\> cd C:\\tensorflow1\\models\\research\n```\n\n然后将以下命令复制并粘贴到命令行中并按回车键：\n```\nprotoc --python_out=. .\\object_detection\\protos\\anchor_generator.proto .\\object_detection\\protos\\argmax_matcher.proto .\\object_detection\\protos\\bipartite_matcher.proto .\\object_detection\\protos\\box_coder.proto .\\object_detection\\protos\\box_predictor.proto .\\object_detection\\protos\\eval.proto .\\object_detection\\protos\\faster_rcnn.proto .\\object_detection\\protos\\faster_rcnn_box_coder.proto .\\object_detection\\protos\\grid_anchor_generator.proto .\\object_detection\\protos\\hyperparams.proto .\\object_detection\\protos\\image_resizer.proto .\\object_detection\\protos\\input_reader.proto .\\object_detection\\protos\\losses.proto .\\object_detection\\protos\\matcher.proto .\\object_detection\\protos\\mean_stddev_box_coder.proto .\\object_detection\\protos\\model.proto .\\object_detection\\protos\\optimizer.proto .\\object_detection\\protos\\pipeline.proto .\\object_detection\\protos\\post_processing.proto .\\object_detection\\protos\\preprocessor.proto .\\object_detection\\protos\\region_similarity_calculator.proto .\\object_detection\\protos\\square_box_coder.proto .\\object_detection\\protos\\ssd.proto .\\object_detection\\protos\\ssd_anchor_generator.proto .\\object_detection\\protos\\string_int_label_map.proto .\\object_detection\\protos\\train.proto .\\object_detection\\protos\\keypoint_box_coder.proto .\\object_detection\\protos\\multiscale_anchor_generator.proto .\\object_detection\\protos\\graph_rewriter.proto .\\object_detection\\protos\\calibration.proto .\\object_detection\\protos\\flexible_grid_anchor_generator.proto\n```\n\n这将为\\object_detection\\protos文件夹中的每个.proto文件生成对应的name_pb2.py文件。\n\n（注：TensorFlow有时会向\\protos文件夹添加新的.proto文件。如果出现ImportError: cannot import name 'something_something_pb2'错误，您可能需要更新protoc命令以包含新增的.proto文件。）\n\n最后，在 C:\\tensorflow1\\models\\research 目录下运行以下命令：\n```\n(tensorflow1) C:\\tensorflow1\\models\\research> python setup.py build\n(tensorflow1) C:\\tensorflow1\\models\\research> python setup.py install\n```\n\n#### 2g. 测试 TensorFlow 安装以验证其是否正常工作\n现在，TensorFlow 对象检测 API 已经设置完毕，可以使用预训练模型进行对象检测，也可以训练一个新的模型。你可以通过启动 Jupyter 中的 object_detection_tutorial.ipynb 脚本来测试并验证安装是否成功。从 \\object_detection 目录下，执行以下命令：\n```\n(tensorflwo1) C:\\tensorflow1\\models\\research\\object_detection> jupyter notebook object_detection_tutorial.ipynb\n```\n这将在你的默认网页浏览器中打开该脚本，允许你逐段逐步运行代码。只需点击顶部工具栏中的“运行”按钮即可逐段执行。当该段落旁边的“In [ * ]”文本显示一个数字（例如“In [1]”）时，就表示该段已执行完毕。\n\n（注：脚本的一部分会从 GitHub 下载 ssd_mobilenet_v1 模型，大小约为 74MB。因此，完成这一部分需要一些时间，请耐心等待。）\n\n当你完整地运行完整个脚本后，页面底部应该会出现两张带有标注的图片。如果看到这些图片，则说明一切正常！如果没有出现，底部区域会显示遇到的任何错误信息。有关我在设置过程中遇到的一些常见错误列表，请参阅[附录](https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#appendix-common-errors)。\n\n**注意：如果你完整运行了 Jupyter Notebook 并未出现任何错误，但仍然没有显示标注图片，请尝试以下操作：进入 object_detection\u002Futils\u002Fvisualization_utils.py 文件，将第 29 和 30 行附近包含 matplotlib 的导入语句注释掉，然后再次运行 Jupyter Notebook。**\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_3150e6f30a05.jpg\">\n\u003C\u002Fp>\n\n\n\n### 3. 收集并标注图片\n现在，TensorFlow 对象检测 API 已经设置完毕并准备就绪，我们需要提供用于训练新检测分类器的图像。\n\n#### 3a. 收集图片\nTensorFlow 需要数百张目标物体的图片才能训练出一个优秀的检测分类器。为了训练出鲁棒的分类器，训练图像中除了目标物体外，还应包含随机物体，并且背景和光照条件应多样化。此外，还应有一些目标物体被部分遮挡、与其他物体重叠或只有一半出现在画面中的图像。\n\n对于我的 Pinochle 卡牌检测分类器，我想要检测六种不同的卡牌等级：9、10、J、Q、K 和 A——我并不打算区分花色，只关注等级。我用 iPhone 分别拍摄了每种卡牌的单独照片约 40 张，同时在照片中加入了一些其他非目标物体。之后，我又拍摄了大约 100 张包含多张卡牌的照片。由于我希望能够在卡牌相互重叠的情况下也能检测到它们，因此我在许多照片中特意让卡牌互相重叠。\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_22ed589707ae.jpg\">\n\u003C\u002Fp>\n\n你可以使用手机拍摄目标物体的照片，或者从 Google 图片搜索下载相关图片。建议至少准备 200 张图片。我用来训练卡牌检测器的图片总数为 311 张。\n\n请确保图片不要太大，每张图片的大小应小于 200KB，分辨率不超过 720x1280。图片越大，训练分类器所需的时间就越长。你可以使用本仓库中的 resizer.py 脚本来缩小图片尺寸。\n\n收集齐所有需要的图片后，将其中 20% 移至 \\object_detection\\images\\test 目录，80% 移至 \\object_detection\\images\\train 目录。确保 \\test 和 \\train 目录中都包含多样化的图片。\n\n#### 3b. 标注图片\n接下来就是有趣的部分了！在收集好所有图片后，现在需要对每张图片中的目标物体进行标注。LabelImg 是一款非常优秀的图像标注工具，其 GitHub 页面提供了清晰明了的安装和使用说明。\n\n[LabelImg GitHub 链接](https:\u002F\u002Fgithub.com\u002Ftzutalin\u002FlabelImg)\n\n[LabelImg 下载链接](https:\u002F\u002Fwww.dropbox.com\u002Fs\u002Ftq7zfrcwl44vxan\u002Fwindows_v1.6.0.zip?dl=1)\n\n下载并安装 LabelImg，将其指向你的 \\images\\train 目录，然后在每张图片中用矩形框圈出每个目标物体。接着，对 \\images\\test 目录中的所有图片重复此操作。这个过程可能会花费一些时间！\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_ed5c4ae1ad56.jpg\">\n\u003C\u002Fp>\n\nLabelImg 会保存一个包含每张图片标注数据的 .xml 文件。这些 .xml 文件将用于生成 TFRecords，而 TFRecords 正是 TensorFlow 训练器的输入之一。完成所有图片的标注并保存后，\\test 和 \\train 目录中将分别对应每张图片生成一个 .xml 文件。\n\n### 4. 生成训练数据\n在完成图片标注后，接下来需要生成作为 TensorFlow 训练模型输入数据的 TFRecords。本教程使用了 [Dat Tran 的浣熊检测数据集](https:\u002F\u002Fgithub.com\u002Fdatitran\u002Fraccoon_dataset) 中的 xml_to_csv.py 和 generate_tfrecord.py 脚本，并根据我们的目录结构做了一些微调。\n\n首先，利用图片的 .xml 数据创建包含训练和测试图像所有数据的 .csv 文件。在 Anaconda 命令提示符中，从 \\object_detection 文件夹下执行以下命令：\n```\n(tensorflow1) C:\\tensorflow1\\models\\research\\object_detection> python xml_to_csv.py\n```\n这将在 \\object_detection\\images 文件夹中生成 train_labels.csv 和 test_labels.csv 文件。\n\n接下来，用文本编辑器打开 generate_tfrecord.py 文件。将从第 31 行开始的标签映射替换为你自己的标签映射，为每个目标物体分配一个 ID 号。这个编号也将用于步骤 5b 中配置 labelmap.pbtxt 文件。\n\n例如，假设你要训练一个检测篮球、衬衫和鞋子的分类器，那么你需要将 generate_tfrecord.py 中的以下代码：\n```\n# TO-DO 替换为标签映射\ndef class_text_to_int(row_label):\n    if row_label == 'nine':\n        return 1\n    elif row_label == 'ten':\n        return 2\n    elif row_label == 'jack':\n        return 3\n    elif row_label == 'queen':\n        return 4\n    elif row_label == 'king':\n        return 5\n    elif row_label == 'ace':\n        return 6\n    else:\n        None\n```\n替换为：\n\n# 待办事项：用标签映射替换此处\ndef class_text_to_int(row_label):\n    if row_label == 'basketball':\n        return 1\n    elif row_label == 'shirt':\n        return 2\n    elif row_label == 'shoe':\n        return 3\n    else:\n        None\n```\n然后，从 \\object_detection 文件夹中执行以下命令来生成 TFRecord 文件：\n```\npython generate_tfrecord.py --csv_input=images\\train_labels.csv --image_dir=images\\train --output_path=train.record\npython generate_tfrecord.py --csv_input=images\\test_labels.csv --image_dir=images\\test --output_path=test.record\n```\n这些命令将在 \\object_detection 文件夹中生成 train.record 和 test.record 文件。这些文件将用于训练新的目标检测分类器。\n\n### 5. 创建标签映射并配置训练\n在开始训练之前，最后需要完成的任务是创建标签映射并编辑训练配置文件。\n\n#### 5a. 标签映射\n标签映射通过定义类别名称与类别 ID 的对应关系，告诉训练程序每个对象的含义。使用文本编辑器创建一个新文件，并将其保存为 labelmap.pbtxt，路径为 C:\\tensorflow1\\models\\research\\object_detection\\training 文件夹。（请确保文件类型为 .pbtxt，而不是 .txt！）在文本编辑器中，复制或键入如下格式的标签映射（下面的示例是我的 Pinochle 牌组卡片检测器的标签映射）：\n```\nitem {\n  id: 1\n  name: 'nine'\n}\n\nitem {\n  id: 2\n  name: 'ten'\n}\n\nitem {\n  id: 3\n  name: 'jack'\n}\n\nitem {\n  id: 4\n  name: 'queen'\n}\n\nitem {\n  id: 5\n  name: 'king'\n}\n\nitem {\n  id: 6\n  name: 'ace'\n}\n```\n标签映射中的 ID 号必须与 generate_tfrecord.py 文件中定义的编号一致。对于第 4 步中提到的篮球、衬衫和鞋子检测器示例，labelmap.pbtxt 文件应如下所示：\n```\nitem {\n  id: 1\n  name: 'basketball'\n}\n\nitem {\n  id: 2\n  name: 'shirt'\n}\n\nitem {\n  id: 3\n  name: 'shoe'\n}\n```\n\n#### 5b. 配置训练\n最后，需要配置目标检测的训练流程。该流程定义了将使用哪种模型以及哪些参数进行训练。这是运行训练之前的最后一步！\n\n导航到 C:\\tensorflow1\\models\\research\\object_detection\\samples\\configs 文件夹，将 faster_rcnn_inception_v2_pets.config 文件复制到 \\object_detection\\training 目录。然后用文本编辑器打开该文件。需要对 .config 文件进行几处修改，主要包括更改类别数和样本数，以及添加训练数据的文件路径。\n\n对 faster_rcnn_inception_v2_pets.config 文件进行如下修改。注意：路径必须使用单斜杠（不能使用反斜杠），否则 TensorFlow 在尝试训练模型时会报文件路径错误！此外，路径必须用双引号（ \" ）括起来，而不是单引号（ ' ）。\n\n- 第 9 行。将 num_classes 改为分类器需要检测的不同物体数量。对于上述篮球、衬衫和鞋子检测器，num_classes 应设置为 3。\n- 第 106 行。将 fine_tune_checkpoint 修改为：\n  - fine_tune_checkpoint : \"C:\u002Ftensorflow1\u002Fmodels\u002Fresearch\u002Fobject_detection\u002Ffaster_rcnn_inception_v2_coco_2018_01_28\u002Fmodel.ckpt\"\n\n- 第 123 和 125 行。在 train_input_reader 部分，将 input_path 和 label_map_path 修改为：\n  - input_path : \"C:\u002Ftensorflow1\u002Fmodels\u002Fresearch\u002Fobject_detection\u002Ftrain.record\"\n  - label_map_path: \"C:\u002Ftensorflow1\u002Fmodels\u002Fresearch\u002Fobject_detection\u002Ftraining\u002Flabelmap.pbtxt\"\n\n- 第 130 行。将 num_examples 修改为 \\images\\test 目录中图像的数量。\n\n- 第 135 和 137 行。在 eval_input_reader 部分，将 input_path 和 label_map_path 修改为：\n  - input_path : \"C:\u002Ftensorflow1\u002Fmodels\u002Fresearch\u002Fobject_detection\u002Ftest.record\"\n  - label_map_path: \"C:\u002Ftensorflow1\u002Fmodels\u002Fresearch\u002Fobject_detection\u002Ftraining\u002Flabelmap.pbtxt\"\n\n完成修改后保存文件。至此，训练任务的所有配置已完成，可以开始训练了！\n\n### 6. 运行训练\n**更新日期：2018年9月26日：**\n*自版本 1.9 起，TensorFlow 已弃用 “train.py” 文件，改用 “model_main.py” 文件。目前我尚未成功使 model_main.py 正常工作（遇到了与 pycocotools 相关的错误）。幸运的是，“train.py” 文件仍然存在于 \u002Fobject_detection\u002Flegacy 文件夹中。只需将 train.py 从 \u002Fobject_detection\u002Flegacy 移至 \u002Fobject_detection 文件夹，然后继续按照以下步骤操作即可。*\n\n现在开始！从 \\object_detection 目录下，执行以下命令以启动训练：\n```\npython train.py --logtostderr --train_dir=training\u002F --pipeline_config_path=training\u002Ffaster_rcnn_inception_v2_pets.config\n```\n如果所有设置都正确，TensorFlow 将初始化训练。初始化可能需要长达 30 秒，之后才会真正开始训练。训练开始时，界面将显示如下：\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_0a3cc4f61c06.jpg\">\n\u003C\u002Fp>\n\n训练的每一步都会报告损失值。初始损失较高，随着训练的进行会逐渐降低。在我使用 Faster-RCNN-Inception-V2 模型进行的训练中，损失最初约为 3.0，随后迅速降至 0.8 以下。建议让模型持续训练，直到损失稳定低于 0.05，这通常需要约 40,000 步，大约 2 小时（具体时间取决于 CPU 和 GPU 的性能）。注意：如果使用不同的模型，损失数值也会有所不同。例如，MobileNet-SSD 的初始损失约为 20，应训练至损失稳定低于 2。\n\n可以通过 TensorBoard 查看训练进度。为此，打开一个新的 Anaconda Prompt 窗口，激活 tensorflow1 虚拟环境，切换到 C:\\tensorflow1\\models\\research\\object_detection 目录，然后执行以下命令：\n```\n(tensorflow1) C:\\tensorflow1\\models\\research\\object_detection>tensorboard --logdir=training\n```\n这将在本地计算机上创建一个网页，地址为 YourPCName:6006，可通过浏览器访问。TensorBoard 页面提供有关训练进展的信息和图表。其中一个重要图表是损失图，它显示了分类器整体损失随时间的变化情况。\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_adec072ade83.jpg\">\n\u003C\u002Fp>\n\n训练过程中会每隔约五分钟自动保存检查点。可以在命令提示符窗口中按 Ctrl+C 终止训练。我通常会在刚保存完检查点后终止训练。您可以随时停止训练并在稍后继续，训练将从最近保存的检查点重新开始。最终用于生成冻结推理图的是步数最高的那个检查点。\n\n### 7. 导出推理图\n现在训练已经完成，最后一步是生成冻结的推理图（.pb 文件）。在 \\object_detection 文件夹中，执行以下命令，其中“model.ckpt-XXXX”中的“XXXX”应替换为训练文件夹中编号最大的 .ckpt 文件：\n```\npython export_inference_graph.py --input_type image_tensor --pipeline_config_path training\u002Ffaster_rcnn_inception_v2_pets.config --trained_checkpoint_prefix training\u002Fmodel.ckpt-XXXX --output_directory inference_graph\n```\n这将在 \\object_detection\\inference_graph 文件夹中创建一个 frozen_inference_graph.pb 文件。该 .pb 文件包含了目标检测分类器。\n\n### 8. 使用你新训练的目标检测分类器！\n目标检测分类器已经准备就绪！我已经编写了 Python 脚本，可以在图像、视频或网络摄像头流上对其进行测试。\n\n在运行这些 Python  scripts 之前，你需要将脚本中的 NUM_CLASSES 变量修改为你要检测的类别数量。（对于我的皮诺克牌检测器，我需要检测六种牌，因此 NUM_CLASSES = 6。）\n\n要测试你的目标检测器，可以将待检测物体的图片移动到 \\object_detection 文件夹中，并将 Object_detection_image.py 中的 IMAGE_NAME 变量修改为与图片文件名一致。你也可以使用包含这些物体的视频（使用 Object_detection_video.py），或者直接连接 USB 网络摄像头并将其对准待检测物体（使用 Object_detection_webcam.py）。\n\n要运行任何脚本，在激活了 “tensorflow1” 虚拟环境的 Anaconda 命令提示符中输入 “idle”，然后按 ENTER 键。这将打开 IDLE，你可以在其中打开任意脚本并运行它们。\n\n如果一切正常，目标检测器会初始化大约 10 秒钟，随后会显示一个窗口，展示它在图像中检测到的所有物体！\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_readme_73f68242d557.jpg\">\n\u003C\u002Fp>\n\n如果你遇到错误，请查看附录：其中列出了我在设置目标检测分类器时遇到的一些常见问题及解决方法。你也可以尝试在 Google 上搜索相关错误信息，通常在 Stack Exchange 或 TensorFlow 的 GitHub Issues 中能找到有用的解决方案。\n\n## 附录：常见错误\n看起来 TensorFlow 目标检测 API 是在基于 Linux 的操作系统上开发的，文档中的大部分说明也都是针对 Linux 系统的。要在 Windows 上让一个为 Linux 开发的软件库正常工作可能会比较困难。我在尝试在 Windows 10 上使用 tensorflow-gpu 训练目标检测分类器时，遇到了许多小问题。本附录列出了我遇到的一些错误及其解决方法。\n\n#### 1. ModuleNotFoundError: 没有名为 'deployment' 或 'nets' 的模块\n\n当尝试运行 object_detection_tutorial.ipynb 或 train.py 时，如果 PATH 和 PYTHONPATH 环境变量未正确设置，就会出现此错误。请关闭并重新打开 Anaconda 命令提示符窗口以退出虚拟环境，然后再次输入 “activate tensorflow1” 重新进入环境，并按照步骤 2e 中的说明设置环境变量。\n\n你可以使用 “echo %PATH%” 和 “echo %PYTHONPATH%” 来检查环境变量，确保它们已正确配置。\n\n此外，请确保你已在 \\models\\research 目录下执行了以下命令：\n```\nsetup.py build\nsetup.py install\n```\n\n#### 2. ImportError: 无法导入名称 'preprocessor_pb2'\n\n#### ImportError: 无法导入名称 'string_int_label_map_pb2'\n\n#### （或其他类似的 pb2 文件错误）\n\n这种情况通常是由于 protobuf 文件（例如 preprocessor.proto）未编译所致。请重新运行步骤 2f 中给出的 protoc 命令。检查 \\object_detection\\protos 文件夹，确保每个 name.proto 文件都有对应的 name_pb2.py 文件。\n\n#### 3. object_detection\u002Fprotos\u002F.proto: 没有此类文件或目录\n\n当你尝试运行 TensorFlow 目标检测 API 安装页面上给出的命令：\n```\n“protoc object_detection\u002Fprotos\u002F*.proto --python_out=.”\n```\n时，可能会出现此错误。遗憾的是，这个命令在 Windows 上无法正常工作！请改用步骤 2f 中给出的完整命令。虽然可能有更好的方法，但我目前还不清楚具体如何操作。\n\n#### 4. TensorSliceReader 构造函数失败：无法获取“文件路径”……文件名、目录名或卷标语法不正确。\n\n当训练配置文件（如 faster_rcnn_inception_v2_pets.config 或其他类似文件）中的文件路径使用正斜杠而非反斜杠时，就会出现此错误。请打开 .config 文件，确保所有文件路径都采用以下格式：\n```\n“C:\u002Fpath\u002Fto\u002Fmodel.file”\n```\n\n#### 5. ValueError: 尝试将 't' 转换为张量失败。错误：参数必须是一个密集张量：范围(0, 3) - 得到形状[3]，但期望[]。\n\n问题出在 models\u002Fresearch\u002Fobject_detection\u002Futils\u002Flearning_schedules.py 文件中。当前代码如下：\n```\nrate_index = tf.reduce_max(tf.where(tf.greater_equal(global_step, boundaries),\n                                      range(num_boundaries),\n                                      [0] * num_boundaries))\n```\n请将 range() 包裹在 list() 中，修改为：\n```\nrate_index = tf.reduce_max(tf.where(tf.greater_equal(global_step, boundaries),\n                                     list(range(num_boundaries)),\n                                      [0] * num_boundaries))\n```\n\n[参考：TensorFlow Issue#3705](https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Fissues\u002F3705#issuecomment-375563179)\n\n#### 6. ImportError: DLL 加载失败：找不到指定的过程。（或其他 DLL 相关错误）\n\n这种错误通常是由于你安装的 CUDA 和 cuDNN 版本与当前使用的 TensorFlow 版本不兼容所致。解决此问题最简单的方法是使用 Anaconda 的 cudatoolkit 包，而不是手动安装 CUDA 和 cuDNN。如果你遇到这些问题，可以尝试创建一个新的 Anaconda 虚拟环境：\n```\nconda create -n tensorflow2 pip python=3.5\n```\n然后在该环境中使用 CONDA 安装 TensorFlow，而不是 PIP：\n```\nconda install tensorflow-gpu\n```\n之后可以从步骤 2 重新开始本指南（但可以跳过步骤 2d 中安装 TensorFlow 的部分）。\n\n#### 7. 在步骤 2g 中，Jupyter Notebook 运行完毕且没有报错，但最终没有显示任何图片。\n\n如果你完整地运行了 Jupyter Notebook 并且没有出现任何错误，但仍然没有看到标注后的图片，请尝试以下操作：进入 object_detection\u002Futils\u002Fvisualization_utils.py 文件，注释掉第 29 和 30 行附近包含 matplotlib 的导入语句，然后再次运行 Jupyter Notebook。（visualization_utils.py 文件的内容可能会有所变化，因此具体的行数可能略有不同。）","# TensorFlow 多目标检测训练快速上手指南 (Windows)\n\n本指南基于 `TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10` 项目整理，旨在帮助开发者在 Windows 环境下从零开始训练自定义的多目标检测分类器。\n\n## 1. 环境准备\n\n### 系统要求\n*   **操作系统**: Windows 10 \u002F 8 \u002F 7 (本指南以 Win10 为主)\n*   **硬件**: 推荐配备 NVIDIA GPU 以加速训练（使用 CPU 亦可，但速度较慢）\n*   **软件版本参考**: 本教程原始基于 TensorFlow v1.13.1 (GPU 版)，但也适用于更新的 TF 1.x 版本。\n\n### 前置依赖\n在开始之前，请确保已安装以下核心组件：\n1.  **Anaconda**: 用于管理 Python 虚拟环境和依赖包。\n2.  **CUDA & cuDNN**: NVIDIA 显卡加速库。\n    *   *注意*: 若使用 Anaconda 安装 `tensorflow-gpu`，它通常会自动安装兼容版本的 CUDA 和 cuDNN，无需手动配置环境变量。\n    *   若需手动安装，请参考 [TensorFlow 官方构建配置表](https:\u002F\u002Fwww.tensorflow.org\u002Finstall\u002Fsource#tested_build_configurations) 匹配版本。\n\n## 2. 安装步骤\n\n### 2.1 创建目录结构与克隆代码\n在 C 盘根目录创建工作文件夹 `tensorflow1`，并下载 TensorFlow Models 仓库。\n\n```powershell\n# 创建目录\nmkdir C:\\tensorflow1\ncd C:\\tensorflow1\n\n# 克隆 models 仓库 (建议使用最新稳定版或对应 TF 版本的 commit)\ngit clone https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels.git\n```\n*注：克隆后文件夹名为 `models`。如果下载的是 zip 包，请解压并将文件夹重命名为 `models`。*\n\n### 2.2 配置 Anaconda 虚拟环境\n创建独立的 Python 环境并安装必要依赖。\n\n```powershell\n# 创建名为 'tensorflow1' 的虚拟环境，指定 Python 版本 (推荐 3.6 或 3.7 适配 TF 1.x)\nconda create -n tensorflow1 pip python=3.7\n\n# 激活环境\nconda activate tensorflow1\n\n# 安装 TensorFlow GPU 版本 (如需 CPU 版则安装 tensorflow)\npip install tensorflow-gpu==1.13.1\n\n# 安装其他必要依赖\npip install lxml\npip install pillow\npip install jupyter\npip install matplotlib\npip install pandas\n\n# 安装 protobuf 编译器\nconda install -c anaconda protobuf\n```\n\n### 2.3 编译 Protobuf 并配置环境变量\nTensorFlow Object Detection API 需要编译 `.proto` 文件并设置 `PYTHONPATH`。\n\n```powershell\n# 进入 research 目录\ncd C:\\tensorflow1\\models\\research\n\n# 编译 protobuf 文件 (Windows 下使用 protoc.exe)\n# 需先下载 protoc.zip (从 GitHub google\u002Fprotobuf  releases), 解压到 research 目录或系统路径\nprotoc object_detection\u002Fprotos\u002F*.proto --python_out=.\n\n# 复制 setup.py 到当前目录并安装\ncp object_detection\u002Fpackages\u002Ftf1\u002Fsetup.py .\npython setup.py build\npython setup.py install\n\n# 设置 PYTHONPATH 环境变量 (临时生效，建议添加到系统环境变量中永久生效)\nset PYTHONPATH=C:\\tensorflow1\\models;C:\\tensorflow1\\models\\research;C:\\tensorflow1\\models\\research\\slim\n```\n\n### 2.4 下载预训练模型\n从 TensorFlow Model Zoo 下载预训练权重（例如 `faster_rcnn_inception_v2_coco`）。\n\n1.  访问 [TF1 Detection Zoo](https:\u002F\u002Fgithub.com\u002Ftensorflow\u002Fmodels\u002Fblob\u002Fmaster\u002Fresearch\u002Fobject_detection\u002Fg3doc\u002Ftf1_detection_zoo.md)。\n2.  下载对应的 `.tar.gz` 文件。\n3.  解压到 `C:\\tensorflow1\\models\\research\\object_detection` 目录下。\n\n## 3. 基本使用流程\n\n以下是训练自定义检测器的核心逻辑简述：\n\n### 3.1 准备数据集\n1.  **收集图片**: 将训练图片放入 `C:\\tensorflow1\\models\\research\\object_detection\\images\\train` 和 `...\\test`。\n2.  **标注图片**: 使用工具（如 LabelImg）标注图片，生成 `.xml` 文件。\n3.  **生成记录**: 运行脚本将 XML 转换为 CSV，再转换为 TFRecord 格式。\n    ```powershell\n    # 示例：生成 TFRecord (需根据实际脚本名称调整)\n    python generate_tfrecord.py --csv_path=images\\train_labels.csv --image_path=images\\train --output_path=train.record\n    python generate_tfrecord.py --csv_path=images\\test_labels.csv --image_path=images\\test --output_path=test.record\n    ```\n\n### 3.2 配置标签映射与训练参数\n1.  **创建 label_map.pbtxt**: 定义类别 ID 与名称的映射。\n    ```text\n    item {\n      id: 1\n      name: 'object_class_1'\n    }\n    item {\n      id: 2\n      name: 'object_class_2'\n    }\n    ```\n2.  **修改配置文件**: 在 `object_detection\u002Fsamples\u002Fconfigs\u002F` 中找到对应模型的 `.config` 文件（如 `faster_rcnn_inception_v2_coco.config`）。\n    *   修改 `num_classes` 为你的类别数量。\n    *   修改 `fine_tune_checkpoint` 指向下载的预训练模型路径。\n    *   修改 `train_input_reader` 和 `eval_input_reader` 中的 `label_map_path` 和 `tf_record_input_reader` 路径。\n\n### 3.3 开始训练\n运行训练脚本。\n\n```powershell\n# 进入 object_detection 目录\ncd C:\\tensorflow1\\models\\research\\object_detection\n\n# 启动训练 (model_config_path 指向修改后的 config 文件)\npython model_main.py --model_dir=training\u002F --pipeline_config_path=training\u002Ffaster_rcnn_inception_v2_coco.config --num_train_steps=50000\n```\n\n### 3.4 导出推理图 (Inference Graph)\n训练完成后，将检查点导出为冻结的图形文件以便部署。\n\n```powershell\npython export_inference_graph.py --input_type image_tensor --pipeline_config_path training\u002Ffaster_rcnn_inception_v2_coco.config --trained_checkpoint_prefix training\u002Fmodel.ckpt-50000 --output_directory inference_graph\n```\n\n### 3.5 测试检测器\n使用提供的测试脚本（如 `object_detection_tutorial.ipynb` 或自定义 Python 脚本）加载 `inference_graph` 中的 `frozen_inference_graph.pb` 文件，对图片、视频或摄像头进行实时检测。\n\n---\n*提示：国内开发者若遇到 GitHub 下载慢的问题，可使用 Gitee 镜像或国内加速代理下载 `models` 仓库及预训练模型文件。*","某小型智能仓储团队需要在 Windows 工作站上快速开发一套系统，用于自动识别并分拣传送带上混放的六种不同规格零件。\n\n### 没有 TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10 时\n- **环境配置困难**：团队成员缺乏深度学习经验，在 Windows 上手动配置 CUDA、cuDNN 及 TensorFlow 依赖时频繁报错，耗时数天仍无法跑通基础代码。\n- **数据流程断裂**：不知道如何将采集的零件图片转换为模型可接受的 TFRecord 格式，也缺乏生成标签映射文件（label map）的标准脚本，导致数据准备停滞。\n- **训练无从下手**：面对复杂的配置文件和训练参数不知所措，不清楚如何针对多类别物体调整网络结构，只能盲目尝试或放弃自定义训练。\n- **部署验证缺失**：即使勉强完成训练，也缺乏现成的推理脚本来导出冻结图（inference graph）并实时测试检测效果，无法验证模型是否可用。\n\n### 使用 TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10 后\n- **一键搭建环境**：依照教程步骤，利用 Anaconda 虚拟环境快速安装了兼容 GPU 加速的完整开发栈，将原本数天的环境调试缩短至几小时。\n- **标准化数据处理**：直接使用提供的 Python 脚本批量生成训练数据和标签映射文件，轻松将自定义的零件图片集转化为标准输入格式。\n- **清晰训练路径**：参考教程中关于配置文件修改和训练命令的详细指南，顺利启动了针对六种零件的多类别训练任务，并实时监控损失函数收敛情况。\n- **即时成果验证**：利用导出的推理图和测试脚本，立即在摄像头画面中看到了对各类零件的精准框选与分类，快速完成了从数据到原型的闭环。\n\n该教程通过提供端到端的 Windows 实战指南，极大地降低了自定义多类别物体检测模型的门槛，让非算法专家也能高效落地工业视觉应用。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FEdjeElectronics_TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10_201e6a37.jpg","EdjeElectronics","Evan","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FEdjeElectronics_8523fa08.jpg","Computer vision engineer and founder at EJ Technology Consultants.","EJ Technology Consultants","Bozeman, MT","evan.juras@ejtech.io","https:\u002F\u002Fejtech.io","https:\u002F\u002Fgithub.com\u002FEdjeElectronics",[82],{"name":83,"color":84,"percentage":85},"Python","#3572A5",100,2929,1276,"2026-04-15T10:46:44","Apache-2.0",4,"Windows 10, Windows 8, Windows 7, Linux","可选但强烈推荐（使用 TensorFlow-GPU 可将训练时间缩短约 8 倍）。需 NVIDIA 显卡，具体型号未说明。CUDA 和 cuDNN 版本需与安装的 TensorFlow 版本严格对应（例如 TF v1.13.1 需特定版本），Anaconda 会自动安装兼容版本。","未说明",{"notes":95,"python":96,"dependencies":97},"本教程主要针对 Windows 环境，Linux 需调整文件路径和安装命令。必须严格按照指定目录结构（如 C:\\tensorflow1）配置。若使用旧版 TensorFlow，需下载对应的 GitHub models 仓库提交版本以避免兼容性错误。CPU 版本也可运行但训练速度极慢。","通过 Anaconda 管理，具体版本取决于所选 TensorFlow 版本（文中示例为 TF v1.5 至 v1.13.1，通常对应 Python 3.6-3.7）",[98,99,100,101,102,103,104,105,106],"tensorflow-gpu (v1.5 - v1.13.1+)","anaconda","cuda","cudnn","protobuf","lxml","jupyter","matplotlib","pillow",[15,14],null,"2026-03-27T02:49:30.150509","2026-04-18T14:12:05.504432",[112,117,122,127,132,136],{"id":113,"question_zh":114,"answer_zh":115,"source_url":116},39772,"运行对象检测脚本时出现 'TypeError: int() argument must be a string... not NoneType' 错误怎么办？","该错误通常发生在将图像数据传入模型时，输入变量（如 frame_expanded 或 image_expanded）为 None。这往往是因为图像读取失败（例如文件路径错误或文件损坏），导致 cv2.imread() 返回了 None。请检查：1. 图像文件路径是否正确；2. 图像文件是否完整可读；3. 在调用 sess.run 之前添加判断，确保图像不为 None 再进行后续处理。","https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10\u002Fissues\u002F101",{"id":118,"question_zh":119,"answer_zh":120,"source_url":121},39773,"训练时出现 'ValueError: Tried to convert t to a tensor and failed' 或配置相关错误如何解决？","此类错误常与配置文件（.config）中的参数设置不当有关，特别是 batch_size 的设置。有用户指出，某些配置文件（如 faster_rcnn_inception_v2_pets.config）的 batch_size 默认值为 1，而其他模型可能设为 24。如果显存不足或环境不匹配，尝试调整 config 文件中的 batch_size 值。此外，确保使用的是与教程匹配的 TensorFlow 版本（通常是 TF 1.x），因为 TF 2.0 已移除 contrib 模块会导致导入错误。","https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10\u002Fissues\u002F11",{"id":123,"question_zh":124,"answer_zh":125,"source_url":126},39774,"导入模块时出现 'ImportError: cannot import name center_net_pb2' 错误的原因及解决方法？","该错误表明 protobuf 文件未正确生成。在 TensorFlow Object Detection API 中，必须先将 .proto 文件编译为 _pb2.py 文件。解决方法是进入 research 目录，运行 protoc 命令生成所有必要的 python 文件。具体命令通常为：\nprotoc object_detection\u002Fprotos\u002F*.proto --python_out=.\n确保已安装 protoc 编译器并将其添加到系统环境变量中。如果只生成了部分文件，请删除旧的 _pb2.py 文件后重新运行该命令。","https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10\u002Fissues\u002F501",{"id":128,"question_zh":129,"answer_zh":130,"source_url":131},39775,"为了在 Android 上使用并转换为 .tflite 格式，应该选择哪个配置文件进行训练？","若目标是部署到 Android 并转换为 TFLite 格式，推荐使用轻量级模型配置。常见的选择包括 ssdlite_mobilenet_v1_coco.config 或 ssd_mobilenet_v1_quantized_300x300_coco14_sync.config。量化版本（quantized）通常更适合移动端，因为它能减小模型体积并提高推理速度。注意，Faster R-CNN 等重型模型通常不支持直接转换为高效的 TFLite 格式。","https:\u002F\u002Fgithub.com\u002FEdjeElectronics\u002FTensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10\u002Fissues\u002F185",{"id":133,"question_zh":134,"answer_zh":135,"source_url":121},39776,"运行 train.py 时提示 'ModuleNotFoundError: No module named nets' 或类似导入错误怎么办？","这通常是因为缺少必要的依赖库或未正确设置 Python 路径。首先确保已安装 tensorflow-gpu（如果需要 GPU）以及 matplotlib、lxml、jupyter 等教程要求的依赖包。其次，检查是否在正确的虚拟环境（如 tensorflow1）中激活并运行脚本。如果是从 GitHub 克隆的代码，确保执行了 setup.py 安装步骤：pip install . 或在 research 目录下运行 python setup.py build。",{"id":137,"question_zh":138,"answer_zh":139,"source_url":116},39777,"为什么我的代码在别人的机器上能跑，在我这里却报 'NoneType' 相关的类型错误？","最常见的原因是图像加载路径问题。在不同操作系统（如 Windows 与 Linux）或不同目录结构下，相对路径和绝对路径的处理方式不同，导致程序找不到图片文件，从而读取到 None。解决方案：1. 使用绝对路径测试；2. 打印图像加载后的变量确认是否为 None；3. 检查代码中是否有针对 Windows 路径分隔符（\\）的特殊处理需求；4. 确保输入视频流或摄像头索引正确无误。",[]]