{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "YOLO", "provenance": [], "collapsed_sections": [], "authorship_tag": "ABX9TyNMWnvxirmzkiHyJgiWE80A", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "DtFCxvOH-sBc", "colab_type": "text" }, "source": [ "# ***Image Classification Model using YOLO (You Only Look Once)***" ] }, { "cell_type": "markdown", "metadata": { "id": "60Vbc4kQBZin", "colab_type": "text" }, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n", " \"Yolo\"View on Yolo site\n", " \n", " Run in Google Colab\n", " \n", " View source on GitHub\n", " \n", " Download Yolo Weights\n", "
" ] }, { "cell_type": "code", "metadata": { "id": "u4nN351_Dd1Y", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 101 }, "outputId": "f7837351-cbd4-40f3-ba43-b11af3253b9f" }, "source": [ "!git clone https://github.com/pjreddie/darknet" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "Cloning into 'darknet'...\n", "remote: Enumerating objects: 5910, done.\u001b[K\n", "Receiving objects: 0% (1/5910) \rReceiving objects: 1% (60/5910) \rReceiving objects: 2% (119/5910) \rReceiving objects: 3% (178/5910) \rReceiving objects: 4% (237/5910) \rReceiving objects: 5% (296/5910) \rReceiving objects: 6% (355/5910) \rReceiving objects: 7% (414/5910) \rReceiving objects: 8% (473/5910) \rReceiving objects: 9% (532/5910) \rReceiving objects: 10% (591/5910) \rReceiving objects: 11% (651/5910) \rReceiving objects: 12% (710/5910) \rReceiving objects: 13% (769/5910) \rReceiving objects: 14% (828/5910) \rReceiving objects: 15% (887/5910) \rReceiving objects: 16% (946/5910) \rReceiving objects: 17% (1005/5910) \rReceiving objects: 18% (1064/5910) \rReceiving objects: 19% (1123/5910) \rReceiving objects: 20% (1182/5910) \rReceiving objects: 21% (1242/5910) \rReceiving objects: 22% (1301/5910) \rReceiving objects: 23% (1360/5910) \rReceiving objects: 24% (1419/5910) \rReceiving objects: 25% (1478/5910) \rReceiving objects: 26% (1537/5910) \rReceiving objects: 27% (1596/5910) \rReceiving objects: 28% (1655/5910) \rReceiving objects: 29% (1714/5910) \rReceiving objects: 30% (1773/5910) \rReceiving objects: 31% (1833/5910) \rReceiving objects: 32% (1892/5910) \rReceiving objects: 33% (1951/5910) \rReceiving objects: 34% (2010/5910) \rReceiving objects: 35% (2069/5910) \rReceiving objects: 36% (2128/5910) \rReceiving objects: 37% (2187/5910) \rReceiving objects: 38% (2246/5910) \rReceiving objects: 39% (2305/5910) \rReceiving objects: 40% (2364/5910) \rReceiving objects: 41% (2424/5910) \rReceiving objects: 42% (2483/5910) \rReceiving objects: 43% (2542/5910) \rReceiving objects: 44% (2601/5910) \rReceiving objects: 45% (2660/5910) \rReceiving objects: 46% (2719/5910) \rReceiving objects: 47% (2778/5910) \rReceiving objects: 48% (2837/5910) \rReceiving objects: 49% (2896/5910) \rReceiving objects: 50% (2955/5910) \rReceiving objects: 51% (3015/5910) \rReceiving objects: 52% (3074/5910) \rReceiving objects: 53% (3133/5910) \rReceiving objects: 54% (3192/5910) \rReceiving objects: 55% (3251/5910) \rReceiving objects: 56% (3310/5910) \rReceiving objects: 57% (3369/5910) \rReceiving objects: 58% (3428/5910) \rReceiving objects: 59% (3487/5910) \rReceiving objects: 60% (3546/5910) \rReceiving objects: 61% (3606/5910) \rReceiving objects: 62% (3665/5910) \rReceiving objects: 63% (3724/5910) \rReceiving objects: 64% (3783/5910) \rReceiving objects: 65% (3842/5910) \rReceiving objects: 66% (3901/5910) \rReceiving objects: 67% (3960/5910) \rReceiving objects: 68% (4019/5910) \rReceiving objects: 69% (4078/5910) \rReceiving objects: 70% (4137/5910) \rReceiving objects: 71% (4197/5910) \rReceiving objects: 72% (4256/5910) \rReceiving objects: 73% (4315/5910) \rReceiving objects: 74% (4374/5910) \rReceiving objects: 75% (4433/5910) \rReceiving objects: 76% (4492/5910) \rReceiving objects: 77% (4551/5910) \rReceiving objects: 78% (4610/5910) \rReceiving objects: 79% (4669/5910) \rReceiving objects: 80% (4728/5910) \rReceiving objects: 81% (4788/5910) \rReceiving objects: 82% (4847/5910) \rReceiving objects: 83% (4906/5910) \rReceiving objects: 84% (4965/5910) \rReceiving objects: 85% (5024/5910) \rReceiving objects: 86% (5083/5910) \rReceiving objects: 87% (5142/5910) \rReceiving objects: 88% (5201/5910) \rReceiving objects: 89% (5260/5910) \rReceiving objects: 90% (5319/5910) \rReceiving objects: 91% (5379/5910) \rReceiving objects: 92% (5438/5910) \rReceiving objects: 93% (5497/5910) \rReceiving objects: 94% (5556/5910) \rReceiving objects: 95% (5615/5910) \rReceiving objects: 96% (5674/5910) \rReceiving objects: 97% (5733/5910) \rReceiving objects: 98% (5792/5910) \rReceiving objects: 99% (5851/5910) \rremote: Total 5910 (delta 0), reused 0 (delta 0), pack-reused 5910\u001b[K\n", "Receiving objects: 100% (5910/5910), 6.33 MiB | 22.21 MiB/s, done.\n", "Resolving deltas: 100% (3917/3917), done.\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "AyORTrBXjoN4", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "50f77431-fc02-4127-d2be-02edb0af2cd7" }, "source": [ "cd darknet" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "/content/darknet\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "C2mBT1ikjzoV", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "outputId": "4a9ca164-a5c1-4d2a-fe54-7decccd03351" }, "source": [ "!make" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "mkdir -p obj\n", "mkdir -p backup\n", "mkdir -p results\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/gemm.c -o obj/gemm.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/utils.c -o obj/utils.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/cuda.c -o obj/cuda.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/deconvolutional_layer.c -o obj/deconvolutional_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/convolutional_layer.c -o obj/convolutional_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/list.c -o obj/list.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/image.c -o obj/image.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/activations.c -o obj/activations.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/im2col.c -o obj/im2col.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/col2im.c -o obj/col2im.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/blas.c -o obj/blas.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/crop_layer.c -o obj/crop_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/dropout_layer.c -o obj/dropout_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/maxpool_layer.c -o obj/maxpool_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/softmax_layer.c -o obj/softmax_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/data.c -o obj/data.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/matrix.c -o obj/matrix.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/network.c -o obj/network.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/connected_layer.c -o obj/connected_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/cost_layer.c -o obj/cost_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/parser.c -o obj/parser.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/option_list.c -o obj/option_list.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/detection_layer.c -o obj/detection_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/route_layer.c -o obj/route_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/upsample_layer.c -o obj/upsample_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/box.c -o obj/box.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/normalization_layer.c -o obj/normalization_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/avgpool_layer.c -o obj/avgpool_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/layer.c -o obj/layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/local_layer.c -o obj/local_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/shortcut_layer.c -o obj/shortcut_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/logistic_layer.c -o obj/logistic_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/activation_layer.c -o obj/activation_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/rnn_layer.c -o obj/rnn_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/gru_layer.c -o obj/gru_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/crnn_layer.c -o obj/crnn_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/demo.c -o obj/demo.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/batchnorm_layer.c -o obj/batchnorm_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/region_layer.c -o obj/region_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/reorg_layer.c -o obj/reorg_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/tree.c -o obj/tree.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/lstm_layer.c -o obj/lstm_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/l2norm_layer.c -o obj/l2norm_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/yolo_layer.c -o obj/yolo_layer.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/iseg_layer.c -o obj/iseg_layer.o\n", "g++ -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./src/image_opencv.cpp -o obj/image_opencv.o\n", "gcc -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -shared obj/gemm.o obj/utils.o obj/cuda.o obj/deconvolutional_layer.o obj/convolutional_layer.o obj/list.o obj/image.o obj/activations.o obj/im2col.o obj/col2im.o obj/blas.o obj/crop_layer.o obj/dropout_layer.o obj/maxpool_layer.o obj/softmax_layer.o obj/data.o obj/matrix.o obj/network.o obj/connected_layer.o obj/cost_layer.o obj/parser.o obj/option_list.o obj/detection_layer.o obj/route_layer.o obj/upsample_layer.o obj/box.o obj/normalization_layer.o obj/avgpool_layer.o obj/layer.o obj/local_layer.o obj/shortcut_layer.o obj/logistic_layer.o obj/activation_layer.o obj/rnn_layer.o obj/gru_layer.o obj/crnn_layer.o obj/demo.o obj/batchnorm_layer.o obj/region_layer.o obj/reorg_layer.o obj/tree.o obj/lstm_layer.o obj/l2norm_layer.o obj/yolo_layer.o obj/iseg_layer.o obj/image_opencv.o -o libdarknet.so -lm -pthread \n", "ar rcs libdarknet.a obj/gemm.o obj/utils.o obj/cuda.o obj/deconvolutional_layer.o obj/convolutional_layer.o obj/list.o obj/image.o obj/activations.o obj/im2col.o obj/col2im.o obj/blas.o obj/crop_layer.o obj/dropout_layer.o obj/maxpool_layer.o obj/softmax_layer.o obj/data.o obj/matrix.o obj/network.o obj/connected_layer.o obj/cost_layer.o obj/parser.o obj/option_list.o obj/detection_layer.o obj/route_layer.o obj/upsample_layer.o obj/box.o obj/normalization_layer.o obj/avgpool_layer.o obj/layer.o obj/local_layer.o obj/shortcut_layer.o obj/logistic_layer.o obj/activation_layer.o obj/rnn_layer.o obj/gru_layer.o obj/crnn_layer.o obj/demo.o obj/batchnorm_layer.o obj/region_layer.o obj/reorg_layer.o obj/tree.o obj/lstm_layer.o obj/l2norm_layer.o obj/yolo_layer.o obj/iseg_layer.o obj/image_opencv.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/captcha.c -o obj/captcha.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/lsd.c -o obj/lsd.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/super.c -o obj/super.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/art.c -o obj/art.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/tag.c -o obj/tag.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/cifar.c -o obj/cifar.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/go.c -o obj/go.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/rnn.c -o obj/rnn.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/segmenter.c -o obj/segmenter.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/regressor.c -o obj/regressor.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/classifier.c -o obj/classifier.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/coco.c -o obj/coco.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/yolo.c -o obj/yolo.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/detector.c -o obj/detector.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/nightmare.c -o obj/nightmare.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/instance-segmenter.c -o obj/instance-segmenter.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -c ./examples/darknet.c -o obj/darknet.o\n", "gcc -Iinclude/ -Isrc/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast obj/captcha.o obj/lsd.o obj/super.o obj/art.o obj/tag.o obj/cifar.o obj/go.o obj/rnn.o obj/segmenter.o obj/regressor.o obj/classifier.o obj/coco.o obj/yolo.o obj/detector.o obj/nightmare.o obj/instance-segmenter.o obj/darknet.o libdarknet.a -o darknet -lm -pthread libdarknet.a\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "Au1pG27cj1V8", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 202 }, "outputId": "b22d59cb-de9b-4345-eaaf-fba35654150c" }, "source": [ "!wget https://pjreddie.com/media/files/yolov3.weights" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "--2020-08-13 06:44:29-- https://pjreddie.com/media/files/yolov3.weights\n", "Resolving pjreddie.com (pjreddie.com)... 128.208.4.108\n", "Connecting to pjreddie.com (pjreddie.com)|128.208.4.108|:443... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: 248007048 (237M) [application/octet-stream]\n", "Saving to: ‘yolov3.weights’\n", "\n", "yolov3.weights 100%[===================>] 236.52M 399KB/s in 9m 8s \n", "\n", "2020-08-13 06:53:39 (442 KB/s) - ‘yolov3.weights’ saved [248007048/248007048]\n", "\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "ys7UffvEkA9T", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "outputId": "3ae7f057-e6e3-4167-b0e1-c817f278a63a" }, "source": [ "!./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "layer filters size input output\n", " 0 conv 32 3 x 3 / 1 608 x 608 x 3 -> 608 x 608 x 32 0.639 BFLOPs\n", " 1 conv 64 3 x 3 / 2 608 x 608 x 32 -> 304 x 304 x 64 3.407 BFLOPs\n", " 2 conv 32 1 x 1 / 1 304 x 304 x 64 -> 304 x 304 x 32 0.379 BFLOPs\n", " 3 conv 64 3 x 3 / 1 304 x 304 x 32 -> 304 x 304 x 64 3.407 BFLOPs\n", " 4 res 1 304 x 304 x 64 -> 304 x 304 x 64\n", " 5 conv 128 3 x 3 / 2 304 x 304 x 64 -> 152 x 152 x 128 3.407 BFLOPs\n", " 6 conv 64 1 x 1 / 1 152 x 152 x 128 -> 152 x 152 x 64 0.379 BFLOPs\n", " 7 conv 128 3 x 3 / 1 152 x 152 x 64 -> 152 x 152 x 128 3.407 BFLOPs\n", " 8 res 5 152 x 152 x 128 -> 152 x 152 x 128\n", " 9 conv 64 1 x 1 / 1 152 x 152 x 128 -> 152 x 152 x 64 0.379 BFLOPs\n", " 10 conv 128 3 x 3 / 1 152 x 152 x 64 -> 152 x 152 x 128 3.407 BFLOPs\n", " 11 res 8 152 x 152 x 128 -> 152 x 152 x 128\n", " 12 conv 256 3 x 3 / 2 152 x 152 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 13 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 14 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 15 res 12 76 x 76 x 256 -> 76 x 76 x 256\n", " 16 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 17 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 18 res 15 76 x 76 x 256 -> 76 x 76 x 256\n", " 19 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 20 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 21 res 18 76 x 76 x 256 -> 76 x 76 x 256\n", " 22 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 23 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 24 res 21 76 x 76 x 256 -> 76 x 76 x 256\n", " 25 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 26 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 27 res 24 76 x 76 x 256 -> 76 x 76 x 256\n", " 28 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 29 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 30 res 27 76 x 76 x 256 -> 76 x 76 x 256\n", " 31 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 32 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 33 res 30 76 x 76 x 256 -> 76 x 76 x 256\n", " 34 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 35 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 36 res 33 76 x 76 x 256 -> 76 x 76 x 256\n", " 37 conv 512 3 x 3 / 2 76 x 76 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 38 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 39 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 40 res 37 38 x 38 x 512 -> 38 x 38 x 512\n", " 41 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 42 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 43 res 40 38 x 38 x 512 -> 38 x 38 x 512\n", " 44 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 45 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 46 res 43 38 x 38 x 512 -> 38 x 38 x 512\n", " 47 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 48 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 49 res 46 38 x 38 x 512 -> 38 x 38 x 512\n", " 50 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 51 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 52 res 49 38 x 38 x 512 -> 38 x 38 x 512\n", " 53 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 54 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 55 res 52 38 x 38 x 512 -> 38 x 38 x 512\n", " 56 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 57 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 58 res 55 38 x 38 x 512 -> 38 x 38 x 512\n", " 59 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 60 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 61 res 58 38 x 38 x 512 -> 38 x 38 x 512\n", " 62 conv 1024 3 x 3 / 2 38 x 38 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 63 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 64 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 65 res 62 19 x 19 x1024 -> 19 x 19 x1024\n", " 66 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 67 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 68 res 65 19 x 19 x1024 -> 19 x 19 x1024\n", " 69 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 70 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 71 res 68 19 x 19 x1024 -> 19 x 19 x1024\n", " 72 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 73 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 74 res 71 19 x 19 x1024 -> 19 x 19 x1024\n", " 75 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 76 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 77 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 78 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 79 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 80 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 81 conv 255 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 255 0.189 BFLOPs\n", " 82 yolo\n", " 83 route 79\n", " 84 conv 256 1 x 1 / 1 19 x 19 x 512 -> 19 x 19 x 256 0.095 BFLOPs\n", " 85 upsample 2x 19 x 19 x 256 -> 38 x 38 x 256\n", " 86 route 85 61\n", " 87 conv 256 1 x 1 / 1 38 x 38 x 768 -> 38 x 38 x 256 0.568 BFLOPs\n", " 88 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 89 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 90 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 91 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 92 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 93 conv 255 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 255 0.377 BFLOPs\n", " 94 yolo\n", " 95 route 91\n", " 96 conv 128 1 x 1 / 1 38 x 38 x 256 -> 38 x 38 x 128 0.095 BFLOPs\n", " 97 upsample 2x 38 x 38 x 128 -> 76 x 76 x 128\n", " 98 route 97 36\n", " 99 conv 128 1 x 1 / 1 76 x 76 x 384 -> 76 x 76 x 128 0.568 BFLOPs\n", " 100 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 101 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 102 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 103 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 104 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 105 conv 255 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 255 0.754 BFLOPs\n", " 106 yolo\n", "Loading weights from yolov3.weights...Done!\n", "data/dog.jpg: Predicted in 25.582477 seconds.\n", "dog: 100%\n", "truck: 92%\n", "bicycle: 99%\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "2B8cOa5PmK4C", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "outputId": "11cbce02-748a-4fc9-b99b-923c3a44faa4" }, "source": [ "!./darknet detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights data/dog.jpg" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "layer filters size input output\n", " 0 conv 32 3 x 3 / 1 608 x 608 x 3 -> 608 x 608 x 32 0.639 BFLOPs\n", " 1 conv 64 3 x 3 / 2 608 x 608 x 32 -> 304 x 304 x 64 3.407 BFLOPs\n", " 2 conv 32 1 x 1 / 1 304 x 304 x 64 -> 304 x 304 x 32 0.379 BFLOPs\n", " 3 conv 64 3 x 3 / 1 304 x 304 x 32 -> 304 x 304 x 64 3.407 BFLOPs\n", " 4 res 1 304 x 304 x 64 -> 304 x 304 x 64\n", " 5 conv 128 3 x 3 / 2 304 x 304 x 64 -> 152 x 152 x 128 3.407 BFLOPs\n", " 6 conv 64 1 x 1 / 1 152 x 152 x 128 -> 152 x 152 x 64 0.379 BFLOPs\n", " 7 conv 128 3 x 3 / 1 152 x 152 x 64 -> 152 x 152 x 128 3.407 BFLOPs\n", " 8 res 5 152 x 152 x 128 -> 152 x 152 x 128\n", " 9 conv 64 1 x 1 / 1 152 x 152 x 128 -> 152 x 152 x 64 0.379 BFLOPs\n", " 10 conv 128 3 x 3 / 1 152 x 152 x 64 -> 152 x 152 x 128 3.407 BFLOPs\n", " 11 res 8 152 x 152 x 128 -> 152 x 152 x 128\n", " 12 conv 256 3 x 3 / 2 152 x 152 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 13 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 14 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 15 res 12 76 x 76 x 256 -> 76 x 76 x 256\n", " 16 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 17 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 18 res 15 76 x 76 x 256 -> 76 x 76 x 256\n", " 19 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 20 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 21 res 18 76 x 76 x 256 -> 76 x 76 x 256\n", " 22 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 23 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 24 res 21 76 x 76 x 256 -> 76 x 76 x 256\n", " 25 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 26 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 27 res 24 76 x 76 x 256 -> 76 x 76 x 256\n", " 28 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 29 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 30 res 27 76 x 76 x 256 -> 76 x 76 x 256\n", " 31 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 32 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 33 res 30 76 x 76 x 256 -> 76 x 76 x 256\n", " 34 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 35 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 36 res 33 76 x 76 x 256 -> 76 x 76 x 256\n", " 37 conv 512 3 x 3 / 2 76 x 76 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 38 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 39 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 40 res 37 38 x 38 x 512 -> 38 x 38 x 512\n", " 41 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 42 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 43 res 40 38 x 38 x 512 -> 38 x 38 x 512\n", " 44 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 45 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 46 res 43 38 x 38 x 512 -> 38 x 38 x 512\n", " 47 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 48 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 49 res 46 38 x 38 x 512 -> 38 x 38 x 512\n", " 50 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 51 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 52 res 49 38 x 38 x 512 -> 38 x 38 x 512\n", " 53 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 54 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 55 res 52 38 x 38 x 512 -> 38 x 38 x 512\n", " 56 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 57 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 58 res 55 38 x 38 x 512 -> 38 x 38 x 512\n", " 59 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 60 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 61 res 58 38 x 38 x 512 -> 38 x 38 x 512\n", " 62 conv 1024 3 x 3 / 2 38 x 38 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 63 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 64 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 65 res 62 19 x 19 x1024 -> 19 x 19 x1024\n", " 66 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 67 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 68 res 65 19 x 19 x1024 -> 19 x 19 x1024\n", " 69 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 70 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 71 res 68 19 x 19 x1024 -> 19 x 19 x1024\n", " 72 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 73 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 74 res 71 19 x 19 x1024 -> 19 x 19 x1024\n", " 75 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 76 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 77 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 78 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 79 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BFLOPs\n", " 80 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BFLOPs\n", " 81 conv 255 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 255 0.189 BFLOPs\n", " 82 yolo\n", " 83 route 79\n", " 84 conv 256 1 x 1 / 1 19 x 19 x 512 -> 19 x 19 x 256 0.095 BFLOPs\n", " 85 upsample 2x 19 x 19 x 256 -> 38 x 38 x 256\n", " 86 route 85 61\n", " 87 conv 256 1 x 1 / 1 38 x 38 x 768 -> 38 x 38 x 256 0.568 BFLOPs\n", " 88 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 89 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 90 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 91 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BFLOPs\n", " 92 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BFLOPs\n", " 93 conv 255 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 255 0.377 BFLOPs\n", " 94 yolo\n", " 95 route 91\n", " 96 conv 128 1 x 1 / 1 38 x 38 x 256 -> 38 x 38 x 128 0.095 BFLOPs\n", " 97 upsample 2x 38 x 38 x 128 -> 76 x 76 x 128\n", " 98 route 97 36\n", " 99 conv 128 1 x 1 / 1 76 x 76 x 384 -> 76 x 76 x 128 0.568 BFLOPs\n", " 100 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 101 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 102 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 103 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs\n", " 104 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs\n", " 105 conv 255 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 255 0.754 BFLOPs\n", " 106 yolo\n", "Loading weights from yolov3.weights...Done!\n", "data/dog.jpg: Predicted in 26.292026 seconds.\n", "dog: 100%\n", "truck: 92%\n", "bicycle: 99%\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "Pg9mlruynfUb", "colab_type": "code", "colab": {} }, "source": [ "# !wget https://pjreddie.com/media/files/yolov3-tiny.weights" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "PqZWTkh4npag", "colab_type": "code", "colab": {} }, "source": [ "import numpy as np\n", "import cv2\n", "\n", "confidenceThreshold = 0.5\n", "NMSThreshold = 0.3\n", "\n", "modelConfiguration = '/content/darknet/cfg/yolov3.cfg'\n", "modelWeights = '/content/darknet/yolov3.weights'\n", "inputimage = '/content/darknet/data/dog.jpg'\n", "labelsPath = '/content/darknet/data/coco.names'\n" ], "execution_count": 1, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "yPlOj_WYwQqR", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "outputId": "0afbb8ee-3585-43d9-a947-128fdf71d1c5" }, "source": [ "labels = open(labelsPath).read().strip().split('\\n')\n", "labels" ], "execution_count": 2, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "['person',\n", " 'bicycle',\n", " 'car',\n", " 'motorbike',\n", " 'aeroplane',\n", " 'bus',\n", " 'train',\n", " 'truck',\n", " 'boat',\n", " 'traffic light',\n", " 'fire hydrant',\n", " 'stop sign',\n", " 'parking meter',\n", " 'bench',\n", " 'bird',\n", " 'cat',\n", " 'dog',\n", " 'horse',\n", " 'sheep',\n", " 'cow',\n", " 'elephant',\n", " 'bear',\n", " 'zebra',\n", " 'giraffe',\n", " 'backpack',\n", " 'umbrella',\n", " 'handbag',\n", " 'tie',\n", " 'suitcase',\n", " 'frisbee',\n", " 'skis',\n", " 'snowboard',\n", " 'sports ball',\n", " 'kite',\n", " 'baseball bat',\n", " 'baseball glove',\n", " 'skateboard',\n", " 'surfboard',\n", " 'tennis racket',\n", " 'bottle',\n", " 'wine glass',\n", " 'cup',\n", " 'fork',\n", " 'knife',\n", " 'spoon',\n", " 'bowl',\n", " 'banana',\n", " 'apple',\n", " 'sandwich',\n", " 'orange',\n", " 'broccoli',\n", " 'carrot',\n", " 'hot dog',\n", " 'pizza',\n", " 'donut',\n", " 'cake',\n", " 'chair',\n", " 'sofa',\n", " 'pottedplant',\n", " 'bed',\n", " 'diningtable',\n", " 'toilet',\n", " 'tvmonitor',\n", " 'laptop',\n", " 'mouse',\n", " 'remote',\n", " 'keyboard',\n", " 'cell phone',\n", " 'microwave',\n", " 'oven',\n", " 'toaster',\n", " 'sink',\n", " 'refrigerator',\n", " 'book',\n", " 'clock',\n", " 'vase',\n", " 'scissors',\n", " 'teddy bear',\n", " 'hair drier',\n", " 'toothbrush']" ] }, "metadata": { "tags": [] }, "execution_count": 2 } ] }, { "cell_type": "code", "metadata": { "id": "O_IKGfHuxUqY", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "outputId": "17f711a8-deaf-42f2-d7bc-b0b32f9681d8" }, "source": [ "np.random.seed(10)\n", "COLORS = np.random.randint(0, 255, size=(len(labels), 3), dtype=\"uint8\")\n", "COLORS" ], "execution_count": 3, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "array([[ 9, 69, 117],\n", " [197, 125, 156],\n", " [123, 76, 228],\n", " [ 79, 5, 15],\n", " [114, 157, 126],\n", " [ 64, 197, 54],\n", " [162, 113, 109],\n", " [105, 113, 123],\n", " [156, 177, 191],\n", " [156, 36, 248],\n", " [212, 217, 39],\n", " [158, 127, 221],\n", " [146, 84, 149],\n", " [240, 69, 140],\n", " [ 57, 157, 167],\n", " [113, 6, 113],\n", " [ 63, 180, 50],\n", " [250, 167, 142],\n", " [181, 8, 36],\n", " [178, 194, 73],\n", " [ 36, 252, 67],\n", " [ 0, 217, 74],\n", " [ 43, 234, 121],\n", " [123, 67, 40],\n", " [112, 157, 22],\n", " [246, 41, 127],\n", " [ 38, 164, 189],\n", " [115, 175, 115],\n", " [185, 14, 175],\n", " [ 16, 150, 17],\n", " [244, 100, 209],\n", " [ 12, 209, 239],\n", " [192, 2, 1],\n", " [139, 201, 8],\n", " [ 86, 54, 8],\n", " [ 31, 131, 88],\n", " [141, 12, 228],\n", " [107, 237, 7],\n", " [208, 122, 28],\n", " [184, 50, 62],\n", " [130, 206, 156],\n", " [ 33, 126, 214],\n", " [ 7, 200, 244],\n", " [196, 184, 100],\n", " [ 95, 171, 224],\n", " [206, 99, 184],\n", " [ 74, 177, 54],\n", " [ 57, 186, 179],\n", " [ 62, 243, 234],\n", " [ 54, 44, 119],\n", " [138, 77, 112],\n", " [238, 182, 197],\n", " [ 61, 167, 33],\n", " [ 13, 48, 228],\n", " [138, 243, 26],\n", " [230, 105, 153],\n", " [ 65, 101, 36],\n", " [126, 197, 90],\n", " [199, 141, 66],\n", " [147, 95, 92],\n", " [143, 122, 149],\n", " [ 86, 5, 148],\n", " [172, 30, 239],\n", " [192, 46, 158],\n", " [250, 27, 113],\n", " [ 89, 32, 122],\n", " [211, 140, 138],\n", " [ 27, 111, 65],\n", " [157, 251, 26],\n", " [ 31, 250, 37],\n", " [158, 57, 123],\n", " [152, 72, 36],\n", " [ 7, 93, 131],\n", " [ 27, 193, 200],\n", " [ 16, 18, 110],\n", " [128, 166, 93],\n", " [ 32, 115, 14],\n", " [ 77, 176, 221],\n", " [153, 150, 233],\n", " [244, 195, 151]], dtype=uint8)" ] }, "metadata": { "tags": [] }, "execution_count": 3 } ] }, { "cell_type": "code", "metadata": { "id": "55N3FwoHCMsl", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 840 }, "outputId": "c80c13df-ced0-4c9b-e684-523b3256efd5" }, "source": [ "net = cv2.dnn.readNetFromDarknet(modelConfiguration, modelWeights)\n", "image = cv2.imread(inputimage)\n", "(H, W) = image.shape[:2]\n", "\n", "net, image, (H, W)" ], "execution_count": 4, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "(, array([[[ 50, 58, 57],\n", " [ 51, 59, 58],\n", " [ 53, 61, 60],\n", " ...,\n", " [ 47, 89, 142],\n", " [ 41, 50, 88],\n", " [ 47, 71, 63]],\n", " \n", " [[ 51, 59, 58],\n", " [ 51, 59, 58],\n", " [ 52, 60, 59],\n", " ...,\n", " [ 37, 74, 124],\n", " [ 41, 50, 83],\n", " [ 46, 70, 58]],\n", " \n", " [[ 51, 59, 58],\n", " [ 51, 59, 58],\n", " [ 52, 60, 59],\n", " ...,\n", " [ 25, 54, 98],\n", " [ 48, 54, 77],\n", " [ 43, 62, 45]],\n", " \n", " ...,\n", " \n", " [[179, 168, 160],\n", " [179, 168, 160],\n", " [182, 171, 163],\n", " ...,\n", " [ 64, 64, 80],\n", " [ 36, 39, 53],\n", " [ 48, 53, 62]],\n", " \n", " [[180, 169, 161],\n", " [179, 168, 160],\n", " [175, 164, 156],\n", " ...,\n", " [ 61, 61, 79],\n", " [ 37, 40, 54],\n", " [ 52, 56, 67]],\n", " \n", " [[176, 165, 157],\n", " [178, 167, 159],\n", " [172, 161, 153],\n", " ...,\n", " [ 62, 62, 80],\n", " [ 33, 36, 50],\n", " [ 35, 39, 50]]], dtype=uint8), (576, 768))" ] }, "metadata": { "tags": [] }, "execution_count": 4 } ] }, { "cell_type": "code", "metadata": { "id": "-AdoJ9MoCWfF", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "outputId": "740c22e0-e231-4cd4-ef75-0eb2a959df5f" }, "source": [ "layerName = net.getLayerNames()\n", "layerName" ], "execution_count": 5, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "['conv_0',\n", " 'bn_0',\n", " 'relu_0',\n", " 'conv_1',\n", " 'bn_1',\n", " 'relu_1',\n", " 'conv_2',\n", " 'bn_2',\n", " 'relu_2',\n", " 'conv_3',\n", " 'bn_3',\n", " 'relu_3',\n", " 'shortcut_4',\n", " 'conv_5',\n", " 'bn_5',\n", " 'relu_5',\n", " 'conv_6',\n", " 'bn_6',\n", " 'relu_6',\n", " 'conv_7',\n", " 'bn_7',\n", " 'relu_7',\n", " 'shortcut_8',\n", " 'conv_9',\n", " 'bn_9',\n", " 'relu_9',\n", " 'conv_10',\n", " 'bn_10',\n", " 'relu_10',\n", " 'shortcut_11',\n", " 'conv_12',\n", " 'bn_12',\n", " 'relu_12',\n", " 'conv_13',\n", " 'bn_13',\n", " 'relu_13',\n", " 'conv_14',\n", " 'bn_14',\n", " 'relu_14',\n", " 'shortcut_15',\n", " 'conv_16',\n", " 'bn_16',\n", " 'relu_16',\n", " 'conv_17',\n", " 'bn_17',\n", " 'relu_17',\n", " 'shortcut_18',\n", " 'conv_19',\n", " 'bn_19',\n", " 'relu_19',\n", " 'conv_20',\n", " 'bn_20',\n", " 'relu_20',\n", " 'shortcut_21',\n", " 'conv_22',\n", " 'bn_22',\n", " 'relu_22',\n", " 'conv_23',\n", " 'bn_23',\n", " 'relu_23',\n", " 'shortcut_24',\n", " 'conv_25',\n", " 'bn_25',\n", " 'relu_25',\n", " 'conv_26',\n", " 'bn_26',\n", " 'relu_26',\n", " 'shortcut_27',\n", " 'conv_28',\n", " 'bn_28',\n", " 'relu_28',\n", " 'conv_29',\n", " 'bn_29',\n", " 'relu_29',\n", " 'shortcut_30',\n", " 'conv_31',\n", " 'bn_31',\n", " 'relu_31',\n", " 'conv_32',\n", " 'bn_32',\n", " 'relu_32',\n", " 'shortcut_33',\n", " 'conv_34',\n", " 'bn_34',\n", " 'relu_34',\n", " 'conv_35',\n", " 'bn_35',\n", " 'relu_35',\n", " 'shortcut_36',\n", " 'conv_37',\n", " 'bn_37',\n", " 'relu_37',\n", " 'conv_38',\n", " 'bn_38',\n", " 'relu_38',\n", " 'conv_39',\n", " 'bn_39',\n", " 'relu_39',\n", " 'shortcut_40',\n", " 'conv_41',\n", " 'bn_41',\n", " 'relu_41',\n", " 'conv_42',\n", " 'bn_42',\n", " 'relu_42',\n", " 'shortcut_43',\n", " 'conv_44',\n", " 'bn_44',\n", " 'relu_44',\n", " 'conv_45',\n", " 'bn_45',\n", " 'relu_45',\n", " 'shortcut_46',\n", " 'conv_47',\n", " 'bn_47',\n", " 'relu_47',\n", " 'conv_48',\n", " 'bn_48',\n", " 'relu_48',\n", " 'shortcut_49',\n", " 'conv_50',\n", " 'bn_50',\n", " 'relu_50',\n", " 'conv_51',\n", " 'bn_51',\n", " 'relu_51',\n", " 'shortcut_52',\n", " 'conv_53',\n", " 'bn_53',\n", " 'relu_53',\n", " 'conv_54',\n", " 'bn_54',\n", " 'relu_54',\n", " 'shortcut_55',\n", " 'conv_56',\n", " 'bn_56',\n", " 'relu_56',\n", " 'conv_57',\n", " 'bn_57',\n", " 'relu_57',\n", " 'shortcut_58',\n", " 'conv_59',\n", " 'bn_59',\n", " 'relu_59',\n", " 'conv_60',\n", " 'bn_60',\n", " 'relu_60',\n", " 'shortcut_61',\n", " 'conv_62',\n", " 'bn_62',\n", " 'relu_62',\n", " 'conv_63',\n", " 'bn_63',\n", " 'relu_63',\n", " 'conv_64',\n", " 'bn_64',\n", " 'relu_64',\n", " 'shortcut_65',\n", " 'conv_66',\n", " 'bn_66',\n", " 'relu_66',\n", " 'conv_67',\n", " 'bn_67',\n", " 'relu_67',\n", " 'shortcut_68',\n", " 'conv_69',\n", " 'bn_69',\n", " 'relu_69',\n", " 'conv_70',\n", " 'bn_70',\n", " 'relu_70',\n", " 'shortcut_71',\n", " 'conv_72',\n", " 'bn_72',\n", " 'relu_72',\n", " 'conv_73',\n", " 'bn_73',\n", " 'relu_73',\n", " 'shortcut_74',\n", " 'conv_75',\n", " 'bn_75',\n", " 'relu_75',\n", " 'conv_76',\n", " 'bn_76',\n", " 'relu_76',\n", " 'conv_77',\n", " 'bn_77',\n", " 'relu_77',\n", " 'conv_78',\n", " 'bn_78',\n", " 'relu_78',\n", " 'conv_79',\n", " 'bn_79',\n", " 'relu_79',\n", " 'conv_80',\n", " 'bn_80',\n", " 'relu_80',\n", " 'conv_81',\n", " 'permute_82',\n", " 'yolo_82',\n", " 'identity_83',\n", " 'conv_84',\n", " 'bn_84',\n", " 'relu_84',\n", " 'upsample_85',\n", " 'concat_86',\n", " 'conv_87',\n", " 'bn_87',\n", " 'relu_87',\n", " 'conv_88',\n", " 'bn_88',\n", " 'relu_88',\n", " 'conv_89',\n", " 'bn_89',\n", " 'relu_89',\n", " 'conv_90',\n", " 'bn_90',\n", " 'relu_90',\n", " 'conv_91',\n", " 'bn_91',\n", " 'relu_91',\n", " 'conv_92',\n", " 'bn_92',\n", " 'relu_92',\n", " 'conv_93',\n", " 'permute_94',\n", " 'yolo_94',\n", " 'identity_95',\n", " 'conv_96',\n", " 'bn_96',\n", " 'relu_96',\n", " 'upsample_97',\n", " 'concat_98',\n", " 'conv_99',\n", " 'bn_99',\n", " 'relu_99',\n", " 'conv_100',\n", " 'bn_100',\n", " 'relu_100',\n", " 'conv_101',\n", " 'bn_101',\n", " 'relu_101',\n", " 'conv_102',\n", " 'bn_102',\n", " 'relu_102',\n", " 'conv_103',\n", " 'bn_103',\n", " 'relu_103',\n", " 'conv_104',\n", " 'bn_104',\n", " 'relu_104',\n", " 'conv_105',\n", " 'permute_106',\n", " 'yolo_106']" ] }, "metadata": { "tags": [] }, "execution_count": 5 } ] }, { "cell_type": "code", "metadata": { "id": "35QWb-EfCbsk", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "2b744afd-4179-4954-de89-76619719b10e" }, "source": [ "layerName = [layerName[i[0] - 1] for i in net.getUnconnectedOutLayers()]\n", "layerName" ], "execution_count": 6, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "['yolo_82', 'yolo_94', 'yolo_106']" ] }, "metadata": { "tags": [] }, "execution_count": 6 } ] }, { "cell_type": "code", "metadata": { "id": "B0_0weqEChNK", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "outputId": "6978406a-ddb1-418e-eb29-8e2574f18b9f" }, "source": [ "blob = cv2.dnn.blobFromImage(image, 1 / 255.0, (416, 416), swapRB = True, crop = False)\n", "nb = net.setInput(blob)\n", "layersOutputs = net.forward(layerName)\n", "\n", "boxes = []\n", "confidences = []\n", "classIDs = []\n", "\n", "blob, nb, layersOutputs" ], "execution_count": 8, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "(array([[[[0.22352943, 0.23529413, 0.2392157 , ..., 0.76470596,\n", " 0.6117647 , 0.28235295],\n", " [0.227451 , 0.23137257, 0.2392157 , ..., 0.78823537,\n", " 0.5137255 , 0.24705884],\n", " [0.23137257, 0.23137257, 0.2392157 , ..., 0.79215693,\n", " 0.3803922 , 0.22352943],\n", " ...,\n", " [0.61960787, 0.6392157 , 0.6156863 , ..., 0.50980395,\n", " 0.40784317, 0.24313727],\n", " [0.627451 , 0.62352943, 0.6039216 , ..., 0.5137255 ,\n", " 0.3529412 , 0.23529413],\n", " [0.61960787, 0.6 , 0.6117647 , ..., 0.5019608 ,\n", " 0.3529412 , 0.20392159]],\n", " \n", " [[0.227451 , 0.2392157 , 0.24705884, ..., 0.9294118 ,\n", " 0.48235297, 0.24313727],\n", " [0.23137257, 0.23529413, 0.24313727, ..., 0.9294118 ,\n", " 0.3921569 , 0.23529413],\n", " [0.23529413, 0.23529413, 0.24313727, ..., 0.8980393 ,\n", " 0.27450982, 0.24313727],\n", " ...,\n", " [0.6509804 , 0.67058825, 0.64705884, ..., 0.4784314 ,\n", " 0.34901962, 0.20000002],\n", " [0.65882355, 0.654902 , 0.6392157 , ..., 0.48235297,\n", " 0.2901961 , 0.18823531],\n", " [0.6509804 , 0.6313726 , 0.6509804 , ..., 0.4666667 ,\n", " 0.28235295, 0.15686275]],\n", " \n", " [[0.19607845, 0.20784315, 0.21568629, ..., 0.5254902 ,\n", " 0.25490198, 0.17254902],\n", " [0.20000002, 0.20392159, 0.21176472, ..., 0.54901963,\n", " 0.20784315, 0.1764706 ],\n", " [0.20392159, 0.20392159, 0.21176472, ..., 0.5372549 ,\n", " 0.13725491, 0.19215688],\n", " ...,\n", " [0.69411767, 0.7137255 , 0.6901961 , ..., 0.4666667 ,\n", " 0.34509805, 0.18039216],\n", " [0.7019608 , 0.69803923, 0.6784314 , ..., 0.47058827,\n", " 0.28627452, 0.17254902],\n", " [0.69411767, 0.6745098 , 0.6901961 , ..., 0.45882356,\n", " 0.28235295, 0.14117648]]]], dtype=float32),\n", " None,\n", " [array([[0.0356935 , 0.04294837, 0.39303777, ..., 0. , 0. ,\n", " 0. ],\n", " [0.04497283, 0.03634426, 0.28341672, ..., 0. , 0. ,\n", " 0. ],\n", " [0.0434874 , 0.03800313, 0.75378764, ..., 0. , 0. ,\n", " 0. ],\n", " ...,\n", " [0.95629567, 0.9496812 , 0.39901513, ..., 0. , 0. ,\n", " 0. ],\n", " [0.9651769 , 0.9616962 , 0.2944686 , ..., 0. , 0. ,\n", " 0. ],\n", " [0.9644257 , 0.963231 , 0.78297573, ..., 0. , 0. ,\n", " 0. ]], dtype=float32),\n", " array([[0.01951509, 0.0228059 , 0.04582008, ..., 0. , 0. ,\n", " 0. ],\n", " [0.01772608, 0.01777437, 0.40595454, ..., 0. , 0. ,\n", " 0. ],\n", " [0.02009349, 0.01785124, 0.07524952, ..., 0. , 0. ,\n", " 0. ],\n", " ...,\n", " [0.97332203, 0.9748124 , 0.05124856, ..., 0. , 0. ,\n", " 0. ],\n", " [0.9798385 , 0.9756502 , 0.29239783, ..., 0. , 0. ,\n", " 0. ],\n", " [0.97963774, 0.98362696, 0.07929821, ..., 0. , 0. ,\n", " 0. ]], dtype=float32),\n", " array([[0.01104157, 0.00598315, 0.01944767, ..., 0. , 0. ,\n", " 0. ],\n", " [0.0109013 , 0.01096408, 0.02180411, ..., 0. , 0. ,\n", " 0. ],\n", " [0.01095261, 0.00942239, 0.15182868, ..., 0. , 0. ,\n", " 0. ],\n", " ...,\n", " [0.9924597 , 0.98857427, 0.01375204, ..., 0. , 0. ,\n", " 0. ],\n", " [0.98946756, 0.9869416 , 0.01889397, ..., 0. , 0. ,\n", " 0. ],\n", " [0.9876355 , 0.9894262 , 0.13790408, ..., 0. , 0. ,\n", " 0. ]], dtype=float32)])" ] }, "metadata": { "tags": [] }, "execution_count": 8 } ] }, { "cell_type": "code", "metadata": { "id": "B5beSinpCn8C", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 235 }, "outputId": "19d57e04-547d-408b-8c03-4fa0d31d3322" }, "source": [ "for output in layersOutputs:\n", " for detection in output:\n", " scores = detection[5:]\n", " classID = np.argmax(scores)\n", " confidence = scores[classID]\n", " if confidence > confidenceThreshold:\n", " box = detection[0:4] * np.array([W, H, W, H])\n", " (centerX, centerY, width, height) = box.astype('int')\n", " x = int(centerX - (width/2))\n", " y = int(centerY - (height/2))\n", "\n", " boxes.append([x, y, int(width), int(height)])\n", " confidences.append(float(confidence))\n", " classIDs.append(classID)\n", "\n", "\n", "boxes, confidences, classIDs" ], "execution_count": 10, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "([[472, 86, 220, 79],\n", " [117, 124, 452, 307],\n", " [122, 223, 197, 320],\n", " [472, 86, 220, 79],\n", " [117, 124, 452, 307],\n", " [122, 223, 197, 320]],\n", " [0.9396677613258362,\n", " 0.9898989796638489,\n", " 0.9979043006896973,\n", " 0.9396677613258362,\n", " 0.9898989796638489,\n", " 0.9979043006896973],\n", " [7, 1, 16, 7, 1, 16])" ] }, "metadata": { "tags": [] }, "execution_count": 10 } ] }, { "cell_type": "code", "metadata": { "id": "-JKGlc9ICxdp", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 67 }, "outputId": "cf59ca6f-b525-4f24-ad81-9fb52b205077" }, "source": [ "detectionNMS = cv2.dnn.NMSBoxes(boxes, confidences, confidenceThreshold, NMSThreshold)\n", "detectionNMS, 'length of detectionNMS = ', len(detectionNMS)" ], "execution_count": 18, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "(array([[2],\n", " [1],\n", " [0]], dtype=int32), 'length of detectionNMS = ', 3)" ] }, "metadata": { "tags": [] }, "execution_count": 18 } ] }, { "cell_type": "code", "metadata": { "id": "t5D4W_VtC9Sx", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 67 }, "outputId": "5271fc18-670d-4837-e38f-ac96c6b37c19" }, "source": [ "if(len(detectionNMS) > 0):\n", " for i in detectionNMS.flatten():\n", " (x, y) = (boxes[i][0], boxes[i][1])\n", " (w, h) = (boxes[i][2], boxes[i][3])\n", " \n", " detected = labels[classIDs[i]]\n", " print(detected)\n", " \n", " color = [int(c) for c in COLORS[classIDs[i]]]\n", " cv2.rectangle(image, (x, y), (x + w, y + h), color, 2)\n", " text = '{}: {:.4f}'.format(labels[classIDs[i]], confidences[i])\n", " cv2.putText(image, text, (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)\n", "\n", "# cv2.imshow('Image', image)\n", "# cv2.waitKey(0)" ], "execution_count": 20, "outputs": [ { "output_type": "stream", "text": [ "dog\n", "bicycle\n", "truck\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "QPqGKCmhDZ2G", "colab_type": "code", "colab": {} }, "source": [ "" ], "execution_count": null, "outputs": [] } ] }