{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running on local URL: http://127.0.0.1:7860/\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(,\n",
" 'http://127.0.0.1:7860/',\n",
" None)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-02-09 14:10:22.417549: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA\n",
"To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\n",
"Total workers: 5\n",
"Number of Helmets: 4\n",
"Number of Vests: 0\n",
"dict vals:\n",
"{'W': 5, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 5\n",
"dict vals:\n",
"{'W': 5, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 5\n",
"Workers wearing helmet and vest: 0\n",
"Workers wearing only vest: 0\n",
"Workers wearing only helmet: 5\n",
"dict vals:\n",
"{'W': 5, 'WH': 5, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 5\n",
"Number of Helmets: 4\n",
"Number of Vests: 0\n",
"dict vals:\n",
"{'W': 5, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"WARNING:tensorflow:5 out of the last 5 calls to .predict_function at 0x7fbc729998b0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.\n",
"\n",
"\n",
"\n",
"Total workers: 5\n",
"Workers wearing helmet and vest: 0\n",
"Workers wearing only vest: 0\n",
"Workers wearing only helmet: 5\n",
"dict vals:\n",
"{'W': 5, 'WH': 5, 'WHV': 0, 'WV': 0}\n",
"WARNING:tensorflow:6 out of the last 6 calls to .predict_function at 0x7fbc979e9ee0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.\n",
"\n",
"\n",
"\n",
"Total workers: 3\n",
"dict vals:\n",
"{'W': 3, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 3\n",
"Workers wearing helmet and vest: 3\n",
"Workers wearing only vest: 0\n",
"Workers wearing only helmet: 0\n",
"dict vals:\n",
"{'W': 3, 'WH': 0, 'WHV': 3, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 3\n",
"Number of Helmets: 3\n",
"Number of Vests: 1\n",
"dict vals:\n",
"{'W': 3, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 5\n",
"Number of Helmets: 4\n",
"Number of Vests: 0\n",
"dict vals:\n",
"{'W': 5, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 6\n",
"Workers wearing helmet and vest: 0\n",
"Workers wearing only vest: 0\n",
"Workers wearing only helmet: 4\n",
"Workers not wearing helmet and vest: 2\n",
"\n",
"\n",
"dict vals:\n",
"{'W': 6, 'WH': 4, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 6\n",
"dict vals:\n",
"{'W': 6, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 5\n",
"Number of Helmets: 4\n",
"Number of Vests: 0\n",
"dict vals:\n",
"{'W': 5, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 6\n",
"dict vals:\n",
"{'W': 6, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 6\n",
"Workers wearing helmet and vest: 0\n",
"Workers wearing only vest: 0\n",
"Workers wearing only helmet: 4\n",
"Workers not wearing helmet and vest: 2\n",
"\n",
"\n",
"dict vals:\n",
"{'W': 6, 'WH': 4, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 1\n",
"Number of Helmets: 1\n",
"Number of Vests: 0\n",
"dict vals:\n",
"{'W': 1, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 1\n",
"Workers wearing helmet and vest: 0\n",
"Workers wearing only vest: 0\n",
"Workers wearing only helmet: 1\n",
"dict vals:\n",
"{'W': 1, 'WH': 1, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 1\n",
"dict vals:\n",
"{'W': 1, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 1\n",
"Workers wearing helmet and vest: 0\n",
"Workers wearing only vest: 0\n",
"Workers wearing only helmet: 1\n",
"dict vals:\n",
"{'W': 1, 'WH': 1, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 5\n",
"Number of Helmets: 4\n",
"Number of Vests: 0\n",
"dict vals:\n",
"{'W': 5, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 6\n",
"Workers wearing helmet and vest: 0\n",
"Workers wearing only vest: 0\n",
"Workers wearing only helmet: 4\n",
"Workers not wearing helmet and vest: 2\n",
"\n",
"\n",
"dict vals:\n",
"{'W': 6, 'WH': 4, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 3\n",
"Workers wearing helmet and vest: 3\n",
"Workers wearing only vest: 0\n",
"Workers wearing only helmet: 0\n",
"dict vals:\n",
"{'W': 3, 'WH': 0, 'WHV': 3, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 3\n",
"dict vals:\n",
"{'W': 3, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 3\n",
"Number of Helmets: 3\n",
"Number of Vests: 1\n",
"dict vals:\n",
"{'W': 3, 'WH': 0, 'WHV': 0, 'WV': 0}\n",
"\n",
"\n",
"\n",
"Total workers: 3\n",
"Workers wearing helmet and vest: 3\n",
"Workers wearing only vest: 0\n",
"Workers wearing only helmet: 0\n",
"dict vals:\n",
"{'W': 3, 'WH': 0, 'WHV': 3, 'WV': 0}\n"
]
}
],
"source": [
"import numpy as np\n",
"import run_code\n",
"import cv2\n",
"import gradio as gr\n",
"\n",
"\n",
"def sepia(Input_Image, Approach):\n",
" pil_image = Input_Image\n",
" open_cv_image = np.asarray(pil_image)\n",
" # Convert RGB to BGR\n",
" #open_cv_image = open_cv_image[:, :, ::-1].copy()\n",
" #Approach = 3\n",
" sepia_img = run_code.run(open_cv_image, Approach)\n",
" images = sepia_img['img']\n",
" texts= sepia_img['text']\n",
" #print (labels)\n",
" return images, texts\n",
"\n",
"image = [gr.inputs.Image(type=\"pil\"), gr.inputs.Radio([1, 2, 3])]\n",
"#output = [\"image\", gr.outputs.Label(num_top_classes=4)]\n",
"output = [\"image\", gr.outputs.Textbox(type=\"auto\")]\n",
"#output = gr.outputs.Label(num_top_classes=4)\n",
"\n",
"title=\"Real-time Detection of Personal-Protective-Equipment (PPE)\"\n",
"description=\"This demo is the implementation of Real-time Detection of Personal-Protective-Equipment (PPE) paper https://github.com/ciber-lab/pictor-ppe\" \\\n",
" \" - by Sanjay Kamath \"\n",
"examples = [[\"examples/ex1.jpg\", 1], [\"examples/ex2.jpg\", 2], [\"examples/ex3.jpg\", 3]]\n",
"\n",
"#iface = gr.Interface(sepia , [ gr.inputs.Image(shape=(200, 200)), gr.inputs.Radio([1, 2, 3])], \"image\", title=title,\n",
"# examples = [[\"examples/ex1.jpg\"], [\"examples/ex2.jpg\"], [\"examples/ex3.jpg\"]],\n",
"# description=description)\n",
"\n",
"iface = gr.Interface(fn=sepia, inputs=image, outputs=output, title=title, description=description, examples=examples)\n",
"\n",
"iface.launch()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}