Object Detection with 10 lines of code

Take a look at a 2 image samples below and the new images saved after detection.Before Detection:Image Credit: alzheimers.co.ukImage Credit: WikicommonsAfter Detection:Console result for above image:person : 55.8402955532074person : 53.21805477142334person : 69.25139427185059person : 76.41745209693909bicycle : 80.30363917350769person : 83.58567953109741person : 89.06581997871399truck : 63.10953497886658person : 69.82483863830566person : 77.11606621742249bus : 98.00949096679688truck : 84.02870297431946car : 71.98476791381836Console result for above image:person : 71.10445499420166person : 59.28672552108765person : 59.61582064628601person : 75.86382627487183motorcycle : 60.1050078868866bus : 99.39600229263306car : 74.05484318733215person : 67.31776595115662person : 63.53200078010559person : 78.2265305519104person : 62.880998849868774person : 72.93365597724915person : 60.01397967338562person : 81.05944991111755motorcycle : 50.591760873794556motorcycle : 58.719027042388916person : 71.69321775436401bicycle : 91.86570048332214motorcycle : 85.38855314254761Now let us explain how the 10-line code works.In the above 3 lines, we imported the ImageAI object detection class in the first line, imported the python os class in the second line and defined a variable to hold the path to the folder where our python file, RetinaNet model file and images are in the third line.In the 5 lines of code above, we defined our object detection class in the first line, set the model type to RetinaNet in the second line, set the model path to the path of our RetinaNet model in the third line, load the model into the object detection class in the fourth line, then we called the detection function and parsed in the input image path and the output image path in the fifth line.In the above 2 lines of code, we iterate over all the results returned by the detector.detectObjectsFromImage function in the first line, then print out the name and percentage probability of the model on each object detected in the image in the second line.ImageAI supports many powerful customization of the object detection process..One of it is the ability to extract the image of each object detected in the image..By simply parsing the extra parameter extract_detected_objects=True into the detectObjectsFromImage function as seen below, the object detection class will create a folder for the image objects, extract each image, save each to the new folder created and return an extra array that contains the path to each of the images.Let us apply it to the first image and see some of the images from the result below:All the pictures of the pedestrians were extracted has well..I did not include all of them has they will take unnecessary space.ImageAI provides many more features useful for customization and production capable deployments for object detection tasks..Some of the features supported are:- Adjusting Minimum Probability: By default, objects detected with a probability percentage of less than 50 will not be shown or reported..You can increase this value for high certainty cases or reduce the value for cases where all possible objects are needed to be detected.- Custom Objects Detection: Using a provided CustomObject class, you can tell the detection class to report detections on one or a few number of unique objects.- Detection Speeds: You can reduce the time it takes to detect an image by setting the speed of detection speed to “fast”, “faster” and “fastest”.- Input Types: You can specify and parse in file path to an image, Numpy array or file stream of an image as the input image- Output Types: You can specify that the detectObjectsFromImage function should return the image in the form of a file or Numpy arrayYou can find all the details and documentation of how to make use of the above features, as well as other computer vision features contained in ImageAI on the official GitHub repository.https://github.com/OlafenwaMoses/ImageAIIf you find this article helpful and enjoyed it, kindly give it a clap..Also, feel free to share it with friends and colleagues.Do you have any questions, suggestions or will like to reach to me?.Send me an email to guymodscientist@gmail.com ..I am also available on twitter via the handle @OlafenwaMoses and on Facebook via https://www.facebook.com/moses.olafenwa .. More details

Leave a Reply