├── ACCIDetect.ipynb ├── ACCIDetect.py ├── ACCIdetect.pptx ├── ML ├── CM.png ├── Learning-curve.png ├── Precision-Recall.png ├── ROC.png ├── preprocessing.py ├── realtimeV2.py └── trainV2.py ├── Readme.md ├── a1.jpeg ├── a2.jpeg ├── final.mp4 ├── hack ├── AndroidManifest.xml ├── MainActivity.java ├── assets │ ├── frozen_inference_graph.pb │ └── label_strings.txt ├── java │ └── com │ │ └── example │ │ └── hackabit │ │ ├── Classifier.java │ │ ├── MainActivity.java │ │ └── TensorFlowImageClassifier.java └── res │ ├── drawable │ ├── a.jpg │ └── ic_launcher_background.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml └── help.txt /ACCIDetect.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stderr", 10 | "output_type": "stream", 11 | "text": [ 12 | "Using TensorFlow backend.\n" 13 | ] 14 | }, 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "[INFO] loading model and label binarizer...\n", 20 | "WARNING:tensorflow:From C:\\Users\\Abhinav\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:517: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.\n", 21 | "\n", 22 | "WARNING:tensorflow:From C:\\Users\\Abhinav\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:4185: The name tf.truncated_normal is deprecated. Please use tf.random.truncated_normal instead.\n", 23 | "\n", 24 | "WARNING:tensorflow:From C:\\Users\\Abhinav\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:245: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.\n", 25 | "\n", 26 | "WARNING:tensorflow:From C:\\Users\\Abhinav\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:174: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.\n", 27 | "\n", 28 | "WARNING:tensorflow:From C:\\Users\\Abhinav\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:181: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.\n", 29 | "\n", 30 | "WARNING:tensorflow:From C:\\Users\\Abhinav\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:1834: The name tf.nn.fused_batch_norm is deprecated. Please use tf.compat.v1.nn.fused_batch_norm instead.\n", 31 | "\n", 32 | "WARNING:tensorflow:From C:\\Users\\Abhinav\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:3976: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.\n", 33 | "\n", 34 | "WARNING:tensorflow:From C:\\Users\\Abhinav\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:3980: The name tf.nn.avg_pool is deprecated. Please use tf.nn.avg_pool2d instead.\n", 35 | "\n", 36 | "WARNING:tensorflow:From C:\\Users\\Abhinav\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:3445: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.\n", 37 | "Instructions for updating:\n", 38 | "Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.\n", 39 | "WARNING:tensorflow:From C:\\Users\\Abhinav\\Anaconda3\\lib\\site-packages\\keras\\optimizers.py:790: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.\n", 40 | "\n", 41 | "WARNING:tensorflow:From C:\\Users\\Abhinav\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\ops\\math_grad.py:1250: add_dispatch_support..wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.\n", 42 | "Instructions for updating:\n", 43 | "Use tf.where in 2.0, which has the same broadcast rule as np.where\n", 44 | "[INFO] starting video stream...\n", 45 | "Results = [4.3293534e-04 3.8548801e-03 2.4781943e-05 9.9568731e-01]\n", 46 | "Maximun Probability = 0.9956873\n", 47 | "Difference of prob 0.9913746118545532\n", 48 | "Results = [4.1209286e-04 3.3790225e-03 2.1892400e-05 9.9618697e-01]\n", 49 | "Maximun Probability = 0.996187\n", 50 | "Difference of prob 0.9923739433288574\n", 51 | "Results = [3.8231528e-04 3.0400951e-03 1.9718520e-05 9.9655789e-01]\n", 52 | "Maximun Probability = 0.9965579\n", 53 | "Difference of prob 0.9931157827377319\n", 54 | "Results = [4.0823285e-04 3.4692693e-03 1.9826053e-05 9.9610269e-01]\n", 55 | "Maximun Probability = 0.9961027\n", 56 | "Difference of prob 0.9922053813934326\n", 57 | "Results = [4.4166693e-04 3.6382810e-03 2.0791607e-05 9.9589932e-01]\n", 58 | "Maximun Probability = 0.9958993\n", 59 | "Difference of prob 0.9917986392974854\n", 60 | "Results = [4.6395161e-04 3.8080963e-03 2.1883048e-05 9.9570608e-01]\n", 61 | "Maximun Probability = 0.9957061\n", 62 | "Difference of prob 0.9914121627807617\n", 63 | "Results = [4.8713089e-04 3.8926492e-03 2.2053255e-05 9.9559820e-01]\n", 64 | "Maximun Probability = 0.9955982\n", 65 | "Difference of prob 0.9911963939666748\n", 66 | "Results = [5.0497561e-04 4.2713946e-03 2.2234248e-05 9.9520141e-01]\n", 67 | "Maximun Probability = 0.9952014\n", 68 | "Difference of prob 0.9904028177261353\n", 69 | "Results = [5.3840579e-04 4.8335474e-03 2.2795035e-05 9.9460530e-01]\n", 70 | "Maximun Probability = 0.9946053\n", 71 | "Difference of prob 0.9892106056213379\n", 72 | "Results = [5.6717161e-04 5.0472245e-03 2.2638722e-05 9.9436301e-01]\n", 73 | "Maximun Probability = 0.994363\n", 74 | "Difference of prob 0.988726019859314\n", 75 | "Results = [5.6933356e-04 5.3468863e-03 2.2271177e-05 9.9406153e-01]\n", 76 | "Maximun Probability = 0.9940615\n", 77 | "Difference of prob 0.9881230592727661\n", 78 | "Results = [5.8164430e-04 6.0448260e-03 2.2676977e-05 9.9335092e-01]\n", 79 | "Maximun Probability = 0.9933509\n", 80 | "Difference of prob 0.9867018461227417\n", 81 | "Results = [6.0467137e-04 6.9230017e-03 2.3635774e-05 9.9244875e-01]\n", 82 | "Maximun Probability = 0.99244875\n", 83 | "Difference of prob 0.9848974943161011\n", 84 | "Results = [6.2682637e-04 7.9353545e-03 2.4414652e-05 9.9141347e-01]\n", 85 | "Maximun Probability = 0.9914135\n", 86 | "Difference of prob 0.9828269481658936\n", 87 | "Results = [6.3753448e-04 8.5867830e-03 2.4880212e-05 9.9075091e-01]\n", 88 | "Maximun Probability = 0.9907509\n", 89 | "Difference of prob 0.9815018177032471\n", 90 | "Results = [6.5410085e-04 9.1052987e-03 2.5656278e-05 9.9021500e-01]\n", 91 | "Maximun Probability = 0.990215\n", 92 | "Difference of prob 0.980430006980896\n", 93 | "Results = [6.9796632e-04 1.0092898e-02 2.7582983e-05 9.8918164e-01]\n", 94 | "Maximun Probability = 0.98918164\n", 95 | "Difference of prob 0.9783632755279541\n", 96 | "Results = [7.2438776e-04 1.0947216e-02 2.9122813e-05 9.8829937e-01]\n", 97 | "Maximun Probability = 0.98829937\n", 98 | "Difference of prob 0.9765987396240234\n", 99 | "Results = [7.5147673e-04 1.1573686e-02 2.9684281e-05 9.8764521e-01]\n", 100 | "Maximun Probability = 0.9876452\n", 101 | "Difference of prob 0.9752904176712036\n", 102 | "Results = [7.7163614e-04 1.1902476e-02 3.0644944e-05 9.8729527e-01]\n", 103 | "Maximun Probability = 0.98729527\n", 104 | "Difference of prob 0.974590539932251\n", 105 | "Results = [7.8111282e-04 1.1962936e-02 3.1487194e-05 9.8722446e-01]\n", 106 | "Maximun Probability = 0.98722446\n", 107 | "Difference of prob 0.9744489192962646\n", 108 | "Results = [7.9536973e-04 1.2239532e-02 3.2128635e-05 9.8693299e-01]\n", 109 | "Maximun Probability = 0.986933\n", 110 | "Difference of prob 0.9738659858703613\n", 111 | "Results = [8.0912141e-04 1.2306459e-02 3.3128850e-05 9.8685133e-01]\n", 112 | "Maximun Probability = 0.98685133\n", 113 | "Difference of prob 0.9737026691436768\n", 114 | "Results = [8.0843450e-04 1.2258045e-02 3.3805798e-05 9.8689979e-01]\n", 115 | "Maximun Probability = 0.9868998\n", 116 | "Difference of prob 0.9737995862960815\n", 117 | "Results = [8.0780208e-04 1.2157122e-02 3.4596644e-05 9.8700052e-01]\n", 118 | "Maximun Probability = 0.9870005\n", 119 | "Difference of prob 0.9740010499954224\n", 120 | "Results = [8.06554453e-04 1.20251905e-02 3.50122245e-05 9.87133265e-01]\n", 121 | "Maximun Probability = 0.98713326\n", 122 | "Difference of prob 0.974266529083252\n", 123 | "Results = [8.0523879e-04 1.1929464e-02 3.5087825e-05 9.8723024e-01]\n", 124 | "Maximun Probability = 0.98723024\n", 125 | "Difference of prob 0.9744604825973511\n", 126 | "Results = [8.1264385e-04 1.1937265e-02 3.5024968e-05 9.8721510e-01]\n", 127 | "Maximun Probability = 0.9872151\n", 128 | "Difference of prob 0.9744302034378052\n", 129 | "Results = [8.1590679e-04 1.1802849e-02 3.4994286e-05 9.8734629e-01]\n", 130 | "Maximun Probability = 0.9873463\n", 131 | "Difference of prob 0.9746925830841064\n", 132 | "Results = [8.1981259e-04 1.1644389e-02 3.4952551e-05 9.8750091e-01]\n", 133 | "Maximun Probability = 0.9875009\n", 134 | "Difference of prob 0.9750018119812012\n", 135 | "Results = [8.1984664e-04 1.1417150e-02 3.5289904e-05 9.8772776e-01]\n", 136 | "Maximun Probability = 0.98772776\n", 137 | "Difference of prob 0.9754555225372314\n", 138 | "Results = [8.2474144e-04 1.1230412e-02 3.5831254e-05 9.8790908e-01]\n", 139 | "Maximun Probability = 0.9879091\n", 140 | "Difference of prob 0.9758181571960449\n", 141 | "Results = [8.3967979e-04 1.1137408e-02 3.6763897e-05 9.8798627e-01]\n", 142 | "Maximun Probability = 0.98798627\n", 143 | "Difference of prob 0.9759725332260132\n", 144 | "Results = [8.5065997e-04 1.0984491e-02 3.7431648e-05 9.8812753e-01]\n", 145 | "Maximun Probability = 0.9881275\n", 146 | "Difference of prob 0.9762550592422485\n", 147 | "Results = [8.5750682e-04 1.0835957e-02 3.7982281e-05 9.8826873e-01]\n", 148 | "Maximun Probability = 0.98826873\n", 149 | "Difference of prob 0.9765374660491943\n", 150 | "Results = [8.6028635e-04 1.0722247e-02 3.8422477e-05 9.8837918e-01]\n", 151 | "Maximun Probability = 0.9883792\n", 152 | "Difference of prob 0.9767583608627319\n", 153 | "Results = [8.6610112e-04 1.0631397e-02 3.8837086e-05 9.8846376e-01]\n", 154 | "Maximun Probability = 0.98846376\n", 155 | "Difference of prob 0.9769275188446045\n", 156 | "Results = [8.7088608e-04 1.0496104e-02 3.8914772e-05 9.8859417e-01]\n", 157 | "Maximun Probability = 0.9885942\n", 158 | "Difference of prob 0.9771883487701416\n", 159 | "Results = [8.9321018e-04 1.1413226e-02 3.9771290e-05 9.8765385e-01]\n", 160 | "Maximun Probability = 0.98765385\n", 161 | "Difference of prob 0.9753077030181885\n", 162 | "Results = [9.2656800e-04 1.2260113e-02 4.0905710e-05 9.8677254e-01]\n", 163 | "Maximun Probability = 0.98677254\n", 164 | "Difference of prob 0.9735450744628906\n" 165 | ] 166 | }, 167 | { 168 | "name": "stdout", 169 | "output_type": "stream", 170 | "text": [ 171 | "Results = [9.53388924e-04 1.30923875e-02 4.17738775e-05 9.85912621e-01]\n", 172 | "Maximun Probability = 0.9859126\n", 173 | "Difference of prob 0.9718252420425415\n", 174 | "Results = [9.9337241e-04 1.4519729e-02 4.3798442e-05 9.8444319e-01]\n", 175 | "Maximun Probability = 0.9844432\n", 176 | "Difference of prob 0.9688863754272461\n", 177 | "Results = [1.0218588e-03 1.6388362e-02 4.5522629e-05 9.8254436e-01]\n", 178 | "Maximun Probability = 0.98254436\n", 179 | "Difference of prob 0.9650887250900269\n", 180 | "Results = [1.0544484e-03 1.7862501e-02 4.7800797e-05 9.8103541e-01]\n", 181 | "Maximun Probability = 0.9810354\n", 182 | "Difference of prob 0.9620708227157593\n", 183 | "Results = [1.0999549e-03 1.9755907e-02 5.0410246e-05 9.7909385e-01]\n", 184 | "Maximun Probability = 0.97909385\n", 185 | "Difference of prob 0.9581876993179321\n", 186 | "Results = [1.1387572e-03 2.1498706e-02 5.2442931e-05 9.7731018e-01]\n", 187 | "Maximun Probability = 0.9773102\n", 188 | "Difference of prob 0.954620361328125\n", 189 | "Results = [1.1532718e-03 2.2602307e-02 5.2996940e-05 9.7619152e-01]\n", 190 | "Maximun Probability = 0.9761915\n", 191 | "Difference of prob 0.9523830413818359\n", 192 | "Results = [1.1789267e-03 2.4327919e-02 5.4100816e-05 9.7443914e-01]\n", 193 | "Maximun Probability = 0.97443914\n", 194 | "Difference of prob 0.948878288269043\n", 195 | "Results = [1.2072386e-03 2.5501823e-02 5.5272820e-05 9.7323579e-01]\n", 196 | "Maximun Probability = 0.9732358\n", 197 | "Difference of prob 0.9464715719223022\n", 198 | "Results = [1.2547242e-03 2.7130371e-02 5.7108089e-05 9.7155792e-01]\n", 199 | "Maximun Probability = 0.9715579\n", 200 | "Difference of prob 0.9431158304214478\n", 201 | "Results = [1.2995467e-03 2.8558640e-02 5.8724621e-05 9.7008318e-01]\n", 202 | "Maximun Probability = 0.9700832\n", 203 | "Difference of prob 0.9401663541793823\n", 204 | "Results = [1.3313026e-03 2.9668251e-02 5.9703125e-05 9.6894085e-01]\n", 205 | "Maximun Probability = 0.96894085\n", 206 | "Difference of prob 0.9378817081451416\n", 207 | "Results = [1.3726103e-03 3.0927086e-02 6.0994891e-05 9.6763945e-01]\n", 208 | "Maximun Probability = 0.96763945\n", 209 | "Difference of prob 0.9352788925170898\n", 210 | "Results = [1.4208475e-03 3.2168455e-02 6.2281622e-05 9.6634853e-01]\n", 211 | "Maximun Probability = 0.9663485\n", 212 | "Difference of prob 0.932697057723999\n", 213 | "Results = [1.4489305e-03 3.3032201e-02 6.3366497e-05 9.6545553e-01]\n", 214 | "Maximun Probability = 0.96545553\n", 215 | "Difference of prob 0.9309110641479492\n", 216 | "Results = [1.4897611e-03 3.3808406e-02 6.4856737e-05 9.6463698e-01]\n", 217 | "Maximun Probability = 0.964637\n", 218 | "Difference of prob 0.9292739629745483\n", 219 | "Results = [1.5410820e-03 3.4587845e-02 6.6046494e-05 9.6380508e-01]\n", 220 | "Maximun Probability = 0.9638051\n", 221 | "Difference of prob 0.9276101589202881\n", 222 | "Results = [1.5768993e-03 3.5401925e-02 6.6584100e-05 9.6295464e-01]\n", 223 | "Maximun Probability = 0.96295464\n", 224 | "Difference of prob 0.9259092807769775\n", 225 | "Results = [1.6030228e-03 3.6241960e-02 6.7325054e-05 9.6208775e-01]\n", 226 | "Maximun Probability = 0.96208775\n", 227 | "Difference of prob 0.924175500869751\n", 228 | "Results = [1.6275145e-03 3.7040103e-02 6.7843874e-05 9.6126455e-01]\n", 229 | "Maximun Probability = 0.96126455\n", 230 | "Difference of prob 0.9225291013717651\n", 231 | "Results = [1.6777738e-03 3.8536437e-02 6.9701826e-05 9.5971608e-01]\n", 232 | "Maximun Probability = 0.9597161\n", 233 | "Difference of prob 0.9194321632385254\n", 234 | "Results = [1.7194557e-03 3.9753404e-02 7.1788680e-05 9.5845538e-01]\n", 235 | "Maximun Probability = 0.9584554\n", 236 | "Difference of prob 0.9169107675552368\n", 237 | "Results = [1.751507e-03 4.087569e-02 7.401698e-05 9.572988e-01]\n", 238 | "Maximun Probability = 0.9572988\n", 239 | "Difference of prob 0.9145976305007935\n", 240 | "Results = [1.7763260e-03 4.1751184e-02 7.5371820e-05 9.5639718e-01]\n", 241 | "Maximun Probability = 0.9563972\n", 242 | "Difference of prob 0.9127943515777588\n", 243 | "Results = [1.7986957e-03 4.3317452e-02 7.6838405e-05 9.5480704e-01]\n", 244 | "Maximun Probability = 0.95480704\n", 245 | "Difference of prob 0.909614086151123\n", 246 | "Results = [1.8181447e-03 4.4870835e-02 7.7822573e-05 9.5323324e-01]\n", 247 | "Maximun Probability = 0.95323324\n", 248 | "Difference of prob 0.9064664840698242\n", 249 | "Results = [1.8402659e-03 4.6290211e-02 7.8921439e-05 9.5179063e-01]\n", 250 | "Maximun Probability = 0.95179063\n", 251 | "Difference of prob 0.9035812616348267\n", 252 | "Results = [1.8578892e-03 4.7049392e-02 7.9773701e-05 9.5101303e-01]\n", 253 | "Maximun Probability = 0.951013\n", 254 | "Difference of prob 0.9020260572433472\n", 255 | "Results = [1.8722534e-03 4.7498237e-02 8.0359496e-05 9.5054924e-01]\n", 256 | "Maximun Probability = 0.95054924\n", 257 | "Difference of prob 0.9010984897613525\n", 258 | "Results = [1.8825146e-03 4.7789600e-02 8.0877820e-05 9.5024711e-01]\n", 259 | "Maximun Probability = 0.9502471\n", 260 | "Difference of prob 0.9004942178726196\n", 261 | "Results = [1.8924760e-03 4.8089933e-02 8.1385537e-05 9.4993621e-01]\n", 262 | "Maximun Probability = 0.9499362\n", 263 | "Difference of prob 0.8998724222183228\n", 264 | "Results = [1.9001751e-03 4.8067823e-02 8.1808364e-05 9.4995022e-01]\n", 265 | "Maximun Probability = 0.9499502\n", 266 | "Difference of prob 0.8999004364013672\n", 267 | "Results = [1.9157225e-03 4.8369441e-02 8.2922546e-05 9.4963199e-01]\n", 268 | "Maximun Probability = 0.949632\n", 269 | "Difference of prob 0.8992639780044556\n", 270 | "Results = [1.9567921e-03 4.8642028e-02 8.5294043e-05 9.4931597e-01]\n", 271 | "Maximun Probability = 0.94931597\n", 272 | "Difference of prob 0.8986319303512573\n", 273 | "Results = [1.9952254e-03 4.9125575e-02 8.6956097e-05 9.4879234e-01]\n", 274 | "Maximun Probability = 0.94879234\n", 275 | "Difference of prob 0.8975846767425537\n", 276 | "Results = [2.0508678e-03 4.9693339e-02 8.9583802e-05 9.4816631e-01]\n", 277 | "Maximun Probability = 0.9481663\n", 278 | "Difference of prob 0.8963326215744019\n", 279 | "Results = [2.1057427e-03 5.0325505e-02 9.2562441e-05 9.4747627e-01]\n", 280 | "Maximun Probability = 0.94747627\n", 281 | "Difference of prob 0.8949525356292725\n", 282 | "Results = [2.1376649e-03 5.0856158e-02 9.3902614e-05 9.4691235e-01]\n", 283 | "Maximun Probability = 0.94691235\n", 284 | "Difference of prob 0.8938246965408325\n", 285 | "Results = [2.1533268e-03 5.1092520e-02 9.4110779e-05 9.4666010e-01]\n", 286 | "Maximun Probability = 0.9466601\n", 287 | "Difference of prob 0.8933202028274536\n", 288 | "Results = [2.1672505e-03 5.1354945e-02 9.4309282e-05 9.4638360e-01]\n", 289 | "Maximun Probability = 0.9463836\n", 290 | "Difference of prob 0.8927671909332275\n", 291 | "Results = [2.1898220e-03 5.1963378e-02 9.5376236e-05 9.4575155e-01]\n", 292 | "Maximun Probability = 0.94575155\n", 293 | "Difference of prob 0.891503095626831\n", 294 | "Results = [2.2105020e-03 5.2581031e-02 9.6414646e-05 9.4511217e-01]\n", 295 | "Maximun Probability = 0.94511217\n", 296 | "Difference of prob 0.8902243375778198\n", 297 | "Results = [2.2414557e-03 5.3529061e-02 9.8018747e-05 9.4413161e-01]\n", 298 | "Maximun Probability = 0.9441316\n", 299 | "Difference of prob 0.8882632255554199\n", 300 | "Results = [2.2649472e-03 5.4214422e-02 9.9312601e-05 9.4342142e-01]\n", 301 | "Maximun Probability = 0.9434214\n", 302 | "Difference of prob 0.8868428468704224\n", 303 | "Results = [2.2882982e-03 5.4799788e-02 1.0086113e-04 9.4281113e-01]\n", 304 | "Maximun Probability = 0.94281113\n", 305 | "Difference of prob 0.8856222629547119\n", 306 | "Results = [2.31109187e-03 5.54721467e-02 1.02534184e-04 9.42114294e-01]\n", 307 | "Maximun Probability = 0.9421143\n", 308 | "Difference of prob 0.8842285871505737\n", 309 | "Results = [2.3243940e-03 5.5849060e-02 1.0354279e-04 9.4172311e-01]\n", 310 | "Maximun Probability = 0.9417231\n", 311 | "Difference of prob 0.883446216583252\n", 312 | "Results = [2.3345249e-03 5.6437697e-02 1.0495071e-04 9.4112295e-01]\n", 313 | "Maximun Probability = 0.94112295\n", 314 | "Difference of prob 0.8822458982467651\n", 315 | "Results = [2.34575011e-03 5.66766970e-02 1.06211664e-04 9.40871418e-01]\n", 316 | "Maximun Probability = 0.9408714\n", 317 | "Difference of prob 0.8817428350448608\n", 318 | "Results = [2.3517376e-03 5.6841899e-02 1.0689718e-04 9.4069952e-01]\n", 319 | "Maximun Probability = 0.9406995\n", 320 | "Difference of prob 0.8813990354537964\n", 321 | "Results = [2.3602317e-03 5.7120126e-02 1.0777316e-04 9.4041193e-01]\n", 322 | "Maximun Probability = 0.9404119\n", 323 | "Difference of prob 0.8808238506317139\n", 324 | "Results = [2.36329250e-03 5.73143922e-02 1.08547145e-04 9.40213799e-01]\n", 325 | "Maximun Probability = 0.9402138\n", 326 | "Difference of prob 0.8804275989532471\n", 327 | "Results = [2.3741112e-03 5.7889353e-02 1.0998712e-04 9.3962663e-01]\n", 328 | "Maximun Probability = 0.93962663\n", 329 | "Difference of prob 0.8792532682418823\n", 330 | "Results = [3.4668585e-03 6.4515099e-02 1.1552545e-04 9.3190265e-01]\n", 331 | "Maximun Probability = 0.93190265\n", 332 | "Difference of prob 0.8638052940368652\n", 333 | "Results = [4.7302595e-03 7.0326269e-02 1.2084766e-04 9.2482275e-01]\n", 334 | "Maximun Probability = 0.92482275\n", 335 | "Difference of prob 0.8496454954147339\n", 336 | "Results = [6.011917e-03 7.563742e-02 1.268776e-04 9.182239e-01]\n", 337 | "Maximun Probability = 0.9182239\n", 338 | "Difference of prob 0.8364478349685669\n", 339 | "Results = [7.1917977e-03 8.1278354e-02 1.3196899e-04 9.1139805e-01]\n", 340 | "Maximun Probability = 0.91139805\n", 341 | "Difference of prob 0.822796106338501\n", 342 | "Results = [8.2327742e-03 8.6945310e-02 1.3606912e-04 9.0468597e-01]\n", 343 | "Maximun Probability = 0.904686\n", 344 | "Difference of prob 0.8093719482421875\n" 345 | ] 346 | }, 347 | { 348 | "name": "stdout", 349 | "output_type": "stream", 350 | "text": [ 351 | "Results = [9.2792306e-03 9.2129551e-02 1.4084826e-04 8.9845055e-01]\n", 352 | "Maximun Probability = 0.89845055\n", 353 | "Difference of prob 0.7969011068344116\n", 354 | "Results = [1.037759e-02 9.721869e-02 1.458773e-04 8.922580e-01]\n", 355 | "Maximun Probability = 0.892258\n", 356 | "Difference of prob 0.7845159769058228\n", 357 | "Results = [1.1430362e-02 1.0204464e-01 1.5121361e-04 8.8637394e-01]\n", 358 | "Maximun Probability = 0.88637394\n", 359 | "Difference of prob 0.7727478742599487\n", 360 | "Results = [1.2454492e-02 1.0711482e-01 1.5653571e-04 8.8027430e-01]\n", 361 | "Maximun Probability = 0.8802743\n", 362 | "Difference of prob 0.7605485916137695\n", 363 | "Results = [1.3461913e-02 1.1207042e-01 1.6137982e-04 8.7430644e-01]\n", 364 | "Maximun Probability = 0.87430644\n", 365 | "Difference of prob 0.7486128807067871\n", 366 | "Results = [1.4444659e-02 1.1684667e-01 1.6562355e-04 8.6854327e-01]\n", 367 | "Maximun Probability = 0.86854327\n", 368 | "Difference of prob 0.7370865345001221\n", 369 | "Results = [1.51858181e-02 1.22297525e-01 1.68438710e-04 8.62348437e-01]\n", 370 | "Maximun Probability = 0.86234844\n", 371 | "Difference of prob 0.7246968746185303\n", 372 | "Results = [1.5898360e-02 1.2757377e-01 1.7160116e-04 8.5635650e-01]\n", 373 | "Maximun Probability = 0.8563565\n", 374 | "Difference of prob 0.7127130031585693\n", 375 | "Results = [1.6748823e-02 1.3204831e-01 1.7532110e-04 8.5102779e-01]\n", 376 | "Maximun Probability = 0.8510278\n", 377 | "Difference of prob 0.7020555734634399\n", 378 | "Results = [1.7732562e-02 1.3616629e-01 1.7954900e-04 8.4592181e-01]\n", 379 | "Maximun Probability = 0.8459218\n", 380 | "Difference of prob 0.6918436288833618\n", 381 | "Results = [1.8729245e-02 1.4010285e-01 1.8403848e-04 8.4098411e-01]\n", 382 | "Maximun Probability = 0.8409841\n", 383 | "Difference of prob 0.6819682121276855\n", 384 | "Results = [1.9696511e-02 1.4437851e-01 1.8874324e-04 8.3573645e-01]\n", 385 | "Maximun Probability = 0.83573645\n", 386 | "Difference of prob 0.6714729070663452\n", 387 | "Results = [2.0507978e-02 1.4917342e-01 1.9331538e-04 8.3012551e-01]\n", 388 | "Maximun Probability = 0.8301255\n", 389 | "Difference of prob 0.6602510213851929\n", 390 | "Results = [2.1260481e-02 1.5400842e-01 1.9816896e-04 8.2453310e-01]\n", 391 | "Maximun Probability = 0.8245331\n", 392 | "Difference of prob 0.6490662097930908\n", 393 | "Results = [2.1930747e-02 1.5909833e-01 2.0185387e-04 8.1876928e-01]\n", 394 | "Maximun Probability = 0.8187693\n", 395 | "Difference of prob 0.6375385522842407\n", 396 | "Results = [2.2523401e-02 1.6424966e-01 2.0546596e-04 8.1302166e-01]\n", 397 | "Maximun Probability = 0.81302166\n", 398 | "Difference of prob 0.6260433197021484\n", 399 | "Results = [2.3299769e-02 1.6890420e-01 2.0951660e-04 8.0758673e-01]\n", 400 | "Maximun Probability = 0.8075867\n", 401 | "Difference of prob 0.6151734590530396\n", 402 | "Results = [2.4048096e-02 1.7326987e-01 2.1360230e-04 8.0246866e-01]\n", 403 | "Maximun Probability = 0.80246866\n", 404 | "Difference of prob 0.6049373149871826\n", 405 | "Results = [2.4694746e-02 1.7757288e-01 2.1798944e-04 7.9751462e-01]\n", 406 | "Maximun Probability = 0.7975146\n", 407 | "Difference of prob 0.5950292348861694\n", 408 | "Results = [2.5586871e-02 1.8149464e-01 2.2351861e-04 7.9269516e-01]\n", 409 | "Maximun Probability = 0.79269516\n", 410 | "Difference of prob 0.5853903293609619\n", 411 | "Results = [2.6593264e-02 1.8535708e-01 2.2808160e-04 7.8782177e-01]\n", 412 | "Maximun Probability = 0.78782177\n", 413 | "Difference of prob 0.5756435394287109\n", 414 | "Results = [2.7463002e-02 1.8936817e-01 2.3176272e-04 7.8293729e-01]\n", 415 | "Maximun Probability = 0.7829373\n", 416 | "Difference of prob 0.5658745765686035\n", 417 | "Results = [2.8245749e-02 1.9330449e-01 2.3493600e-04 7.7821505e-01]\n", 418 | "Maximun Probability = 0.77821505\n", 419 | "Difference of prob 0.5564301013946533\n", 420 | "Results = [2.9007280e-02 1.9707040e-01 2.3833921e-04 7.7368420e-01]\n", 421 | "Maximun Probability = 0.7736842\n", 422 | "Difference of prob 0.5473684072494507\n", 423 | "Results = [2.9637331e-02 2.0089945e-01 2.4174440e-04 7.6922166e-01]\n", 424 | "Maximun Probability = 0.76922166\n", 425 | "Difference of prob 0.5384433269500732\n", 426 | "Results = [3.0188695e-02 2.0498207e-01 2.4530798e-04 7.6458412e-01]\n", 427 | "Maximun Probability = 0.7645841\n", 428 | "Difference of prob 0.5291682481765747\n", 429 | "Results = [3.0762309e-02 2.0878512e-01 2.4892343e-04 7.6020384e-01]\n", 430 | "Maximun Probability = 0.76020384\n", 431 | "Difference of prob 0.5204076766967773\n", 432 | "Results = [3.1303819e-02 2.1273373e-01 2.5224066e-04 7.5571042e-01]\n", 433 | "Maximun Probability = 0.7557104\n", 434 | "Difference of prob 0.5114208459854126\n", 435 | "Results = [3.1977035e-02 2.1621852e-01 2.5580902e-04 7.5154883e-01]\n", 436 | "Maximun Probability = 0.7515488\n", 437 | "Difference of prob 0.503097653388977\n", 438 | "Results = [3.2585129e-02 2.1986488e-01 2.5937165e-04 7.4729079e-01]\n", 439 | "Maximun Probability = 0.7472908\n", 440 | "Difference of prob 0.49458158016204834\n", 441 | "Results = [3.3474185e-02 2.2476162e-01 2.6524960e-04 7.4149907e-01]\n", 442 | "Maximun Probability = 0.74149907\n", 443 | "Difference of prob 0.4829981327056885\n", 444 | "Results = [3.4326144e-02 2.2946939e-01 2.7032619e-04 7.3593426e-01]\n", 445 | "Maximun Probability = 0.73593426\n", 446 | "Difference of prob 0.47186851501464844\n", 447 | "Results = [3.5152875e-02 2.3481956e-01 2.7563266e-04 7.2975206e-01]\n", 448 | "Maximun Probability = 0.72975206\n", 449 | "Difference of prob 0.4595041275024414\n", 450 | "Results = [3.5919379e-02 2.4028973e-01 2.8097749e-04 7.2351015e-01]\n", 451 | "Maximun Probability = 0.72351015\n", 452 | "Difference of prob 0.4470202922821045\n", 453 | "Results = [3.6657024e-02 2.4603975e-01 2.8595250e-04 7.1701735e-01]\n", 454 | "Maximun Probability = 0.71701735\n", 455 | "Difference of prob 0.43403470516204834\n", 456 | "Results = [3.7416369e-02 2.5151208e-01 2.9060096e-04 7.1078110e-01]\n", 457 | "Maximun Probability = 0.7107811\n", 458 | "Difference of prob 0.42156219482421875\n", 459 | "Results = [3.8111974e-02 2.5718862e-01 2.9505955e-04 7.0440453e-01]\n", 460 | "Maximun Probability = 0.70440453\n", 461 | "Difference of prob 0.4088090658187866\n", 462 | "Results = [3.8780764e-02 2.6279032e-01 2.9966104e-04 6.9812936e-01]\n", 463 | "Maximun Probability = 0.69812936\n", 464 | "Difference of prob 0.39625871181488037\n", 465 | "Results = [3.9263442e-02 2.6321250e-01 3.4021647e-04 6.9718391e-01]\n", 466 | "Maximun Probability = 0.6971839\n", 467 | "Difference of prob 0.3943678140640259\n", 468 | "Results = [3.9824955e-02 2.6369035e-01 3.8872290e-04 6.9609612e-01]\n", 469 | "Maximun Probability = 0.6960961\n", 470 | "Difference of prob 0.3921922445297241\n", 471 | "Results = [4.0350243e-02 2.6411331e-01 4.3551734e-04 6.9510102e-01]\n", 472 | "Maximun Probability = 0.695101\n", 473 | "Difference of prob 0.39020204544067383\n", 474 | "Results = [4.0851887e-02 2.6447198e-01 4.8617530e-04 6.9419003e-01]\n", 475 | "Maximun Probability = 0.69419\n", 476 | "Difference of prob 0.3883800506591797\n", 477 | "Results = [4.1359238e-02 2.6510394e-01 5.5432570e-04 6.9298261e-01]\n", 478 | "Maximun Probability = 0.6929826\n", 479 | "Difference of prob 0.3859652280807495\n", 480 | "Results = [4.1912988e-02 2.6600119e-01 6.2514393e-04 6.9146073e-01]\n", 481 | "Maximun Probability = 0.6914607\n", 482 | "Difference of prob 0.3829214572906494\n", 483 | "Results = [4.2431090e-02 2.6691043e-01 6.8228005e-04 6.8997622e-01]\n", 484 | "Maximun Probability = 0.6899762\n", 485 | "Difference of prob 0.37995243072509766\n", 486 | "Results = [0.04300736 0.26765883 0.00073433 0.6885996 ]\n", 487 | "Maximun Probability = 0.6885996\n", 488 | "Difference of prob 0.3771991729736328\n", 489 | "Results = [0.04365732 0.26833013 0.00078897 0.6872236 ]\n", 490 | "Maximun Probability = 0.6872236\n", 491 | "Difference of prob 0.374447226524353\n", 492 | "Results = [0.04449764 0.26919633 0.00084865 0.6854574 ]\n", 493 | "Maximun Probability = 0.6854574\n", 494 | "Difference of prob 0.3709148168563843\n", 495 | "Results = [0.04502483 0.2695298 0.00087607 0.6845693 ]\n", 496 | "Maximun Probability = 0.6845693\n", 497 | "Difference of prob 0.36913859844207764\n", 498 | "Results = [0.04608308 0.27004886 0.00091064 0.68295753]\n", 499 | "Maximun Probability = 0.68295753\n", 500 | "Difference of prob 0.36591506004333496\n", 501 | "Results = [0.04730458 0.27040976 0.00094365 0.6813421 ]\n", 502 | "Maximun Probability = 0.6813421\n", 503 | "Difference of prob 0.3626842498779297\n", 504 | "Results = [0.04836786 0.27117482 0.00099191 0.6794656 ]\n", 505 | "Maximun Probability = 0.6794656\n", 506 | "Difference of prob 0.35893118381500244\n", 507 | "Results = [0.04944633 0.27194786 0.00104206 0.6775639 ]\n", 508 | "Maximun Probability = 0.6775639\n", 509 | "Difference of prob 0.35512781143188477\n", 510 | "Results = [0.05007906 0.27220097 0.0010677 0.6766525 ]\n", 511 | "Maximun Probability = 0.6766525\n", 512 | "Difference of prob 0.35330498218536377\n", 513 | "Results = [0.05142226 0.27258825 0.00110752 0.6748821 ]\n", 514 | "Maximun Probability = 0.6748821\n", 515 | "Difference of prob 0.34976422786712646\n", 516 | "Results = [0.05244524 0.27286625 0.00114238 0.6735463 ]\n", 517 | "Maximun Probability = 0.6735463\n", 518 | "Difference of prob 0.3470926284790039\n", 519 | "Results = [0.05404091 0.27325305 0.00119355 0.6715126 ]\n", 520 | "Maximun Probability = 0.6715126\n", 521 | "Difference of prob 0.34302520751953125\n", 522 | "[INFO] cleaning up...\n" 523 | ] 524 | }, 525 | { 526 | "ename": "AttributeError", 527 | "evalue": "'cv2.VideoCapture' object has no attribute 'stream'", 528 | "output_type": "error", 529 | "traceback": [ 530 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 531 | "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", 532 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 138\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"[INFO] cleaning up...\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 139\u001b[0m \u001b[0mwriter\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrelease\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 140\u001b[1;33m \u001b[0mvs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstream\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrelease\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 533 | "\u001b[1;31mAttributeError\u001b[0m: 'cv2.VideoCapture' object has no attribute 'stream'" 534 | ] 535 | } 536 | ], 537 | "source": [ 538 | "from keras.models import load_model\n", 539 | "from collections import deque\n", 540 | "import numpy as np\n", 541 | "import argparse\n", 542 | "import time\n", 543 | "import pickle\n", 544 | "import cv2\n", 545 | "from twilio.rest import Client\n", 546 | "camid = 101 \n", 547 | "location = 'Hackabit BIT MESHRA,Ranchi, Jharkhand ,India' \n", 548 | "\n", 549 | "ap = argparse.ArgumentParser()\n", 550 | "ap.add_argument(\"-m\", \"--model\", required=True,\n", 551 | "\thelp=\"path to trained serialized model\")\n", 552 | "ap.add_argument(\"-l\", \"--label-bin\", required=True,\n", 553 | "\thelp=\"path to label binarizer\")\n", 554 | "ap.add_argument(\"-i\", \"--input\", required=False,\n", 555 | "\thelp=\"path to our input video\")\n", 556 | "ap.add_argument(\"-o\", \"--output\", required=True,\n", 557 | "\thelp=\"path to our output video\")\n", 558 | "ap.add_argument(\"-s\", \"--size\", type=int, default=128,\n", 559 | "\thelp=\"size of queue for averaging\")\n", 560 | "args = vars(ap.parse_args('-m model -l label-bin -o output'.split()))\n", 561 | "\n", 562 | "print(\"[INFO] loading model and label binarizer...\")\n", 563 | "model = load_model(args[\"model\"])\n", 564 | "lb = pickle.loads(open(args[\"label_bin\"], \"rb\").read())\n", 565 | "\n", 566 | "mean = np.array([123.68, 116.779, 103.939][::1], dtype=\"float32\")\n", 567 | "Q = deque(maxlen=args[\"size\"])\n", 568 | "\n", 569 | "print(\"[INFO] starting video stream...\")\n", 570 | "vs = cv2.VideoCapture('demo.mp4')\n", 571 | "writer = None\n", 572 | "time.sleep(2.0)\n", 573 | "#-------------------\n", 574 | "(W, H) = (None, None)\n", 575 | "client = Client(\"AC358d6a22cb7b8966c3267905a9XXXXXXX\", \"2f9227d6e04fd21e44d85772c5XXXXX\") \n", 576 | "prelabel = ''\n", 577 | "prelabel = ''\n", 578 | "ok = 'Normal'\n", 579 | "fi_label = []\n", 580 | "framecount = 0\n", 581 | "while True:\n", 582 | "\tflag,frame = vs.read()\n", 583 | "\n", 584 | "\n", 585 | "\tif W is None or H is None:\n", 586 | "\t\t(H, W) = frame.shape[:2]\n", 587 | "\n", 588 | "\n", 589 | "\toutput = frame.copy()\n", 590 | "\tframe = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)\n", 591 | "\tframe = cv2.resize(frame, (224, 224)).astype(\"float32\")\n", 592 | "\tframe -= mean\n", 593 | "\n", 594 | "\n", 595 | "\tpreds = model.predict(np.expand_dims(frame, axis=0))[0]\n", 596 | "\n", 597 | "\tprediction = preds.argmax(axis=0)\n", 598 | "\tQ.append(preds)\n", 599 | "\n", 600 | "\n", 601 | "\tresults = np.array(Q).mean(axis=0)\n", 602 | "\tprint('Results = ', results)\n", 603 | "\tmaxprob = np.max(results)\n", 604 | "\tprint('Maximun Probability = ', maxprob)\n", 605 | "\ti = np.argmax(results)\n", 606 | "\tlabel = lb[i]\n", 607 | "\n", 608 | "\trest = 1 - maxprob\n", 609 | " \n", 610 | "\tdiff = (maxprob) - (rest)\n", 611 | "\tprint('Difference of prob ', diff)\n", 612 | "\tth = 100\n", 613 | "\tif diff > .80:\n", 614 | "\t\tth = diff\n", 615 | " \n", 616 | " \n", 617 | " \n", 618 | " \n", 619 | "\tif (preds[prediction]) < th:\n", 620 | "\t\ttext = \"Alert : {} - {:.2f}%\".format((ok), 100 - (maxprob * 100))\n", 621 | "\t\tcv2.putText(output, text, (35, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.25, (0, 255, 0), 5)\n", 622 | "\telse:\n", 623 | "\t\tfi_label = np.append(fi_label, label)\n", 624 | "\t\ttext = \"Alert : {} - {:.2f}%\".format((label), maxprob * 100)\n", 625 | "\t\tcv2.putText(output, text, (35, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.25, (0, 255, 0), 5) \n", 626 | "\t\tif label != prelabel: \n", 627 | "\t\t\tclient.messages.create(to=\"+917975720047\", \n", 628 | " from_=\"+12054967936\", \n", 629 | " body='\\n'+ str(text) +'\\n Satellite: ' + str(camid) + '\\n Orbit: ' + location)\n", 630 | "\t\tprelabel = label\n", 631 | "\n", 632 | "\n", 633 | "\tif writer is None:\n", 634 | "\t\tfourcc = cv2.VideoWriter_fourcc(*\"MJPG\")\n", 635 | "\t\twriter = cv2.VideoWriter(args[\"output\"], fourcc, 30,\n", 636 | "\t\t\t(W, H), True)\n", 637 | "\n", 638 | "\twriter.write(output)\n", 639 | "\n", 640 | "\t# show the output image\n", 641 | "\tcv2.imshow(\"Output\", output)\n", 642 | "\tkey = cv2.waitKey(1) & 0xFF\n", 643 | "\n", 644 | "\tif key == ord(\"q\"):\n", 645 | "\t\tbreak\n", 646 | "\n", 647 | "# release the file pointers\n", 648 | "print(\"[INFO] cleaning up...\")\n", 649 | "writer.release()\n", 650 | "vs.stream.release()\n" 651 | ] 652 | }, 653 | { 654 | "cell_type": "code", 655 | "execution_count": null, 656 | "metadata": {}, 657 | "outputs": [], 658 | "source": [] 659 | }, 660 | { 661 | "cell_type": "code", 662 | "execution_count": null, 663 | "metadata": {}, 664 | "outputs": [], 665 | "source": [] 666 | } 667 | ], 668 | "metadata": { 669 | "kernelspec": { 670 | "display_name": "Python 3", 671 | "language": "python", 672 | "name": "python3" 673 | }, 674 | "language_info": { 675 | "codemirror_mode": { 676 | "name": "ipython", 677 | "version": 3 678 | }, 679 | "file_extension": ".py", 680 | "mimetype": "text/x-python", 681 | "name": "python", 682 | "nbconvert_exporter": "python", 683 | "pygments_lexer": "ipython3", 684 | "version": "3.7.4" 685 | } 686 | }, 687 | "nbformat": 4, 688 | "nbformat_minor": 2 689 | } 690 | -------------------------------------------------------------------------------- /ACCIDetect.py: -------------------------------------------------------------------------------- 1 | from keras.models import load_model 2 | from collections import deque 3 | import numpy as np 4 | import argparse 5 | import time 6 | import pickle 7 | import cv2 8 | from twilio.rest import Client 9 | camid = 101 10 | location = 'Hackabit BIT MESHRA,Ranchi, Jharkhand ,India' 11 | 12 | ap = argparse.ArgumentParser() 13 | ap.add_argument("-m", "--model", required=True, 14 | help="path to trained serialized model") 15 | ap.add_argument("-l", "--label-bin", required=True, 16 | help="path to label binarizer") 17 | ap.add_argument("-i", "--input", required=False, 18 | help="path to our input video") 19 | ap.add_argument("-o", "--output", required=True, 20 | help="path to our output video") 21 | ap.add_argument("-s", "--size", type=int, default=128, 22 | help="size of queue for averaging") 23 | args = vars(ap.parse_args('-m model -l label-bin -o output'.split())) 24 | 25 | print("[INFO] loading model and label binarizer...") 26 | model = load_model(args["model"]) 27 | lb = pickle.loads(open(args["label_bin"], "rb").read()) 28 | 29 | mean = np.array([123.68, 116.779, 103.939][::1], dtype="float32") 30 | Q = deque(maxlen=args["size"]) 31 | 32 | print("[INFO] starting video stream...") 33 | vs = cv2.VideoCapture('demo.mp4') 34 | writer = None 35 | time.sleep(2.0) 36 | #------------------- 37 | (W, H) = (None, None) 38 | client = Client("AC358d6a22cb7b8966c3267905a939c03b", "2f9227d6e04fd21e44d85772c5412511") 39 | prelabel = '' 40 | prelabel = '' 41 | ok = 'Normal' 42 | fi_label = [] 43 | framecount = 0 44 | while True: 45 | flag,frame = vs.read() 46 | 47 | 48 | if W is None or H is None: 49 | (H, W) = frame.shape[:2] 50 | 51 | 52 | output = frame.copy() 53 | frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) 54 | frame = cv2.resize(frame, (224, 224)).astype("float32") 55 | frame -= mean 56 | 57 | 58 | preds = model.predict(np.expand_dims(frame, axis=0))[0] 59 | 60 | prediction = preds.argmax(axis=0) 61 | Q.append(preds) 62 | 63 | 64 | results = np.array(Q).mean(axis=0) 65 | print('Results = ', results) 66 | maxprob = np.max(results) 67 | print('Maximun Probability = ', maxprob) 68 | i = np.argmax(results) 69 | label = lb[i] 70 | 71 | rest = 1 - maxprob 72 | 73 | diff = (maxprob) - (rest) 74 | print('Difference of prob ', diff) 75 | th = 100 76 | if diff > .80: 77 | th = diff 78 | 79 | 80 | 81 | 82 | if (preds[prediction]) < th: 83 | text = "Alert : {} - {:.2f}%".format((ok), 100 - (maxprob * 100)) 84 | cv2.putText(output, text, (35, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.25, (0, 255, 0), 5) 85 | else: 86 | fi_label = np.append(fi_label, label) 87 | text = "Alert : {} - {:.2f}%".format((label), maxprob * 100) 88 | cv2.putText(output, text, (35, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.25, (0, 255, 0), 5) 89 | if label != prelabel: 90 | client.messages.create(to="+917975720047", 91 | from_="+12054967936", 92 | body='\n'+ str(text) +'\n Satellite: ' + str(camid) + '\n Orbit: ' + location) 93 | prelabel = label 94 | 95 | 96 | if writer is None: 97 | fourcc = cv2.VideoWriter_fourcc(*"MJPG") 98 | writer = cv2.VideoWriter(args["output"], fourcc, 30, 99 | (W, H), True) 100 | 101 | writer.write(output) 102 | 103 | # show the output image 104 | cv2.imshow("Output", output) 105 | key = cv2.waitKey(1) & 0xFF 106 | 107 | if key == ord("q"): 108 | break 109 | 110 | # release the file pointers 111 | print("[INFO] cleaning up...") 112 | writer.release() 113 | vs.stream.release() 114 | -------------------------------------------------------------------------------- /ACCIdetect.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackabit19/DevSena/3a1bed96db0ad4cb326af1845fdc1d339a43e34f/ACCIdetect.pptx -------------------------------------------------------------------------------- /ML/CM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackabit19/DevSena/3a1bed96db0ad4cb326af1845fdc1d339a43e34f/ML/CM.png -------------------------------------------------------------------------------- /ML/Learning-curve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackabit19/DevSena/3a1bed96db0ad4cb326af1845fdc1d339a43e34f/ML/Learning-curve.png -------------------------------------------------------------------------------- /ML/Precision-Recall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackabit19/DevSena/3a1bed96db0ad4cb326af1845fdc1d339a43e34f/ML/Precision-Recall.png -------------------------------------------------------------------------------- /ML/ROC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackabit19/DevSena/3a1bed96db0ad4cb326af1845fdc1d339a43e34f/ML/ROC.png -------------------------------------------------------------------------------- /ML/preprocessing.py: -------------------------------------------------------------------------------- 1 | import matplotlib 2 | import tensorflow as tf 3 | from keras.preprocessing.image import ImageDataGenerator 4 | from keras.layers.pooling import AveragePooling2D 5 | from keras.applications import ResNet50 6 | from keras.layers.core import Dropout 7 | from keras.layers.core import Flatten 8 | from keras.layers.core import Dense 9 | from keras.layers import Input 10 | from keras.models import Model 11 | from keras.optimizers import SGD 12 | from sklearn.preprocessing import LabelBinarizer 13 | from sklearn.model_selection import train_test_split 14 | from sklearn.metrics import classification_report 15 | from imutils import paths 16 | import matplotlib.pyplot as plt 17 | import numpy as np 18 | import argparse 19 | import pickle 20 | import cv2 21 | import os 22 | from sklearn.metrics import confusion_matrix 23 | from sklearn.utils.multiclass import unique_labels 24 | 25 | ap = argparse.ArgumentParser() 26 | ap.add_argument("-d", "--dataset", required=True, 27 | help="path to input dataset") 28 | ap.add_argument("-m", "--model", required=True, 29 | help="path to output serialized model") 30 | ap.add_argument("-l", "--label-bin", required=True, 31 | help="path to output label binarizer") 32 | ap.add_argument("-e", "--epochs", type=int, default=20, 33 | help="# of epochs to train our network for") 34 | ap.add_argument("-p", "--plot", type=str, default="plot.png", 35 | help="path to output loss/accuracy plot") 36 | args = vars(ap.parse_args('-d dataset -m model -l label-bin'.split())) 37 | 38 | LABELS = set(["Accident", "Fire", "Flood", "Robbery"]) 39 | 40 | print("[INFO] loading images...") 41 | imagePaths = list(paths.list_images(args["dataset"])) 42 | data = [] 43 | labels = [] 44 | 45 | for imagePath in imagePaths: 46 | label = imagePath.split(os.path.sep)[-2] 47 | 48 | if label not in LABELS: 49 | continue 50 | 51 | image = cv2.imread(imagePath) 52 | image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) 53 | image = cv2.resize(image, (224, 224)) 54 | 55 | data.append(image) 56 | labels.append(label) 57 | 58 | data = np.array(data) 59 | labels = np.array(labels) 60 | 61 | lb = LabelBinarizer() 62 | labels = lb.fit_transform(labels) 63 | 64 | (trainX, testX, trainY, testY) = train_test_split(data, labels, 65 | test_size=0.20, stratify=labels, random_state=42) 66 | 67 | trainAug = ImageDataGenerator( 68 | rotation_range=30, 69 | zoom_range=0.15, 70 | width_shift_range=0.2, 71 | height_shift_range=0.2, 72 | shear_range=0.15, 73 | horizontal_flip=True, 74 | fill_mode="nearest") 75 | 76 | valAug = ImageDataGenerator() 77 | 78 | mean = np.array([123.68, 116.779, 103.939], dtype="float32") 79 | trainAug.mean = mean 80 | valAug.mean = mean 81 | -------------------------------------------------------------------------------- /ML/realtimeV2.py: -------------------------------------------------------------------------------- 1 | from keras.models import load_model 2 | from imutils.video import VideoStream 3 | from collections import deque 4 | import numpy as np 5 | import argparse 6 | import time 7 | import pickle 8 | import cv2 9 | ap = argparse.ArgumentParser() 10 | ap.add_argument("-m", "--model", required=True, 11 | help="path to trained serialized model") 12 | ap.add_argument("-l", "--label-bin", required=True, 13 | help="path to label binarizer") 14 | ap.add_argument("-i", "--input", required=False, 15 | help="path to our input video") 16 | ap.add_argument("-o", "--output", required=True, 17 | help="path to our output video") 18 | ap.add_argument("-s", "--size", type=int, default=128, 19 | help="size of queue for averaging") 20 | args = vars(ap.parse_args('-m model -l label-bin -o output'.split())) 21 | 22 | print("[INFO] loading model and label binarizer...") 23 | model = load_model(args["model"]) 24 | lb = pickle.loads(open(args["label_bin"], "rb").read()) 25 | 26 | mean = np.array([123.68, 116.779, 103.939][::1], dtype="float32") 27 | Q = deque(maxlen=args["size"]) 28 | 29 | print("[INFO] starting video stream...") 30 | vs = cv2.VideoCapture('demo.mp4') 31 | writer = None 32 | time.sleep(2.0) 33 | #------------------- 34 | (W, H) = (None, None) 35 | prelabel = '' 36 | prelabel = '' 37 | ok = 'Normal' 38 | fi_label = [] 39 | framecount = 0 40 | while True: 41 | flag,frame = vs.read() 42 | 43 | if W is None or H is None: 44 | (H, W) = frame.shape[:2] 45 | output = frame.copy() 46 | frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) 47 | frame = cv2.resize(frame, (224, 224)).astype("float32") 48 | frame -= mean 49 | 50 | preds = model.predict(np.expand_dims(frame, axis=0))[0] 51 | 52 | prediction = preds.argmax(axis=0) 53 | Q.append(preds) 54 | 55 | results = np.array(Q).mean(axis=0) 56 | print('Results = ', results) 57 | maxprob = np.max(results) 58 | print('Maximun Probability = ', maxprob) 59 | i = np.argmax(results) 60 | label = lb[i] 61 | rest = 1 - maxprob 62 | 63 | diff = (maxprob) - (rest) 64 | print('Difference of prob ', diff) 65 | th = 100 66 | if diff > .80: 67 | th = diff 68 | 69 | 70 | 71 | 72 | if (preds[prediction]) < th: 73 | text = "Alert : {} - {:.2f}%".format((ok), 100 - (maxprob * 100)) 74 | cv2.putText(output, text, (35, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.25, (0, 255, 0), 5) 75 | else: 76 | fi_label = np.append(fi_label, label) 77 | text = "Alert : {} - {:.2f}%".format((label), maxprob * 100) 78 | cv2.putText(output, text, (35, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.25, (0, 255, 0), 5) 79 | 80 | prelabel = label 81 | 82 | if writer is None: 83 | fourcc = cv2.VideoWriter_fourcc(*"MJPG") 84 | writer = cv2.VideoWriter(args["output"], fourcc, 30, 85 | (W, H), True) 86 | 87 | writer.write(output) 88 | 89 | cv2.imshow("Output", output) 90 | key = cv2.waitKey(1) & 0xFF 91 | 92 | if key == ord("q"): 93 | break 94 | print("[INFO] cleaning up...") 95 | writer.release() 96 | vs.stream.release() 97 | -------------------------------------------------------------------------------- /ML/trainV2.py: -------------------------------------------------------------------------------- 1 | import matplotlib 2 | import tensorflow as tf 3 | from keras.preprocessing.image import ImageDataGenerator 4 | from keras.layers.pooling import AveragePooling2D 5 | from keras.applications import ResNet50 6 | from keras.layers.core import Dropout 7 | from keras.layers.core import Flatten 8 | from keras.layers.core import Dense 9 | from keras.layers import Input 10 | from keras.models import Model 11 | from keras.optimizers import SGD 12 | from sklearn.preprocessing import LabelBinarizer 13 | from sklearn.model_selection import train_test_split 14 | from sklearn.metrics import classification_report 15 | from imutils import paths 16 | import matplotlib.pyplot as plt 17 | import numpy as np 18 | import argparse 19 | import pickle 20 | import cv2 21 | import os 22 | from sklearn.metrics import confusion_matrix 23 | from sklearn.utils.multiclass import unique_labels 24 | 25 | ap = argparse.ArgumentParser() 26 | ap.add_argument("-d", "--dataset", required=True, 27 | help="path to input dataset") 28 | ap.add_argument("-m", "--model", required=True, 29 | help="path to output serialized model") 30 | ap.add_argument("-l", "--label-bin", required=True, 31 | help="path to output label binarizer") 32 | ap.add_argument("-e", "--epochs", type=int, default=20, 33 | help="# of epochs to train our network for") 34 | ap.add_argument("-p", "--plot", type=str, default="plot.png", 35 | help="path to output loss/accuracy plot") 36 | args = vars(ap.parse_args('-d dataset -m model -l label-bin'.split())) 37 | 38 | LABELS = set(["Accident", "Fire", "Flood", "Robbery"]) 39 | 40 | print("[INFO] loading images...") 41 | imagePaths = list(paths.list_images(args["dataset"])) 42 | data = [] 43 | labels = [] 44 | 45 | for imagePath in imagePaths: 46 | label = imagePath.split(os.path.sep)[-2] 47 | 48 | if label not in LABELS: 49 | continue 50 | 51 | image = cv2.imread(imagePath) 52 | image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) 53 | image = cv2.resize(image, (224, 224)) 54 | 55 | data.append(image) 56 | labels.append(label) 57 | 58 | data = np.array(data) 59 | labels = np.array(labels) 60 | 61 | lb = LabelBinarizer() 62 | labels = lb.fit_transform(labels) 63 | 64 | (trainX, testX, trainY, testY) = train_test_split(data, labels, 65 | test_size=0.20, stratify=labels, random_state=42) 66 | 67 | trainAug = ImageDataGenerator( 68 | rotation_range=30, 69 | zoom_range=0.15, 70 | width_shift_range=0.2, 71 | height_shift_range=0.2, 72 | shear_range=0.15, 73 | horizontal_flip=True, 74 | fill_mode="nearest") 75 | 76 | valAug = ImageDataGenerator() 77 | 78 | mean = np.array([123.68, 116.779, 103.939], dtype="float32") 79 | trainAug.mean = mean 80 | valAug.mean = mean 81 | 82 | baseModel = ResNet50(weights="imagenet", include_top=False, 83 | input_tensor=Input(shape=(224, 224, 3))) 84 | 85 | headModel = baseModel.output 86 | headModel = AveragePooling2D(pool_size=(7, 7))(headModel) 87 | headModel = Flatten(name="flatten")(headModel) 88 | headModel = Dense(512, activation="relu")(headModel) 89 | headModel = Dropout(0.5)(headModel) 90 | headModel = Dense(len(lb.classes_), activation="softmax")(headModel) 91 | 92 | model = Model(inputs=baseModel.input, outputs=headModel) 93 | 94 | for layer in baseModel.layers: 95 | layer.trainable = False 96 | 97 | print("[INFO] compiling model...") 98 | opt = SGD(lr=1e-4, momentum=0.9, decay=1e-4 / args["epochs"]) 99 | model.compile(loss="categorical_crossentropy", optimizer=opt, 100 | metrics=["accuracy"]) 101 | 102 | 103 | print("[INFO] training head...") 104 | H = model.fit_generator( 105 | trainAug.flow(trainX, trainY, batch_size=32), 106 | steps_per_epoch=len(trainX) // 32, 107 | validation_data=valAug.flow(testX, testY), 108 | validation_steps=len(testX) // 32, 109 | epochs=args["epochs"]) 110 | 111 | print("[INFO] evaluating network...") 112 | y_score = model.predict(testX, batch_size=32) 113 | print(classification_report(testY.argmax(axis=1), 114 | y_score.argmax(axis=1), target_names=lb.classes_)) 115 | 116 | lw = 2 117 | from sklearn.metrics import roc_curve, auc 118 | from scipy import interp 119 | fpr = dict() 120 | tpr = dict() 121 | roc_auc = dict() 122 | y_score = model.predict(testX, batch_size=32) 123 | n_classes = 4 124 | for i in range(n_classes): 125 | fpr[i], tpr[i], _ = roc_curve(testY[:, i], y_score[:, i]) 126 | roc_auc[i] = auc(fpr[i], tpr[i]) 127 | 128 | fpr["micro"], tpr["micro"], _ = roc_curve(testY.ravel(), y_score.ravel()) 129 | roc_auc["micro"] = auc(fpr["micro"], tpr["micro"]) 130 | 131 | plt.clf() 132 | plt.figure(1) 133 | plt.plot(fpr["micro"], tpr["micro"], 134 | label='micro-average ROC curve (area = {0:0.2f})' 135 | ''.format(roc_auc["micro"]), 136 | color='navy', linestyle=':', linewidth=4) 137 | 138 | plt.plot([0, 1], [0, 1], 'k--', lw=lw) 139 | plt.xlim([0.0, 1.0]) 140 | plt.ylim([0.0, 1.05]) 141 | plt.xlabel('False Positive Rate') 142 | plt.ylabel('True Positive Rate') 143 | plt.title('Receiver Operating Characteristic Curve') 144 | plt.legend(loc="lower right") 145 | 146 | plt.savefig('ROC.eps', format='eps', dpi=1000) 147 | plt.savefig('ROC.png', format='png', dpi=1000) 148 | 149 | from sklearn.metrics import precision_recall_curve 150 | from sklearn.metrics import auc 151 | from sklearn.metrics import average_precision_score 152 | 153 | precision = dict() 154 | recall = dict() 155 | average_precision = dict() 156 | for i in range(n_classes): 157 | precision[i], recall[i], _ = precision_recall_curve(testY[:, i], 158 | y_score[:, i]) 159 | average_precision[i] = average_precision_score(testY[:, i], y_score[:, i]) 160 | 161 | precision["micro"], recall["micro"], _ = precision_recall_curve(testY.ravel(), 162 | y_score.ravel()) 163 | average_precision["micro"] = average_precision_score(testY, y_score, 164 | average="micro") 165 | 166 | plt.clf() 167 | plt.figure(2) 168 | plt.step(recall['micro'], precision['micro'], color='b', alpha=0.2, 169 | where='post') 170 | plt.fill_between(recall["micro"], precision["micro"], alpha=0.2, color='b')#, 171 | 172 | 173 | plt.xlabel('Recall') 174 | plt.ylabel('Precision') 175 | plt.ylim([0.0, 1.05]) 176 | plt.xlim([0.0, 1.0]) 177 | plt.title('Average precision score over all classes: AP={0:0.2f}' 178 | .format(average_precision["micro"])) 179 | plt.savefig('Precision-Recall.eps', format='eps', dpi=1000) 180 | plt.savefig('Precision-Recall.png', format='png', bbox_inches='tight') 181 | 182 | plt.clf() 183 | plt.figure(4) 184 | plt.plot(H.history["val_loss"], label="val_loss") 185 | plt.plot(H.history["val_acc"], label="val_acc") 186 | plt.plot(H.history["loss"], label="train_loss") 187 | plt.plot(H.history["acc"], label="train_acc") 188 | plt.title('Model Learning Curve') 189 | plt.ylabel('Loss/Accuracy') 190 | plt.xlabel('Epoch') 191 | plt.legend(['Validation loss', 'Validation accuracy', 'Training loss', 'Training accuracy'], loc='upper right') 192 | plt.savefig('Learning-curve.eps', format='eps', dpi=1000) 193 | plt.savefig('Learning-curve.png', format='png', bbox_inches='tight') 194 | def plot_confusion_matrix1(y_true, y_pred, classes, 195 | normalize=False, 196 | title=None, 197 | cmap=plt.cm.Blues): 198 | 199 | if not title: 200 | if normalize: 201 | title = 'Normalized confusion matrix' 202 | else: 203 | title = 'Confusion matrix, without normalization' 204 | 205 | cm = confusion_matrix(y_true, y_pred) 206 | if normalize: 207 | cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] 208 | print("Normalized confusion matrix") 209 | else: 210 | print('Confusion matrix, without normalization') 211 | 212 | print(cm) 213 | 214 | fig, ax = plt.subplots() 215 | im = ax.imshow(cm, interpolation='nearest', cmap=cmap) 216 | ax.figure.colorbar(im, ax=ax) 217 | 218 | ax.set(xticks=np.arange(cm.shape[1]), 219 | yticks=np.arange(cm.shape[0]), 220 | xticklabels=classes, yticklabels=classes, 221 | title=title, 222 | ylabel='True label', 223 | xlabel='Predicted label') 224 | 225 | plt.setp(ax.get_xticklabels(), rotation=45, ha="right", 226 | rotation_mode="anchor") 227 | 228 | fmt = '.2f' if normalize else 'd' 229 | thresh = cm.max() / 2. 230 | for i in range(cm.shape[0]): 231 | for j in range(cm.shape[1]): 232 | ax.text(j, i, format(cm[i, j], fmt), 233 | ha="center", va="center", 234 | color="white" if cm[i, j] > thresh else "black") 235 | fig.tight_layout() 236 | return ax 237 | 238 | 239 | np.set_printoptions(precision=2) 240 | 241 | y_test = testY.argmax(axis=1) 242 | y_pred = y_score.argmax(axis=1) 243 | lb = ["Accident", "Fire", "Flood", "Robbery"] 244 | plot_confusion_matrix1(y_test, y_pred, classes=lb, normalize=True, 245 | title='Normalized confusion matrix') 246 | 247 | plt.savefig('CM.png', format='png', dpi=1000) 248 | plt.savefig('CM.tiff', format='tiff', dpi=1000) 249 | 250 | print("[INFO] Saving model...") 251 | model.save(args["model"]) 252 | 253 | f = open(args["label_bin"], "wb") 254 | f.write(pickle.dumps(lb)) 255 | f.close() -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # ACCIDetect ![CI status](https://img.shields.io/badge/build-passing-brightgreen.svg) 3 |

AI based accident detection system

4 |

The problem

5 | According to a data, around one and a half lakh persons die due to road accidents per year in India alone . 30-40% of these road accidents goes unnoticed or neglected by the general public to avoid the unwanted enquiry that can cost lives of several people. 6 | 7 | The delay in the response time to these accidents leads to delayed arrival of ambulance or fire brigade to the spot. In these critical situations every second counts for the life. 8 | 9 | There is not any concrete step to stop the loss of lives due to such road accidents. 10 | 11 | ### Solution to the Problem 12 | 13 | Most of these deaths are avoidable. Then the million-dollar question is, “what can we do to avoid it”? 14 | The idea is to use the CCTV cameras on the road to detect the road accident and then if it suspects an accident or the chance of occurrence of accident then it generates a signal and informs it to the nearest available services like ambulance, fire brigade and police station. 15 | Now, comes the question on the availability of cctv cameras. 16 | Delhi reporting highest no. of road accidents (1591) has 100 cameras at present to monitor the speed limit. These cameras can be used to monitor the occurrence of accident. 17 | Chennai records the highest no. of accidents. Third Eye campaign in Chennai has installed 34,293 cameras to monitor the speed activities which can be deployed for accident detection as well. 18 | Bengaluru has also put 5000 surveillance cameras on the road. 19 | 20 | 21 | ## Technologies Used 22 | 23 | * **TensorFlow** 24 | * **Keras** 25 | * **OpenCv** 26 | * **pickle** 27 | * **twilio** 28 | * **scikitlearn** 29 | * **matplotlib** 30 | 31 | 32 | ### Demo 33 | * Video Demo is availabe [here](https://drive.google.com/file/d/19Rb5UcmBkM2XKab2V27iBjIcmnjz_pZ7) 34 | * Pictures
35 | ![](https://github.com/hackabit19/DevSena/blob/master/a1.jpeg)| 36 | ![](https://github.com/hackabit19/DevSena/blob/master/a2.jpeg)
37 | 38 | 39 | 40 | 41 | ### Requirements 42 | For Lite Version of the Model 43 | * Android 5.0 and higher 44 | [Get the app here](https://drive.google.com/open?id=1iX9ZJTzbCB1mx9bGShA4z5vFhw3FFkzT) 45 | 46 | 47 | ## WorkFlow 48 | * We have designed a Deep Learning Neural Network which will feed on real time video captured through cctv cameras installed at accidents prone part of the city. The algorithm was trained on accident images from kaggle 49 | * The first step after obtaining images was to pre process the image into a vector containing RGB values. The values obtained were normalized to avoid biases among features 50 | * The model uses RESnet as a deep learning neural network to obtain a higher accuracy in predicting the possibility of an accident. In this step the image is convoluted, spooled and fed into layers of neural network. 51 | * The model then predicts probability of accident for each frame of video and if the value reaches the threshold it sends a text message to the nearest police station, hospital. 52 | 53 | 54 | 55 | 56 | ## Contributing 57 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 58 | Please make sure to update tests as appropriate. 59 | 60 | ## The Team 61 | * [Abhinav Jha](https://github.com/aBITnav) 62 | * [Nizdain Ahmed](https://github.com/nizd) 63 | * [Shubham Jha](https://github.com/shubhamjha15) 64 | * [Sanket Agarwal](https://github.com/xterm-hackslash) 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /a1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackabit19/DevSena/3a1bed96db0ad4cb326af1845fdc1d339a43e34f/a1.jpeg -------------------------------------------------------------------------------- /a2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackabit19/DevSena/3a1bed96db0ad4cb326af1845fdc1d339a43e34f/a2.jpeg -------------------------------------------------------------------------------- /final.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackabit19/DevSena/3a1bed96db0ad4cb326af1845fdc1d339a43e34f/final.mp4 -------------------------------------------------------------------------------- /hack/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /hack/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.hackabit; 2 | 3 | import android.content.Intent; 4 | import android.database.Cursor; 5 | import android.graphics.Bitmap; 6 | import android.graphics.BitmapFactory; 7 | import android.net.Uri; 8 | import android.os.Bundle; 9 | import android.provider.MediaStore; 10 | import android.text.method.ScrollingMovementMethod; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.ImageView; 14 | import android.widget.TextView; 15 | 16 | import androidx.appcompat.app.AppCompatActivity; 17 | 18 | import com.wonderkiln.camerakit.CameraKitError; 19 | import com.wonderkiln.camerakit.CameraKitEvent; 20 | import com.wonderkiln.camerakit.CameraKitEventListener; 21 | import com.wonderkiln.camerakit.CameraKitImage; 22 | import com.wonderkiln.camerakit.CameraKitVideo; 23 | import com.wonderkiln.camerakit.CameraView; 24 | 25 | import java.io.IOException; 26 | import java.util.List; 27 | import java.util.concurrent.Executor; 28 | import java.util.concurrent.Executors; 29 | 30 | public class MainActivity extends AppCompatActivity { 31 | 32 | private static final int INPUT_SIZE = 300; 33 | //private static final String INPUT_NAME = "input"; 34 | private static final String INPUT_NAME = "image_tensor"; 35 | //private static final String OUTPUT_NAME = "output"; 36 | private static final String OUTPUT_NAME = "detection_boxes,detection_scores,detection_classes,num_detections"; 37 | //private static final String OUTPUT_NAME = "detection_classes:0"; 38 | 39 | private static final String MODEL_FILE = "file:///android_asset/frozen_inference_graph.pb"; 40 | private static final String LABEL_FILE = "file:///android_asset/label_strings.txt"; 41 | 42 | private Classifier classifier; 43 | private Executor executor = Executors.newSingleThreadExecutor(); 44 | private TextView textViewResult; 45 | private Button btnDetectObject,btnDetectObject2; 46 | private ImageView imageViewResult; 47 | private CameraView cameraView; 48 | private Uri file; 49 | private int requestCode; 50 | private int resultCode; 51 | 52 | @Override 53 | protected void onCreate(Bundle savedInstanceState) { 54 | super.onCreate(savedInstanceState); 55 | setContentView(R.layout.activity_main); 56 | cameraView = (CameraView) findViewById(R.id.cameraView); 57 | imageViewResult = (ImageView) findViewById(R.id.imageViewResult); 58 | textViewResult = (TextView) findViewById(R.id.textViewResult); 59 | textViewResult.setMovementMethod(new ScrollingMovementMethod()); 60 | 61 | btnDetectObject = (Button) findViewById(R.id.btnDetectObject); 62 | btnDetectObject2 = (Button) findViewById(R.id.btnDetectObject2); 63 | 64 | cameraView.addCameraKitListener(new CameraKitEventListener() { 65 | @Override 66 | public void onEvent(CameraKitEvent cameraKitEvent) { 67 | 68 | } 69 | 70 | @Override 71 | public void onError(CameraKitError cameraKitError) { 72 | 73 | } 74 | 75 | @Override 76 | public void onImage(CameraKitImage cameraKitImage) { 77 | 78 | Bitmap bitmap = cameraKitImage.getBitmap(); 79 | 80 | bitmap = Bitmap.createScaledBitmap(bitmap, INPUT_SIZE, INPUT_SIZE, false); 81 | 82 | final List results = classifier.recognizeImage(bitmap); 83 | 84 | imageViewResult.setImageBitmap(bitmap); 85 | 86 | textViewResult.setText(results.toString()); 87 | } 88 | 89 | @Override 90 | public void onVideo(CameraKitVideo cameraKitVideo) { 91 | 92 | } 93 | }); 94 | btnDetectObject.setOnClickListener(new View.OnClickListener() { 95 | @Override 96 | public void onClick(View v) { 97 | cameraView.captureImage(); 98 | } 99 | }); 100 | btnDetectObject2.setOnClickListener(new View.OnClickListener() { 101 | @Override 102 | public void onClick(View v) { 103 | Intent i = new Intent( 104 | Intent.ACTION_PICK, 105 | android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 106 | startActivityForResult(i, 1); 107 | } 108 | }); 109 | 110 | 111 | 112 | 113 | initTensorFlowAndLoadModel(); 114 | 115 | 116 | } 117 | @Override 118 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 119 | super.onActivityResult(requestCode, resultCode, data); 120 | 121 | if (requestCode == 1 && resultCode == RESULT_OK && null != data) { 122 | Uri selectedImage = data.getData(); 123 | String[] filePathColumn = { MediaStore.Images.Media.DATA }; 124 | 125 | Cursor cursor = getContentResolver().query(selectedImage, 126 | filePathColumn, null, null, null); 127 | cursor.moveToFirst(); 128 | 129 | int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 130 | String picturePath = cursor.getString(columnIndex); 131 | cursor.close(); 132 | 133 | Bitmap bitmap = BitmapFactory.decodeFile(picturePath); 134 | 135 | bitmap = Bitmap.createScaledBitmap(bitmap, INPUT_SIZE, INPUT_SIZE, false); 136 | 137 | final List results = classifier.recognizeImage(bitmap); 138 | 139 | imageViewResult.setImageBitmap(bitmap); 140 | 141 | textViewResult.setText(results.toString()); 142 | 143 | initTensorFlowAndLoadModel(); 144 | 145 | 146 | } 147 | 148 | 149 | 150 | 151 | } 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | @Override 165 | protected void onResume() { 166 | super.onResume(); 167 | cameraView.start(); 168 | } 169 | 170 | @Override 171 | protected void onPause() { 172 | cameraView.stop(); 173 | super.onPause(); 174 | } 175 | 176 | @Override 177 | protected void onDestroy() { 178 | super.onDestroy(); 179 | executor.execute(new Runnable() { 180 | @Override 181 | public void run() { 182 | classifier.close(); 183 | } 184 | }); 185 | } 186 | 187 | private void initTensorFlowAndLoadModel() { 188 | executor.execute(new Runnable() { 189 | @Override 190 | public void run() { 191 | try { 192 | classifier = TensorFlowImageClassifier.create( 193 | getAssets(), 194 | MODEL_FILE, 195 | LABEL_FILE, 196 | INPUT_SIZE, 197 | INPUT_NAME, 198 | OUTPUT_NAME); 199 | makeButtonVisible(); 200 | } catch (final Exception e) { 201 | throw new RuntimeException("Error initializing TensorFlow!", e); 202 | } 203 | } 204 | }); 205 | } 206 | 207 | private void makeButtonVisible() { 208 | runOnUiThread(new Runnable() { 209 | @Override 210 | public void run() { 211 | btnDetectObject.setVisibility(View.VISIBLE); 212 | } 213 | }); 214 | } 215 | } -------------------------------------------------------------------------------- /hack/assets/frozen_inference_graph.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackabit19/DevSena/3a1bed96db0ad4cb326af1845fdc1d339a43e34f/hack/assets/frozen_inference_graph.pb -------------------------------------------------------------------------------- /hack/assets/label_strings.txt: -------------------------------------------------------------------------------- 1 | ??? 2 | car accident -------------------------------------------------------------------------------- /hack/java/com/example/hackabit/Classifier.java: -------------------------------------------------------------------------------- 1 | package com.example.hackabit; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.RectF; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Generic interface for interacting with different recognition engines. 10 | */ 11 | public interface Classifier { 12 | /** 13 | * An immutable result returned by a Classifier describing what was recognized. 14 | */ 15 | public class Recognition { 16 | /** 17 | * A unique identifier for what has been recognized. Specific to the class, not the instance of 18 | * the object. 19 | */ 20 | private final String id; 21 | 22 | /** 23 | * Display name for the recognition. 24 | */ 25 | private final String title; 26 | 27 | /** 28 | * A sortable score for how good the recognition is relative to others. Higher should be better. 29 | */ 30 | private final Float confidence; 31 | 32 | /** 33 | * Optional location within the source image for the location of the recognized object. 34 | */ 35 | private RectF location; 36 | 37 | public Recognition( 38 | final String id, final String title, final Float confidence, final RectF location) { 39 | this.id = id; 40 | this.title = title; 41 | this.confidence = confidence; 42 | this.location = location; 43 | } 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public String getTitle() { 50 | return title; 51 | } 52 | 53 | public Float getConfidence() { 54 | return confidence; 55 | } 56 | 57 | public RectF getLocation() { 58 | return new RectF(location); 59 | } 60 | 61 | public void setLocation(RectF location) { 62 | this.location = location; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | String resultString = ""; 68 | if (id != null) { 69 | resultString += "[" + id + "] "; 70 | } 71 | 72 | if (title != null) { 73 | resultString += title + " "; 74 | } 75 | 76 | if (confidence != null) { 77 | resultString += String.format("(%.1f%%) ", confidence * 100.0f); 78 | } 79 | 80 | if (location != null) { 81 | resultString += location + " "; 82 | } 83 | 84 | return resultString.trim(); 85 | } 86 | } 87 | 88 | List recognizeImage(Bitmap bitmap); 89 | 90 | void enableStatLogging(final boolean debug); 91 | 92 | String getStatString(); 93 | 94 | void close(); 95 | } 96 | 97 | -------------------------------------------------------------------------------- /hack/java/com/example/hackabit/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.hackabit; 2 | 3 | import android.graphics.Bitmap; 4 | import android.os.Bundle; 5 | import android.text.method.ScrollingMovementMethod; 6 | import android.view.View; 7 | import android.widget.Button; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import androidx.appcompat.app.AppCompatActivity; 12 | 13 | import com.wonderkiln.camerakit.CameraKitError; 14 | import com.wonderkiln.camerakit.CameraKitEvent; 15 | import com.wonderkiln.camerakit.CameraKitEventListener; 16 | import com.wonderkiln.camerakit.CameraKitImage; 17 | import com.wonderkiln.camerakit.CameraKitVideo; 18 | import com.wonderkiln.camerakit.CameraView; 19 | 20 | import java.util.List; 21 | import java.util.concurrent.Executor; 22 | import java.util.concurrent.Executors; 23 | 24 | public class MainActivity extends AppCompatActivity { 25 | 26 | private static final int INPUT_SIZE = 300; 27 | //private static final String INPUT_NAME = "input"; 28 | private static final String INPUT_NAME = "image_tensor"; 29 | //private static final String OUTPUT_NAME = "output"; 30 | private static final String OUTPUT_NAME = "detection_boxes,detection_scores,detection_classes,num_detections"; 31 | //private static final String OUTPUT_NAME = "detection_classes:0"; 32 | 33 | private static final String MODEL_FILE = "file:///android_asset/frozen_inference_graph.pb"; 34 | private static final String LABEL_FILE = "file:///android_asset/label_strings.txt"; 35 | 36 | private Classifier classifier; 37 | private Executor executor = Executors.newSingleThreadExecutor(); 38 | private TextView textViewResult; 39 | private Button btnDetectObject,btnDetectObject2; 40 | private ImageView imageViewResult; 41 | private CameraView cameraView; 42 | 43 | @Override 44 | protected void onCreate(Bundle savedInstanceState) { 45 | super.onCreate(savedInstanceState); 46 | setContentView(R.layout.activity_main); 47 | cameraView = (CameraView) findViewById(R.id.cameraView); 48 | imageViewResult = (ImageView) findViewById(R.id.imageViewResult); 49 | textViewResult = (TextView) findViewById(R.id.textViewResult); 50 | textViewResult.setMovementMethod(new ScrollingMovementMethod()); 51 | 52 | btnDetectObject = (Button) findViewById(R.id.btnDetectObject); 53 | 54 | cameraView.addCameraKitListener(new CameraKitEventListener() { 55 | @Override 56 | public void onEvent(CameraKitEvent cameraKitEvent) { 57 | 58 | } 59 | 60 | @Override 61 | public void onError(CameraKitError cameraKitError) { 62 | 63 | } 64 | 65 | @Override 66 | public void onImage(CameraKitImage cameraKitImage) { 67 | 68 | Bitmap bitmap = cameraKitImage.getBitmap(); 69 | 70 | bitmap = Bitmap.createScaledBitmap(bitmap, INPUT_SIZE, INPUT_SIZE, false); 71 | 72 | final List results = classifier.recognizeImage(bitmap); 73 | 74 | imageViewResult.setImageBitmap(bitmap); 75 | 76 | textViewResult.setText(results.toString()); 77 | } 78 | 79 | @Override 80 | public void onVideo(CameraKitVideo cameraKitVideo) { 81 | 82 | } 83 | }); 84 | 85 | btnDetectObject.setOnClickListener(new View.OnClickListener() { 86 | @Override 87 | public void onClick(View v) { 88 | cameraView.captureImage(); 89 | 90 | initTensorFlowAndLoadModel(); 91 | } 92 | }); 93 | /*btnDetectObject.setOnClickListener(new View.OnClickListener() { 94 | @Override 95 | public void onClick(View v) { 96 | Handler handler = new Handler(); 97 | int i=10000; 98 | while(i>0){ 99 | handler.postDelayed(new Runnable() { 100 | @Override 101 | public void run() { 102 | cameraView.captureImage(); 103 | initTensorFlowAndLoadModel(); 104 | } 105 | }, 200); 106 | i--; 107 | 108 | } 109 | } 110 | });*/ 111 | 112 | } 113 | 114 | @Override 115 | protected void onResume() { 116 | super.onResume(); 117 | cameraView.start(); 118 | } 119 | 120 | @Override 121 | protected void onPause() { 122 | cameraView.stop(); 123 | super.onPause(); 124 | } 125 | 126 | @Override 127 | protected void onDestroy() { 128 | super.onDestroy(); 129 | executor.execute(new Runnable() { 130 | @Override 131 | public void run() { 132 | classifier.close(); 133 | } 134 | }); 135 | } 136 | 137 | private void initTensorFlowAndLoadModel() { 138 | executor.execute(new Runnable() { 139 | @Override 140 | public void run() { 141 | try { 142 | classifier = TensorFlowImageClassifier.create( 143 | getAssets(), 144 | MODEL_FILE, 145 | LABEL_FILE, 146 | INPUT_SIZE, 147 | INPUT_NAME, 148 | OUTPUT_NAME); 149 | makeButtonVisible(); 150 | } catch (final Exception e) { 151 | throw new RuntimeException("Error initializing TensorFlow!", e); 152 | } 153 | } 154 | }); 155 | } 156 | 157 | private void makeButtonVisible() { 158 | runOnUiThread(new Runnable() { 159 | @Override 160 | public void run() { 161 | btnDetectObject.setVisibility(View.VISIBLE); 162 | } 163 | }); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /hack/java/com/example/hackabit/TensorFlowImageClassifier.java: -------------------------------------------------------------------------------- 1 | package com.example.hackabit; 2 | 3 | import android.content.res.AssetManager; 4 | import android.graphics.Bitmap; 5 | 6 | import org.tensorflow.contrib.android.TensorFlowInferenceInterface; 7 | 8 | import java.io.BufferedReader; 9 | import java.io.IOException; 10 | import java.io.InputStreamReader; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import java.util.Vector; 14 | 15 | /** 16 | * A classifier specialized to label images using TensorFlow. 17 | */ 18 | public class TensorFlowImageClassifier implements Classifier { 19 | 20 | // Only return this many results with at least this confidence. 21 | private static final int MAX_RESULTS = 3; 22 | private static final float THRESHOLD = 0.6f; //Return results >= 60% 23 | 24 | // Config values. 25 | private String inputName; 26 | private String outputName; 27 | private int inputSize; 28 | private int imageMean; 29 | private float imageStd; 30 | 31 | // Pre-allocated buffers. 32 | private Vector labels = new Vector(); 33 | private int[] intValues; 34 | private byte[] bytesValues; 35 | private float[] outputs; 36 | private float[] output_classes; 37 | private String[] outputNames; 38 | 39 | private TensorFlowInferenceInterface inferenceInterface; 40 | 41 | private boolean runStats = false; 42 | 43 | private TensorFlowImageClassifier() { 44 | } 45 | 46 | /** 47 | * Initializes a native TensorFlow session for classifying images. 48 | * 49 | * @param assetManager The asset manager to be used to load assets. 50 | * @param modelFilename The filepath of the model GraphDef protocol buffer. 51 | * @param labelFilename The filepath of label file for classes. 52 | * @param inputSize The input size. A square image of inputSize x inputSize is assumed. 53 | * @param inputName The label of the image input node. 54 | * @param outputName The label of the output node. 55 | * @throws IOException 56 | */ 57 | public static Classifier create( 58 | AssetManager assetManager, 59 | String modelFilename, 60 | String labelFilename, 61 | int inputSize, 62 | String inputName, 63 | String outputName) 64 | throws IOException { 65 | TensorFlowImageClassifier c = new TensorFlowImageClassifier(); 66 | c.inputName = inputName; 67 | c.outputName = outputName; 68 | 69 | // Read the label names into memory. 70 | // TODO(andrewharp): make this handle non-assets. 71 | String actualFilename = labelFilename.split("file:///android_asset/")[1]; 72 | 73 | BufferedReader br = new BufferedReader(new InputStreamReader(assetManager.open(actualFilename))); 74 | 75 | String line; 76 | while ((line = br.readLine()) != null) { 77 | c.labels.add(line); 78 | } 79 | 80 | br.close(); 81 | 82 | c.inferenceInterface = new TensorFlowInferenceInterface(assetManager, modelFilename); 83 | // The shape of the output is [N, NUM_CLASSES], where N is the batch size. 84 | //int numClasses = (int) c.inferenceInterface.graph().operation(outputName).output(0).shape().size(1); 85 | //int numClasses = (int) c.inferenceInterface.graph().operation("detection_classes").output(0).shape().size(1); 86 | int numClasses = 1; 87 | 88 | // Ideally, inputSize could have been retrieved from the shape of the input operation. Alas, 89 | // the placeholder node for input in the graphdef typically used does not specify a shape, so it 90 | // must be passed in as a parameter. 91 | c.inputSize = inputSize; 92 | 93 | // Pre-allocate buffers. 94 | //c.outputNames = new String[]{"detection_boxes","detection_scores","detection_classes","num_detections"}; 95 | c.outputNames = new String[]{"detection_scores","detection_classes"}; 96 | c.intValues = new int[inputSize * inputSize]; 97 | c.bytesValues = new byte[inputSize * inputSize * 3]; 98 | //c.outputs = new float[numClasses]; 99 | c.outputs = new float[20]; 100 | c.output_classes = new float[20]; 101 | 102 | return c; 103 | } 104 | 105 | @Override 106 | public List recognizeImage(final Bitmap bitmap) { 107 | // Preprocess the image data from 0-255 int to normalized float based 108 | // on the provided parameters. 109 | bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); 110 | 111 | for (int i = 0; i < intValues.length; ++i) { 112 | final int val = intValues[i]; 113 | bytesValues[i * 3] = (byte) ((val >> 16) & 0xFF); 114 | bytesValues[i * 3 + 1] = (byte) ((val >> 8) & 0xFF); 115 | bytesValues[i * 3 + 2] = (byte) (val & 0xFF); 116 | } 117 | 118 | // Copy the input data into TensorFlow. 119 | inferenceInterface.feed(inputName, bytesValues, new long[]{1, inputSize, inputSize, 3}); 120 | 121 | // Run the inference call. 122 | inferenceInterface.run(outputNames, runStats); 123 | 124 | // Copy the output Tensor back into the output array. 125 | inferenceInterface.fetch("detection_scores", outputs); 126 | inferenceInterface.fetch("detection_classes", output_classes); 127 | 128 | // Find the best classifications. 129 | /*PriorityQueue pq = new PriorityQueue( 130 | 3, 131 | new Comparator() { 132 | @Override 133 | public int compare(Recognition lhs, Recognition rhs) { 134 | // Intentionally reversed to put high confidence at the head of the queue. 135 | return Float.compare(rhs.getConfidence(), lhs.getConfidence()); 136 | } 137 | });*/ 138 | final ArrayList recognitions = new ArrayList(); 139 | for (int i = 0; i < outputs.length; i++) { 140 | if (outputs[i] > THRESHOLD) { 141 | //pq.add(new Recognition("" + i, labels.size() > i ? labels.get(i) : "unknown", outputs[i], null)); 142 | recognitions.add(new Recognition("" + i, labels.get(Math.round(output_classes[i])), outputs[i], null)); 143 | } 144 | } 145 | /*int recognitionsSize = Math.min(pq.size(), MAX_RESULTS); 146 | for (int i = 0; i < recognitionsSize; ++i) { 147 | recognitions.add(pq.poll()); 148 | }*/ 149 | return recognitions; 150 | } 151 | 152 | @Override 153 | public void enableStatLogging(boolean debug) { 154 | runStats = debug; 155 | } 156 | 157 | @Override 158 | public String getStatString() { 159 | return inferenceInterface.getStatString(); 160 | } 161 | 162 | @Override 163 | public void close() { 164 | inferenceInterface.close(); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /hack/res/drawable/a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackabit19/DevSena/3a1bed96db0ad4cb326af1845fdc1d339a43e34f/hack/res/drawable/a.jpg -------------------------------------------------------------------------------- /hack/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /hack/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 21 | 22 | 35 | 36 | 37 | 43 | 44 |