{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "ImageAI for Object Detection\n", "http://imageai.org/#features" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "ImageAI provides API to recognize 1000 different objects in a picture using pre-trained models that were trained on the ImageNet-1000 dataset. The model implementations provided are SqueezeNet, ResNet, InceptionV3 and DenseNet.\n", "
\n", "ImageAI provides API to detect, locate and identify 80 most common objects in everyday life in a picture using pre-trained models that were trained on the COCO Dataset. The model implementations provided include RetinaNet, YOLOv3 and TinyYOLOv3." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are 80 possible objects that you can detect with the\n", "ObjectDetection class, and they are as seen below.\n", "\n", " person, bicycle, car, motorcycle, airplane,\n", " bus, train, truck, boat, traffic light, fire hydrant, stop_sign,\n", " parking meter, bench, bird, cat, dog, horse, sheep, cow, elephant, bear, zebra,\n", " giraffe, backpack, umbrella, handbag, tie, suitcase, frisbee, skis, snowboard,\n", " sports ball, kite, baseball bat, baseball glove, skateboard, surfboard, tennis racket,\n", " bottle, wine glass, cup, fork, knife, spoon, bowl, banana, apple, sandwich, orange,\n", " broccoli, carrot, hot dog, pizza, donot, cake, chair, couch, potted plant, bed,\n", " dining table, toilet, tv, laptop, mouse, remote, keyboard, cell phone, microwave,\n", " oven, toaster, sink, refrigerator, book, clock, vase, scissors, teddy bear, hair dryer,\n", " toothbrush." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "requirements:
\n", "tensorflow==1.15.0
\n", "numpy==1.19.5
\n", "scipy==1.4.1
\n", "keras==2.1.0
\n", "imageai==2.0.2
\n", "\n", "Or update to newest version, see https://github.com/OlafenwaMoses/ImageAI
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Download the RetinaNet model file for object detection\n", "\n", "https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/resnet50_coco_best_v2.0.1.h5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from imageai.Detection import ObjectDetection\n", "import matplotlib.pyplot as plt\n", "import skimage.io\n", "import os" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "execution_path = os.getcwd()\n", "\n", "detector = ObjectDetection()\n", "detector.setModelTypeAsRetinaNet()\n", "detector.setModelPath(os.path.join(execution_path, \"resnet50_coco_best_v2.0.1.h5\"))\n", "detector.loadModel()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "detections = detector.detectObjectsFromImage(\n", " input_image=os.path.join(execution_path, \"image.jpg\"),\n", " output_image_path=os.path.join(execution_path, \"imagenew.jpg\"),\n", ")\n", "\n", "for eachObject in detections:\n", " print(eachObject[\"name\"], \" : \", eachObject[\"percentage_probability\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image = skimage.io.imread(\"image.jpg\")\n", "imagenew = skimage.io.imread(\"imagenew.jpg\")\n", "\n", "_, axis = plt.subplots(1, 2)\n", "axis[0].imshow(image, cmap=\"gray\")\n", "axis[1].imshow(imagenew, cmap=\"gray\")\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }