{"id":2048,"date":"2022-02-23T16:02:38","date_gmt":"2022-02-23T16:02:38","guid":{"rendered":"https:\/\/dreid.nl\/?p=2048"},"modified":"2022-04-15T08:31:52","modified_gmt":"2022-04-15T08:31:52","slug":"how-to-get-started-with-the-google-tensorflow-object-detection-api","status":"publish","type":"post","link":"https:\/\/dreid.nl\/?p=2048","title":{"rendered":"How to get started with the Google Tensorflow Object Detection API"},"content":{"rendered":"<p>Object detection and recognition is a hot item, and massive advances have been achieved in recent years thanks to Convolutional Neural Networks (CNNs). Besides the technology, you also need either labelled training data or pre-trained models. The <a href=\"https:\/\/cocodataset.org\/#home\" target=\"_blank\" rel=\"noopener\">COCO dataset<\/a> is a popular set of images used for training and evaluating object detection models.<\/p>\n<p>Google provide an <a href=\"https:\/\/github.com\/tensorflow\/models\/blob\/master\/research\/object_detection\/g3doc\/tf2.md\" target=\"_blank\" rel=\"noopener\">object detection API<\/a>, including models that are trained on COCO. The Github page explains how to download and install it. You might have to install <a href=\"https:\/\/git-scm.com\/download\/win\" target=\"_blank\" rel=\"noopener\">git<\/a> and <a href=\"https:\/\/github.com\/protocolbuffers\/protobuf\/releases\" target=\"_blank\" rel=\"noopener\">protoc<\/a> first. I assume that you already have a running Python environment for data science and Machine Learning &#8211; on Windows, <a href=\"https:\/\/www.anaconda.com\/products\/individual\" target=\"_blank\" rel=\"noopener\">Anaconda<\/a> is the easiest way to get this up and running.<\/p>\n<p>How to do inference is shown in a <a href=\"https:\/\/github.com\/tensorflow\/models\/blob\/master\/research\/object_detection\/colab_tutorials\/inference_tf2_colab.ipynb\" target=\"_blank\" rel=\"noopener\">Colab<\/a>. You can take the code here and paste it into a Python file. You&#8217;ll have to make a few minor adjustments. Instead of downloading and unpacking a model as shown in the Colab, I recommend manually downloading the models from <a href=\"https:\/\/github.com\/tensorflow\/models\/blob\/master\/research\/object_detection\/g3doc\/tf2_detection_zoo.md\" target=\"_blank\" rel=\"noopener\">the model zoo<\/a> and unpacking them to the models\\research\\object_detection\\test_data folder. I could not get it to work with one of the keypoints models and only used models without keypoints.<\/p>\n<p>In the Python script, you need to modify the path to the config and model checkpoint:<\/p>\n<p><code>pipeline_config = 'models\/research\/object_detection\/test_data\/efficientdet_d7_coco17_tpu-32\/pipeline.config'<br \/>\nmodel_dir = 'models\/research\/object_detection\/test_data\/efficientdet_d7_coco17_tpu-32\/checkpoint\/'<\/code><\/p>\n<p>In the pipeline config file, you need to set the path to the label definitions:<\/p>\n<p><code>eval_input_reader: {<br \/>\nlabel_map_path: \"models\/research\/object_detection\/data\/mscoco_label_map.pbtxt\"<\/code><\/p>\n<p>The plotting functions in the Colab use the inline plt.show() functionality, but this will not work in a script run through the command line Python interpreter.This needs to be replaced by saving to file, e.g.<\/p>\n<p><code>plt.savefig('img1.png')<br \/>\nplt.close()<\/code><br \/>\nYou should then be able to run the Python script and get as output an image with the bounding boxes:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-2050\" src=\"http:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1-1024x563.png\" alt=\"\" width=\"1024\" height=\"563\" srcset=\"https:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1-1024x563.png 1024w, https:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1-300x165.png 300w, https:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1-768x422.png 768w, https:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1-1536x845.png 1536w, https:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1-600x330.png 600w, https:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1.png 1964w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>You can try different models. For the non-Centernet models, you&#8217;ll have to disable the plotting of heatmaps. Models with a larger input size can detect more detail, but are slower.<\/p>\n<p>You can try GPU-based processing. This requires the installation of Nvidia CUDA, cuDNN, and probably Zlib &#8211; and of course a CUDA-capable GPU.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Object detection and recognition is a hot item, and massive advances have been achieved in recent years thanks to Convolutional Neural Networks (CNNs). Besides the technology, you also need either labelled training data or pre-trained models. The COCO dataset is a popular set of images used for training and evaluating object detection models. Google provide [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2050,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[100],"tags":[112,111],"class_list":{"0":"post-2048","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-blog","8":"tag-image-processing","9":"tag-machine-learning","10":"czr-hentry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to get started with the Google Tensorflow Object Detection API - DreiD BV<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dreid.nl\/?p=2048\" \/>\n<meta property=\"og:locale\" content=\"nl_NL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to get started with the Google Tensorflow Object Detection API - DreiD BV\" \/>\n<meta property=\"og:description\" content=\"Object detection and recognition is a hot item, and massive advances have been achieved in recent years thanks to Convolutional Neural Networks (CNNs). Besides the technology, you also need either labelled training data or pre-trained models. The COCO dataset is a popular set of images used for training and evaluating object detection models. Google provide [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dreid.nl\/?p=2048\" \/>\n<meta property=\"og:site_name\" content=\"DreiD BV\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DreiDBV\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-23T16:02:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-15T08:31:52+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1964\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Tobias\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Geschreven door\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tobias\" \/>\n\t<meta name=\"twitter:label2\" content=\"Verwachte leestijd\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/dreid.nl\\\/?p=2048#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dreid.nl\\\/?p=2048\"},\"author\":{\"name\":\"Tobias\",\"@id\":\"https:\\\/\\\/dreid.nl\\\/#\\\/schema\\\/person\\\/724765ca445bdd176b5dfa6f0f432741\"},\"headline\":\"How to get started with the Google Tensorflow Object Detection API\",\"datePublished\":\"2022-02-23T16:02:38+00:00\",\"dateModified\":\"2022-04-15T08:31:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/dreid.nl\\\/?p=2048\"},\"wordCount\":353,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/dreid.nl\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/dreid.nl\\\/?p=2048#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/dreid.nl\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/img1-1.png\",\"keywords\":[\"Image processing\",\"Machine Learning\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/dreid.nl\\\/?p=2048#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/dreid.nl\\\/?p=2048\",\"url\":\"https:\\\/\\\/dreid.nl\\\/?p=2048\",\"name\":\"How to get started with the Google Tensorflow Object Detection API - DreiD BV\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dreid.nl\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/dreid.nl\\\/?p=2048#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/dreid.nl\\\/?p=2048#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/dreid.nl\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/img1-1.png\",\"datePublished\":\"2022-02-23T16:02:38+00:00\",\"dateModified\":\"2022-04-15T08:31:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/dreid.nl\\\/?p=2048#breadcrumb\"},\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/dreid.nl\\\/?p=2048\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\\\/\\\/dreid.nl\\\/?p=2048#primaryimage\",\"url\":\"https:\\\/\\\/dreid.nl\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/img1-1.png\",\"contentUrl\":\"https:\\\/\\\/dreid.nl\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/img1-1.png\",\"width\":1964,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/dreid.nl\\\/?p=2048#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/dreid.nl\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to get started with the Google Tensorflow Object Detection API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/dreid.nl\\\/#website\",\"url\":\"https:\\\/\\\/dreid.nl\\\/\",\"name\":\"DreiD BV\",\"description\":\"3D printen en meer\",\"publisher\":{\"@id\":\"https:\\\/\\\/dreid.nl\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/dreid.nl\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"nl-NL\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/dreid.nl\\\/#organization\",\"name\":\"DreiD B.V.\",\"url\":\"https:\\\/\\\/dreid.nl\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\\\/\\\/dreid.nl\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"http:\\\/\\\/dreid.nl\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/cropped-logo-vierkant.png\",\"contentUrl\":\"http:\\\/\\\/dreid.nl\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/cropped-logo-vierkant.png\",\"width\":512,\"height\":512,\"caption\":\"DreiD B.V.\"},\"image\":{\"@id\":\"https:\\\/\\\/dreid.nl\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/DreiDBV\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/dreid.nl\\\/#\\\/schema\\\/person\\\/724765ca445bdd176b5dfa6f0f432741\",\"name\":\"Tobias\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/da384b41c29915cbc57151669bfd69215048a0d4cebed631ab35a6f893826870?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/da384b41c29915cbc57151669bfd69215048a0d4cebed631ab35a6f893826870?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/da384b41c29915cbc57151669bfd69215048a0d4cebed631ab35a6f893826870?s=96&d=mm&r=g\",\"caption\":\"Tobias\"},\"url\":\"https:\\\/\\\/dreid.nl\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to get started with the Google Tensorflow Object Detection API - DreiD BV","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dreid.nl\/?p=2048","og_locale":"nl_NL","og_type":"article","og_title":"How to get started with the Google Tensorflow Object Detection API - DreiD BV","og_description":"Object detection and recognition is a hot item, and massive advances have been achieved in recent years thanks to Convolutional Neural Networks (CNNs). Besides the technology, you also need either labelled training data or pre-trained models. The COCO dataset is a popular set of images used for training and evaluating object detection models. Google provide [&hellip;]","og_url":"https:\/\/dreid.nl\/?p=2048","og_site_name":"DreiD BV","article_publisher":"https:\/\/www.facebook.com\/DreiDBV","article_published_time":"2022-02-23T16:02:38+00:00","article_modified_time":"2022-04-15T08:31:52+00:00","og_image":[{"width":1964,"height":1080,"url":"http:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1.png","type":"image\/png"}],"author":"Tobias","twitter_card":"summary_large_image","twitter_misc":{"Geschreven door":"Tobias","Verwachte leestijd":"2 minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dreid.nl\/?p=2048#article","isPartOf":{"@id":"https:\/\/dreid.nl\/?p=2048"},"author":{"name":"Tobias","@id":"https:\/\/dreid.nl\/#\/schema\/person\/724765ca445bdd176b5dfa6f0f432741"},"headline":"How to get started with the Google Tensorflow Object Detection API","datePublished":"2022-02-23T16:02:38+00:00","dateModified":"2022-04-15T08:31:52+00:00","mainEntityOfPage":{"@id":"https:\/\/dreid.nl\/?p=2048"},"wordCount":353,"commentCount":0,"publisher":{"@id":"https:\/\/dreid.nl\/#organization"},"image":{"@id":"https:\/\/dreid.nl\/?p=2048#primaryimage"},"thumbnailUrl":"https:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1.png","keywords":["Image processing","Machine Learning"],"articleSection":["Blog"],"inLanguage":"nl-NL","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dreid.nl\/?p=2048#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dreid.nl\/?p=2048","url":"https:\/\/dreid.nl\/?p=2048","name":"How to get started with the Google Tensorflow Object Detection API - DreiD BV","isPartOf":{"@id":"https:\/\/dreid.nl\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dreid.nl\/?p=2048#primaryimage"},"image":{"@id":"https:\/\/dreid.nl\/?p=2048#primaryimage"},"thumbnailUrl":"https:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1.png","datePublished":"2022-02-23T16:02:38+00:00","dateModified":"2022-04-15T08:31:52+00:00","breadcrumb":{"@id":"https:\/\/dreid.nl\/?p=2048#breadcrumb"},"inLanguage":"nl-NL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dreid.nl\/?p=2048"]}]},{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/dreid.nl\/?p=2048#primaryimage","url":"https:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1.png","contentUrl":"https:\/\/dreid.nl\/wp-content\/uploads\/2022\/02\/img1-1.png","width":1964,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/dreid.nl\/?p=2048#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dreid.nl\/"},{"@type":"ListItem","position":2,"name":"How to get started with the Google Tensorflow Object Detection API"}]},{"@type":"WebSite","@id":"https:\/\/dreid.nl\/#website","url":"https:\/\/dreid.nl\/","name":"DreiD BV","description":"3D printen en meer","publisher":{"@id":"https:\/\/dreid.nl\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dreid.nl\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"nl-NL"},{"@type":"Organization","@id":"https:\/\/dreid.nl\/#organization","name":"DreiD B.V.","url":"https:\/\/dreid.nl\/","logo":{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/dreid.nl\/#\/schema\/logo\/image\/","url":"http:\/\/dreid.nl\/wp-content\/uploads\/2017\/11\/cropped-logo-vierkant.png","contentUrl":"http:\/\/dreid.nl\/wp-content\/uploads\/2017\/11\/cropped-logo-vierkant.png","width":512,"height":512,"caption":"DreiD B.V."},"image":{"@id":"https:\/\/dreid.nl\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DreiDBV"]},{"@type":"Person","@id":"https:\/\/dreid.nl\/#\/schema\/person\/724765ca445bdd176b5dfa6f0f432741","name":"Tobias","image":{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/secure.gravatar.com\/avatar\/da384b41c29915cbc57151669bfd69215048a0d4cebed631ab35a6f893826870?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/da384b41c29915cbc57151669bfd69215048a0d4cebed631ab35a6f893826870?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/da384b41c29915cbc57151669bfd69215048a0d4cebed631ab35a6f893826870?s=96&d=mm&r=g","caption":"Tobias"},"url":"https:\/\/dreid.nl\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/dreid.nl\/index.php?rest_route=\/wp\/v2\/posts\/2048","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dreid.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dreid.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dreid.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dreid.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2048"}],"version-history":[{"count":2,"href":"https:\/\/dreid.nl\/index.php?rest_route=\/wp\/v2\/posts\/2048\/revisions"}],"predecessor-version":[{"id":2195,"href":"https:\/\/dreid.nl\/index.php?rest_route=\/wp\/v2\/posts\/2048\/revisions\/2195"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dreid.nl\/index.php?rest_route=\/wp\/v2\/media\/2050"}],"wp:attachment":[{"href":"https:\/\/dreid.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dreid.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dreid.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}