{"id":20915253,"url":"https://github.com/brooksian/b2detect","last_synced_at":"2025-05-13T10:32:47.533Z","repository":{"id":182374180,"uuid":"201272836","full_name":"BrooksIan/B2Detect","owner":"BrooksIan","description":"Detect photographs with B2 Stealth Bombers from social media sites using Tensorflow and Apache NiFi","archived":false,"fork":false,"pushed_at":"2023-01-31T16:45:04.000Z","size":51650,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-10-20T18:33:11.997Z","etag":null,"topics":["apache-nifi","nifi-templates","tensorflow","tensorflow-object-detection","tensorflow-serving"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrooksIan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-08-08T14:13:28.000Z","updated_at":"2023-02-10T16:46:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"dfce69dc-44a1-4d69-9741-6963ec518370","html_url":"https://github.com/BrooksIan/B2Detect","commit_stats":null,"previous_names":["brooksian/b2detect"],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrooksIan%2FB2Detect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrooksIan%2FB2Detect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrooksIan%2FB2Detect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrooksIan%2FB2Detect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrooksIan","download_url":"https://codeload.github.com/BrooksIan/B2Detect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225206312,"owners_count":17438085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apache-nifi","nifi-templates","tensorflow","tensorflow-object-detection","tensorflow-serving"],"created_at":"2024-11-18T16:13:47.615Z","updated_at":"2024-11-18T16:13:48.122Z","avatar_url":"https://github.com/BrooksIan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# B2Detect\n## Data Science\n### Object Detection on steaming images using Tensorflow and Apache NiFi\n\n## Introduction - B2 Stealth Bomber Social Media Photo Detector \u003ca name=\"introduction\"\u003e\u003c/a\u003e\nThe 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. \n\n![result2](https://github.com/BrooksIan/B2Detect/blob/master/images/project/result2.jpg)\n\n\n**Language**: Python\n\n**Requirements**: \n- Python 2.7\n- Tensorflow 1.13\n\n**Author**: Ian R Brooks\n\n**Follow**: [LinkedIn - Ian Brooks PhD](https://www.linkedin.com/in/ianrbrooksphd/)\n\n# Table of Contents\n1. [Introduction](#introduction)\n2. [Links](#links)\n    1. [Apache NiFi](#linksnifi)\n    2. [Tensorflow](#linksTF)\n \t3. [Additional](#linksAdd)\n\n3. [Setup Environment](#Setup)\n\t1. [Download Python Libraries](#Setup1)\n\t2. [Download NiFi Processor](#Setup2)\n\t3. [Download Project](#Setup3)\n\t4. [Upload NiFi Templates](#Setup4)\n\n4. [NiFi Configuration](#NifiConfig)\n5. [Tensorflow Serving](#TFServe)\n6. [Results - Images Posted To Slack](#Result)\n\n## Links \u003ca name=\"links\"\u003e\u003c/a\u003e\n**NiFi Links**: \u003ca name=\"linksNifi\"\u003e\u003c/a\u003e\n- [Posting Images with Apache NiFi 1.7 and a Custom Processor](https://community.hortonworks.com/articles/223916/posting-images-with-apache-nifi-17-and-a-custom-pr.html \"link1\")\n- [Post Images To Slack Custom Processor](https://github.com/tspannhw/nifi-postimage-processor \"link2\")\n- [Great Read On Posting Images to Slack from Apache NiFi Using Custom Processor](https://www.datainmotion.dev/2019/03/posting-images-to-slack-from-apache.html \"link3\")\n- [Uploading NiFi Template](https://www.youtube.com/watch?v=nha90lYQZ-0)\n\n**TensorFlow Links**: \u003ca name=\"linksTF\"\u003e\u003c/a\u003e\n- [Tensorflow Serving](https://www.tensorflow.org/tfx/guide/serving \"link9\")\n- [Tensorflow Serving Using Docker](https://www.tensorflow.org/tfx/serving/docker \"link10\")\n\n**Additional Links**: \u003ca name=\"linksAdd\"\u003e\u003c/a\u003e\n- [Ian's Tensorflow Object Detection Tutorial](https://github.com/BrooksIan/LogoTL)\n- [Social Searcher](https://www.social-searcher.com/)\n- [Slack](https://slack.com/)\n\n## Setup Environment - Download Everything! \u003ca name=\"Setup\"\u003e\u003c/a\u003e\n\n### Download Python Libraries  \u003ca name=\"Setup1\"\u003e\u003c/a\u003e\n\nRun at terminal prompt\n\n```bash\npip install requests\npip install pillow\npip install numpy\npip install image\npip install Pillow-PIL\n```\n\n### Download NiFi Processor \u003ca name=\"Setup2\"\u003e\u003c/a\u003e\n\nRun at terminal prompt\n\n```bash\n#Download Post Image Processor nar  - Thank You Tim Spann! \nwget https://github.com/tspannhw/nifi-postimage-processor/releases/download/1.0/nifi-postimage-nar-1.0.nar \\\n-O /usr/hdf/current/nifi/lib/nifi-postimage-nar-1.0.nar\n```\n\n### Download Project \u003ca name=\"Setup3\"\u003e\u003c/a\u003e\nDownload the project using the git url for [here.](https://github.com/BrooksIan/B2Detect.git) \n\n\n### Upload NiFi Template \u003ca name=\"Setup4\"\u003e\u003c/a\u003e\n\nNiFi flow template is called [B2DetectFlow_BaseTemplate.xml](https://raw.githubusercontent.com/BrooksIan/B2Detect/master/B2DetectFlow_BaseTemplate.xml)\n\n![tempupload](https://github.com/BrooksIan/B2Detect/blob/master/images/project/tempupload.png)\n\nOnce the template has been loaded, you should see the following NiFi flow\n\n![nififlow](https://github.com/BrooksIan/B2Detect/blob/master/images/project/nififlow.png)\n\n## NiFi Configuration \u003ca name=\"NifiConfig\"\u003e\u003c/a\u003e\n\n\n### Set Social Seacher API Token in InvokeHTTP processor \n\n![social0](https://github.com/BrooksIan/B2Detect/blob/master/images/project/socialset0.png)\n\n![social1](https://github.com/BrooksIan/B2Detect/blob/master/images/project/socialset1.png)\n\nSet Social Searcher token value\n\n```bash\nhttp://api.social-searcher.com/v2/search?q=B2+Stealth+Bomber\u0026type=photo\u0026key=\u003cYOUR TOKEN VALUE HERE\u003e\n```\n\n### SSL Context Configuration in InvokeHTTP processor\n\n![nifissl](https://github.com/BrooksIan/B2Detect/blob/master/images/project/nifissl.png)\n![nifissl0](https://github.com/BrooksIan/B2Detect/blob/master/images/project/nifisslcontext0.png)\n![nifissl1](https://github.com/BrooksIan/B2Detect/blob/master/images/project/nifisslcontext1.png)\n\n### Post Image Processor Configuration\n\n![postimageprocessor](https://github.com/BrooksIan/B2Detect/blob/master/images/project/postimageprocessor.png)\n\n![postimageconfig](https://github.com/BrooksIan/B2Detect/blob/master/images/project/postimageconfig.png)\n\nUpdate Slack API Token in URL value: \n\n```bash\nhttps://slack.com/api/files.upload?token= \u003cYOUR KEY HERE\u003e \u0026channels=b2detect\u0026filename=${absolute.path}${filename}\u0026files:write:user\u0026pretty=1\n```\n\n### Put Slack Processor Configuration\n\n![putslack](https://github.com/BrooksIan/B2Detect/blob/master/images/project/putslack.png)\n\nUpdate Webhook URL value\n\n![slackwebhook](https://github.com/BrooksIan/B2Detect/blob/master/images/project/slackwebhook.png)\n\n## Tensorflow Serving Using Docker \u003ca name=\"TFServe\"\u003e\u003c/a\u003e\n\nRun at terminal prompt.  Note the path need to point to the location of [saved_model directory](https://github.com/BrooksIan/B2Detect/tree/master/saved_model) in this github repo.\n\n```bash\ndocker pull tensorflow/serving\n\n#Adding the Version number on model target path is VERY important! \ndocker run -p 8900:8500 -p 8501:8501  --mount type=bind,source=/saved_model,target=/models/saved_model/1 \\\n-e MODEL_NAME=saved_model -t tensorflow/serving \u0026\n\n```\n\n## Configure Execute Stream Command Processor \u003ca name=\"modelcall\"\u003e\u003c/a\u003e\n\n![steamc0](https://github.com/BrooksIan/B2Detect/blob/master/images/project/streamcommand0.png)\n\n![steamc1](https://github.com/BrooksIan/B2Detect/blob/master/images/project/streamcommand1.png)\n\n1. Download (or copy) [callTFModel.py](https://raw.githubusercontent.com/BrooksIan/B2Detect/master/callTFModel.py) python script to the path set in the Exectute Stream Command processor, which is used to call the Tensorflow model.\n\n2. In callTFModel.py, set the URL of the Tensorflow Serving Docker container\n\n```python\nimport PIL.Image\nfrom PIL import ImageDraw\nimport numpy\nimport requests\nimport time\nimport json\nimport sys\n\nimagePath = str(sys.argv[1])\nthreshold=0.95 \ntimeTheashold = 2.5\n\nimage = PIL.Image.open(imagePath)  \nimage_np = numpy.array(image)\ndraw = ImageDraw.Draw(image)\n\npayload = {\"instances\": [image_np.tolist()]}\nstart = time.time()\nres = requests.post(\"\u003cURL OF DOCKER CONTAINER\u003e:8501/v1/models/saved_model:predict\", json=payload)\nprocessTime = time.time()-start\n\njsonStr= json.dumps(res.json())\njsonDict = json.loads(jsonStr)\n\npredScore = jsonDict['predictions'][0]['detection_scores'][0]\n\nif((predScore \u003e= threshold) and (timeTheashold \u003e= processTime)):\n\tresponse = {\"response\":\"B2Found\",\"confidence\": predScore , \"duration\": processTime }\n\nelse:\n\tresponse = {\"response\":\"B2NotFound\",\"confidence\":predScore,\"duration\":processTime}\n\njsonresponse = json.dumps(response)\nprint(jsonresponse)\n```\n\n## Results - Images Are Posted To Slack Channel\u003ca name=\"Result\"\u003e\u003c/a\u003e\n![FinalResult](https://github.com/BrooksIan/B2Detect/blob/master/images/project/slackUpload.png)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrooksian%2Fb2detect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrooksian%2Fb2detect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrooksian%2Fb2detect/lists"}