Giter VIP home page Giter VIP logo

b2detect's Introduction

B2Detect

Data Science

Object Detection on steaming images using Tensorflow and Apache NiFi

Introduction - B2 Stealth Bomber Social Media Photo Detector

The goal of this project is to build an end-to-end project to detect images that contain B2 Stealth Bomber from popular social media sites.

result2

Language: Python

Requirements:

  • Python 2.7
  • Tensorflow 1.13

Author: Ian R Brooks

Follow: LinkedIn - Ian Brooks PhD

Table of Contents

  1. Introduction

  2. Links

    1. Apache NiFi
    2. Tensorflow
    3. Additional
  3. Setup Environment

    1. Download Python Libraries
    2. Download NiFi Processor
    3. Download Project
    4. Upload NiFi Templates
  4. NiFi Configuration

  5. Tensorflow Serving

  6. Results - Images Posted To Slack

Links

NiFi Links:

TensorFlow Links:

Additional Links:

Setup Environment - Download Everything!

Download Python Libraries

Run at terminal prompt

pip install requests
pip install pillow
pip install numpy
pip install image
pip install Pillow-PIL

Download NiFi Processor

Run at terminal prompt

#Download Post Image Processor nar  - Thank You Tim Spann! 
wget https://github.com/tspannhw/nifi-postimage-processor/releases/download/1.0/nifi-postimage-nar-1.0.nar \
-O /usr/hdf/current/nifi/lib/nifi-postimage-nar-1.0.nar

Download Project

Download the project using the git url for here.

Upload NiFi Template

NiFi flow template is called B2DetectFlow_BaseTemplate.xml

tempupload

Once the template has been loaded, you should see the following NiFi flow

nififlow

NiFi Configuration

Set Social Seacher API Token in InvokeHTTP processor

social0

social1

Set Social Searcher token value

http://api.social-searcher.com/v2/search?q=B2+Stealth+Bomber&type=photo&key=<YOUR TOKEN VALUE HERE>

SSL Context Configuration in InvokeHTTP processor

nifissl nifissl0 nifissl1

Post Image Processor Configuration

postimageprocessor

postimageconfig

Update Slack API Token in URL value:

https://slack.com/api/files.upload?token= <YOUR KEY HERE> &channels=b2detect&filename=${absolute.path}${filename}&files:write:user&pretty=1

Put Slack Processor Configuration

putslack

Update Webhook URL value

slackwebhook

Tensorflow Serving Using Docker

Run at terminal prompt. Note the path need to point to the location of saved_model directory in this github repo.

docker pull tensorflow/serving

#Adding the Version number on model target path is VERY important! 
docker run -p 8900:8500 -p 8501:8501  --mount type=bind,source=/saved_model,target=/models/saved_model/1 \
-e MODEL_NAME=saved_model -t tensorflow/serving &

Configure Execute Stream Command Processor

steamc0

steamc1

  1. Download (or copy) callTFModel.py python script to the path set in the Exectute Stream Command processor, which is used to call the Tensorflow model.

  2. In callTFModel.py, set the URL of the Tensorflow Docker container

import PIL.Image
from PIL import ImageDraw
import numpy
import requests
from pprint import pprint
import time
import json
import sys


imagePath = str(sys.argv[1])
#output_name = str(sys.argv[2])
threshold=0.95 #= str(sys.argv[3])
timeTheashold = 2.5

image = PIL.Image.open(imagePath)  
image_np = numpy.array(image)
draw = ImageDraw.Draw(image)


payload = {"instances": [image_np.tolist()]}
start = time.time()
res = requests.post("<URL OF DOCKER CONTAINER>:8501/v1/models/saved_model:predict", json=payload)
processTime = time.time()-start


jsonStr= json.dumps(res.json())
jsonDict = json.loads(jsonStr)

predScore = jsonDict['predictions'][0]['detection_scores'][0]

if((predScore >= threshold) and (timeTheashold >= processTime)):
	response = {"response":"B2Found","confidence": predScore , "duration": processTime }

else:
	response = {"response":"B2NotFound","confidence":predScore,"duration":processTime}

jsonresponse = json.dumps(response)
print(jsonresponse)

Result - B2 Images Posted To Slack Channel

FinalResult

b2detect's People

Contributors

brooksian avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.