SlideShare a Scribd company logo
1 of 16
Training
Custom
Object
Detection
Model in GCP
Cloud ML
Engine
Prerequisite
• Install Git
• Install Tensorflow
• Requires Python 3.4, 3.5, or 3.6
• pip install tensorflow # CPU Version
• https://www.tensorflow.org/install
• Download Tensorflow models git
• git clone https://github.com/tensorflow/models
• Some other python libraries
• Pillow, lxml, contextlib2 (use pip install)
• Install Google cloud SDK
• https://cloud.google.com/sdk/docs/quickstart-windows
Setup Google Cloud Platform
• Create Google Cloud Platform (GCP) Account
• Create a project
• Enable Billing
• On Command prompt (Terminal)
• gcloud init
• gcloud config auth list
• gcloud config list
• gcloud config set project
Protobuf
• The TensorFlow Object Detection API uses .proto files which need to be
compiled into .py files. Google provides a program called Protobuf that
will batch compile these.
• cd models/research
• For windows
• Download version 3.4.0 for Windows from
https://github.com/protocolbuffers/protobuf/releases/tag/v3.4.0
• “E:Object_Detectiondemoprotoc-3.4.0-win32binprotoc.exe"
object_detectionprotos*.proto --python_out=.
• For Linux
• sudo apt-get install protobuf-compiler
• protoc object_detection/protos/*.proto --python_out=.
• You will see multiple python files now in “object_detectionprotos” folder
Environment Setup
• Linux
• export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
• Windows
• Add to Environment Variable
• modelsresearch
• modelsresearchslim
• Test Installation
• python object_detection/builders/model_builder_test.py
• If no errors installation is perfect
Create Dataset
• Create two folders:
• images
• Image Name Format: categoryName_imageID.jpg (only one "_")
• annotations
• trainval.txt
• categoryName_imageID category_ID (80% images for train/val)
• test.txt
• categoryName_imageID category_ID (20% images for test)
• list.txt
• categoryName_imageID category_ID (all images)
• xmls
• categoryName_imageID.xml
• Label_map.pbtxt
• Note:
• Make sure no image is corrupt, bounding boxes are well defined.
• Bounding box co-ordinates do not fall outside of image height and width.
• Image Height and width are correct.
• If one image has many object of same kind, only one copy of image is needed with respective object category name and all bounding box locations in
xml.
• If image has many object of different category, multiple copies of same image will be stored with one object category in image name in one copy
Samples
images
annotations
xmls
Sample xml
Label_map.pbtxt
Create TFRecord
• The Tensorflow Object Detection API uses the TFRecord format for
training and validation datasets
• python object_detection/dataset_tools/create_pet_tf_record.py
--label_map_path=E:Object_Detectiondemolabel_map.pbtxt
--data_dir=E:Object_Detectiondemo
--output_dir=E:Object_Detectiondemo
• You will see two new files at output_dir location
• pet_train.record
• pet_val.record
Move data to GCS (Google Cloud Storage)
• Create a new bucket
• gsutil mb gs://train_coke
• Set bucket name for future use
• set YOUR_GCS_BUCKET=gs://train_coke
• Move file to new GCS Bucket
• gsutil cp pet_train.record %YOUR_GCS_BUCKET%/data/pet_train.record
• gsutil cp pet_val.record %YOUR_GCS_BUCKET%/data/pet_val.record
• gsutil cp label_map.pbtxt %YOUR_GCS_BUCKET%/data/pet_label_map.pbtxt
Transfer Learning
• Upload trained model to GCS
• wget
https://storage.googleapis.com/download.tensorflow.org/models/object_detection/fast
er_rcnn_resnet101_coco_11_06_2017.tar.gz
• tar -xvf faster_rcnn_resnet101_coco_11_06_2017.tar.gz
• gsutil cp faster_rcnn_resnet101_coco_11_06_2017/model.ckpt.*
%YOUR_GCS_BUCKET%/data/
• Edit Config File
• sed -i "s|PATH_TO_BE_CONFIGURED|"${YOUR_GCS_BUCKET}" data|g"
object_detection/samples/configs/faster_rcnn_resnet101_pets.config #Linux
• gsutil cp object_detection/samples/configs/faster_rcnn_resnet101_pets.config
%YOUR_GCS_BUCKET%/data/faster_rcnn_resnet101_pets.config
• Tensorflow detection model zoo
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/det
ection_model_zoo.md
Train Model
• Package the TensorFlow Object Detection API and TF Slim
• python setup.py sdist
• cd slim
• python setup.py sdist
• Enable Cloud Machine Learning Engine API
• bash object_detection/dataset_tools/create_pycocotools_package.sh /tmp/pycocotools (#Linux)
• gcloud ml-engine jobs submit training object_detection_coke
--runtime-version 1.9
--job-dir=%YOUR_GCS_BUCKET%/model_dir
--packages dist/object_detection-0.1.tar.gz,slim/dist/slim-0.1.tar.gz,pycocotools/pycocotools-2.0.tar.gz
--module-name object_detection.model_main
--region us-east1
--config object_detection/samples/cloud/cloud.yml
--
--model_dir=%YOUR_GCS_BUCKET%/model_dir
--pipeline_config_path=%YOUR_GCS_BUCKET%/data/faster_rcnn_resnet101_pets.config
• Get Logs
• gcloud ml-engine jobs stream-logs object_detection_pets
Tensorboard
• pip install tensorboard
• From cloudshell
• tensorboard --logdir=${YOUR_GCS_BUCKET}/model_dir --port=5000
Export Trained Model
• Get model checkpoint number
• Set CHECKPOINT_NUMBER=2975
• set YOUR_LOCAL_CHK_DIR=exported_model
• Copy model checkpoint files to local from GCS
• gsutil cp %YOUR_GCS_BUCKET%/model_dir/model.ckpt-
%CHECKPOINT_NUMBER%.* % YOUR_LOCAL_CHK_DIR%
• Export Inference Graph
• python object_detection/export_inference_graph.py
--input_type image_tensor
--pipeline_config_path
object_detection/samples/configs/faster_rcnn_resnet101_pets.config
--trained_checkpoint_prefix %YOUR_LOCAL_CHK_DIR%/model.ckpt-
%CHECKPOINT_NUMBER%
--output_directory exported_graphs
Test Model
References
• https://cloud.google.com/blog/products/gcp/training-an-object-
detector-using-cloud-machine-learning-engine
• https://towardsdatascience.com/google-object-detection-api-to-
detect-brand-logos-fd9e113725d8
• https://towardsdatascience.com/google-object-detection-api-to-
detect-brand-logos-part-2-384055e4e109
• Git Repo
• https://github.com/sahuvaibhav/Object_Detection

More Related Content

What's hot

Luigi presentation NYC Data Science
Luigi presentation NYC Data ScienceLuigi presentation NYC Data Science
Luigi presentation NYC Data ScienceErik Bernhardsson
 
Monitoring MySQL with Prometheus, Grafana and Percona Dashboards
Monitoring MySQL with Prometheus, Grafana and Percona DashboardsMonitoring MySQL with Prometheus, Grafana and Percona Dashboards
Monitoring MySQL with Prometheus, Grafana and Percona DashboardsJulien Pivotto
 
2019 IRIS-HEP AS workshop: Boost-histogram and hist
2019 IRIS-HEP AS workshop: Boost-histogram and hist2019 IRIS-HEP AS workshop: Boost-histogram and hist
2019 IRIS-HEP AS workshop: Boost-histogram and histHenry Schreiner
 
Getting to Know Airflow
Getting to Know AirflowGetting to Know Airflow
Getting to Know AirflowRosanne Hoyem
 
Gotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipelineGotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipelineAnton Babenko
 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowPyData
 
H2O World - PySparkling Water - Nidhi Mehta
H2O World - PySparkling Water - Nidhi MehtaH2O World - PySparkling Water - Nidhi Mehta
H2O World - PySparkling Water - Nidhi MehtaSri Ambati
 
Building an analytics workflow using Apache Airflow
Building an analytics workflow using Apache AirflowBuilding an analytics workflow using Apache Airflow
Building an analytics workflow using Apache AirflowYohei Onishi
 
Jonathan Coveney: Why Pig?
Jonathan Coveney: Why Pig?Jonathan Coveney: Why Pig?
Jonathan Coveney: Why Pig?mortardata
 
(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag Session(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag SessionJens Hadlich
 
Introduction to Garbage Collection
Introduction to Garbage CollectionIntroduction to Garbage Collection
Introduction to Garbage CollectionArtur Mkrtchyan
 
Luigi Presentation at OSCON 2013
Luigi Presentation at OSCON 2013Luigi Presentation at OSCON 2013
Luigi Presentation at OSCON 2013Erik Bernhardsson
 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowLaura Lorenz
 
InfluxDB & Kubernetes
InfluxDB & KubernetesInfluxDB & Kubernetes
InfluxDB & KubernetesInfluxData
 

What's hot (20)

Luigi presentation NYC Data Science
Luigi presentation NYC Data ScienceLuigi presentation NYC Data Science
Luigi presentation NYC Data Science
 
Monitoring MySQL with Prometheus, Grafana and Percona Dashboards
Monitoring MySQL with Prometheus, Grafana and Percona DashboardsMonitoring MySQL with Prometheus, Grafana and Percona Dashboards
Monitoring MySQL with Prometheus, Grafana and Percona Dashboards
 
2019 IRIS-HEP AS workshop: Boost-histogram and hist
2019 IRIS-HEP AS workshop: Boost-histogram and hist2019 IRIS-HEP AS workshop: Boost-histogram and hist
2019 IRIS-HEP AS workshop: Boost-histogram and hist
 
Getting to Know Airflow
Getting to Know AirflowGetting to Know Airflow
Getting to Know Airflow
 
Gotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipelineGotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipeline
 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with Airflow
 
Fun421 stephens
Fun421 stephensFun421 stephens
Fun421 stephens
 
H2O World - PySparkling Water - Nidhi Mehta
H2O World - PySparkling Water - Nidhi MehtaH2O World - PySparkling Water - Nidhi Mehta
H2O World - PySparkling Water - Nidhi Mehta
 
Building an analytics workflow using Apache Airflow
Building an analytics workflow using Apache AirflowBuilding an analytics workflow using Apache Airflow
Building an analytics workflow using Apache Airflow
 
Jonathan Coveney: Why Pig?
Jonathan Coveney: Why Pig?Jonathan Coveney: Why Pig?
Jonathan Coveney: Why Pig?
 
(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag Session(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag Session
 
Hadoop 3
Hadoop 3Hadoop 3
Hadoop 3
 
Pybind11 - SciPy 2021
Pybind11 - SciPy 2021Pybind11 - SciPy 2021
Pybind11 - SciPy 2021
 
Introduction to Garbage Collection
Introduction to Garbage CollectionIntroduction to Garbage Collection
Introduction to Garbage Collection
 
Apache Storm
Apache StormApache Storm
Apache Storm
 
Luigi Presentation at OSCON 2013
Luigi Presentation at OSCON 2013Luigi Presentation at OSCON 2013
Luigi Presentation at OSCON 2013
 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with Airflow
 
InfluxDB & Kubernetes
InfluxDB & KubernetesInfluxDB & Kubernetes
InfluxDB & Kubernetes
 
Airflow at WePay
Airflow at WePayAirflow at WePay
Airflow at WePay
 
Playing the toStrings
Playing the toStringsPlaying the toStrings
Playing the toStrings
 

Similar to Custom object detection_gcp

GDG-MLOps using Protobuf in Unity
GDG-MLOps using Protobuf in UnityGDG-MLOps using Protobuf in Unity
GDG-MLOps using Protobuf in UnityIvan Chiou
 
I want my model to be deployed ! (another story of MLOps)
I want my model to be deployed ! (another story of MLOps)I want my model to be deployed ! (another story of MLOps)
I want my model to be deployed ! (another story of MLOps)AZUG FR
 
Accessing Google Cloud APIs
Accessing Google Cloud APIsAccessing Google Cloud APIs
Accessing Google Cloud APIswesley chun
 
Azure machine learning service
Azure machine learning serviceAzure machine learning service
Azure machine learning serviceRuth Yakubu
 
Colab workshop (for Computer vision Students)
Colab workshop (for Computer vision Students)Colab workshop (for Computer vision Students)
Colab workshop (for Computer vision Students)Asim Hameed Khan
 
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDays
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDaysBuild and deploy PyTorch models with Azure Machine Learning - Henk - CCDays
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDaysCodeOps Technologies LLP
 
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...Shift Conference
 
Jaffle: managing processes and log messages of multiple applications in devel...
Jaffle: managing processes and log messages of multiple applicationsin devel...Jaffle: managing processes and log messages of multiple applicationsin devel...
Jaffle: managing processes and log messages of multiple applications in devel...Masaki Yatsu
 
MLOps pipelines using MLFlow - From training to production
MLOps pipelines using MLFlow - From training to productionMLOps pipelines using MLFlow - From training to production
MLOps pipelines using MLFlow - From training to productionFabian Hadiji
 
Containerised ASP.NET Core apps with Kubernetes
Containerised ASP.NET Core apps with KubernetesContainerised ASP.NET Core apps with Kubernetes
Containerised ASP.NET Core apps with KubernetesCodemotion Tel Aviv
 
How to Puppetize Google Cloud Platform - PuppetConf 2014
How to Puppetize Google Cloud Platform - PuppetConf 2014How to Puppetize Google Cloud Platform - PuppetConf 2014
How to Puppetize Google Cloud Platform - PuppetConf 2014Puppet
 
Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"IT Event
 
22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...
22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...
22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...Athens Big Data
 
Customizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UICustomizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UITech OneStop
 
How to Use Your Own Private Registry
How to Use Your Own Private RegistryHow to Use Your Own Private Registry
How to Use Your Own Private RegistryDocker, Inc.
 
What's new in TYPO3 6.2 LTS - #certiFUNcation Alumni Event 05.06.2015
What's new in TYPO3 6.2 LTS - #certiFUNcation Alumni Event 05.06.2015What's new in TYPO3 6.2 LTS - #certiFUNcation Alumni Event 05.06.2015
What's new in TYPO3 6.2 LTS - #certiFUNcation Alumni Event 05.06.2015die.agilen GmbH
 

Similar to Custom object detection_gcp (20)

GDG-MLOps using Protobuf in Unity
GDG-MLOps using Protobuf in UnityGDG-MLOps using Protobuf in Unity
GDG-MLOps using Protobuf in Unity
 
I want my model to be deployed ! (another story of MLOps)
I want my model to be deployed ! (another story of MLOps)I want my model to be deployed ! (another story of MLOps)
I want my model to be deployed ! (another story of MLOps)
 
Stetl-engine-nlextract-smartem
Stetl-engine-nlextract-smartemStetl-engine-nlextract-smartem
Stetl-engine-nlextract-smartem
 
Accessing Google Cloud APIs
Accessing Google Cloud APIsAccessing Google Cloud APIs
Accessing Google Cloud APIs
 
Python for Delphi Developers - Part 2
Python for Delphi Developers - Part 2Python for Delphi Developers - Part 2
Python for Delphi Developers - Part 2
 
Azure machine learning service
Azure machine learning serviceAzure machine learning service
Azure machine learning service
 
Colab workshop (for Computer vision Students)
Colab workshop (for Computer vision Students)Colab workshop (for Computer vision Students)
Colab workshop (for Computer vision Students)
 
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDays
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDaysBuild and deploy PyTorch models with Azure Machine Learning - Henk - CCDays
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDays
 
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
 
Jaffle: managing processes and log messages of multiple applications in devel...
Jaffle: managing processes and log messages of multiple applicationsin devel...Jaffle: managing processes and log messages of multiple applicationsin devel...
Jaffle: managing processes and log messages of multiple applications in devel...
 
Docker meetup
Docker meetupDocker meetup
Docker meetup
 
MLOps pipelines using MLFlow - From training to production
MLOps pipelines using MLFlow - From training to productionMLOps pipelines using MLFlow - From training to production
MLOps pipelines using MLFlow - From training to production
 
Supercharge your app with Cloud Functions for Firebase
Supercharge your app with Cloud Functions for FirebaseSupercharge your app with Cloud Functions for Firebase
Supercharge your app with Cloud Functions for Firebase
 
Containerised ASP.NET Core apps with Kubernetes
Containerised ASP.NET Core apps with KubernetesContainerised ASP.NET Core apps with Kubernetes
Containerised ASP.NET Core apps with Kubernetes
 
How to Puppetize Google Cloud Platform - PuppetConf 2014
How to Puppetize Google Cloud Platform - PuppetConf 2014How to Puppetize Google Cloud Platform - PuppetConf 2014
How to Puppetize Google Cloud Platform - PuppetConf 2014
 
Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"Mete Atamel "Resilient microservices with kubernetes"
Mete Atamel "Resilient microservices with kubernetes"
 
22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...
22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...
22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...
 
Customizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UICustomizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UI
 
How to Use Your Own Private Registry
How to Use Your Own Private RegistryHow to Use Your Own Private Registry
How to Use Your Own Private Registry
 
What's new in TYPO3 6.2 LTS - #certiFUNcation Alumni Event 05.06.2015
What's new in TYPO3 6.2 LTS - #certiFUNcation Alumni Event 05.06.2015What's new in TYPO3 6.2 LTS - #certiFUNcation Alumni Event 05.06.2015
What's new in TYPO3 6.2 LTS - #certiFUNcation Alumni Event 05.06.2015
 

Recently uploaded

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...caitlingebhard1
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingWSO2
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaWSO2
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringWSO2
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfdanishmna97
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 

Recently uploaded (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Custom object detection_gcp

  • 2.
  • 3. Prerequisite • Install Git • Install Tensorflow • Requires Python 3.4, 3.5, or 3.6 • pip install tensorflow # CPU Version • https://www.tensorflow.org/install • Download Tensorflow models git • git clone https://github.com/tensorflow/models • Some other python libraries • Pillow, lxml, contextlib2 (use pip install) • Install Google cloud SDK • https://cloud.google.com/sdk/docs/quickstart-windows
  • 4. Setup Google Cloud Platform • Create Google Cloud Platform (GCP) Account • Create a project • Enable Billing • On Command prompt (Terminal) • gcloud init • gcloud config auth list • gcloud config list • gcloud config set project
  • 5. Protobuf • The TensorFlow Object Detection API uses .proto files which need to be compiled into .py files. Google provides a program called Protobuf that will batch compile these. • cd models/research • For windows • Download version 3.4.0 for Windows from https://github.com/protocolbuffers/protobuf/releases/tag/v3.4.0 • “E:Object_Detectiondemoprotoc-3.4.0-win32binprotoc.exe" object_detectionprotos*.proto --python_out=. • For Linux • sudo apt-get install protobuf-compiler • protoc object_detection/protos/*.proto --python_out=. • You will see multiple python files now in “object_detectionprotos” folder
  • 6. Environment Setup • Linux • export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim • Windows • Add to Environment Variable • modelsresearch • modelsresearchslim • Test Installation • python object_detection/builders/model_builder_test.py • If no errors installation is perfect
  • 7. Create Dataset • Create two folders: • images • Image Name Format: categoryName_imageID.jpg (only one "_") • annotations • trainval.txt • categoryName_imageID category_ID (80% images for train/val) • test.txt • categoryName_imageID category_ID (20% images for test) • list.txt • categoryName_imageID category_ID (all images) • xmls • categoryName_imageID.xml • Label_map.pbtxt • Note: • Make sure no image is corrupt, bounding boxes are well defined. • Bounding box co-ordinates do not fall outside of image height and width. • Image Height and width are correct. • If one image has many object of same kind, only one copy of image is needed with respective object category name and all bounding box locations in xml. • If image has many object of different category, multiple copies of same image will be stored with one object category in image name in one copy
  • 9. Create TFRecord • The Tensorflow Object Detection API uses the TFRecord format for training and validation datasets • python object_detection/dataset_tools/create_pet_tf_record.py --label_map_path=E:Object_Detectiondemolabel_map.pbtxt --data_dir=E:Object_Detectiondemo --output_dir=E:Object_Detectiondemo • You will see two new files at output_dir location • pet_train.record • pet_val.record
  • 10. Move data to GCS (Google Cloud Storage) • Create a new bucket • gsutil mb gs://train_coke • Set bucket name for future use • set YOUR_GCS_BUCKET=gs://train_coke • Move file to new GCS Bucket • gsutil cp pet_train.record %YOUR_GCS_BUCKET%/data/pet_train.record • gsutil cp pet_val.record %YOUR_GCS_BUCKET%/data/pet_val.record • gsutil cp label_map.pbtxt %YOUR_GCS_BUCKET%/data/pet_label_map.pbtxt
  • 11. Transfer Learning • Upload trained model to GCS • wget https://storage.googleapis.com/download.tensorflow.org/models/object_detection/fast er_rcnn_resnet101_coco_11_06_2017.tar.gz • tar -xvf faster_rcnn_resnet101_coco_11_06_2017.tar.gz • gsutil cp faster_rcnn_resnet101_coco_11_06_2017/model.ckpt.* %YOUR_GCS_BUCKET%/data/ • Edit Config File • sed -i "s|PATH_TO_BE_CONFIGURED|"${YOUR_GCS_BUCKET}" data|g" object_detection/samples/configs/faster_rcnn_resnet101_pets.config #Linux • gsutil cp object_detection/samples/configs/faster_rcnn_resnet101_pets.config %YOUR_GCS_BUCKET%/data/faster_rcnn_resnet101_pets.config • Tensorflow detection model zoo https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/det ection_model_zoo.md
  • 12. Train Model • Package the TensorFlow Object Detection API and TF Slim • python setup.py sdist • cd slim • python setup.py sdist • Enable Cloud Machine Learning Engine API • bash object_detection/dataset_tools/create_pycocotools_package.sh /tmp/pycocotools (#Linux) • gcloud ml-engine jobs submit training object_detection_coke --runtime-version 1.9 --job-dir=%YOUR_GCS_BUCKET%/model_dir --packages dist/object_detection-0.1.tar.gz,slim/dist/slim-0.1.tar.gz,pycocotools/pycocotools-2.0.tar.gz --module-name object_detection.model_main --region us-east1 --config object_detection/samples/cloud/cloud.yml -- --model_dir=%YOUR_GCS_BUCKET%/model_dir --pipeline_config_path=%YOUR_GCS_BUCKET%/data/faster_rcnn_resnet101_pets.config • Get Logs • gcloud ml-engine jobs stream-logs object_detection_pets
  • 13. Tensorboard • pip install tensorboard • From cloudshell • tensorboard --logdir=${YOUR_GCS_BUCKET}/model_dir --port=5000
  • 14. Export Trained Model • Get model checkpoint number • Set CHECKPOINT_NUMBER=2975 • set YOUR_LOCAL_CHK_DIR=exported_model • Copy model checkpoint files to local from GCS • gsutil cp %YOUR_GCS_BUCKET%/model_dir/model.ckpt- %CHECKPOINT_NUMBER%.* % YOUR_LOCAL_CHK_DIR% • Export Inference Graph • python object_detection/export_inference_graph.py --input_type image_tensor --pipeline_config_path object_detection/samples/configs/faster_rcnn_resnet101_pets.config --trained_checkpoint_prefix %YOUR_LOCAL_CHK_DIR%/model.ckpt- %CHECKPOINT_NUMBER% --output_directory exported_graphs
  • 16. References • https://cloud.google.com/blog/products/gcp/training-an-object- detector-using-cloud-machine-learning-engine • https://towardsdatascience.com/google-object-detection-api-to- detect-brand-logos-fd9e113725d8 • https://towardsdatascience.com/google-object-detection-api-to- detect-brand-logos-part-2-384055e4e109 • Git Repo • https://github.com/sahuvaibhav/Object_Detection