With the rise and popularity of deep learning algorithms, the field of artificial intelligence has made remarkable progress, especially in the field of computer vision. The second decade of the 21st century quickly adopted convolutional neural networks, inventing the most advanced algorithms, the availability of a large amount of training data, and the invention of high performance and cost-effective computing. A key concept in computer vision is image classification; this is the ability of a software system to correctly mark dominant objects in an image.
ImageAI is a Python library designed to help developers build applications and systems with self-contained computer vision capabilities.
1. Install Python 3.5.1 or higher and pip
(If you already have Python 3.5.1 or higher installed, skip this section)
2. Install the ImageAI dependency
3. Install the ImageAI library
Pip3 install https://github.com/OlafenwaMoses/ImageAI/raw/master/dist/imageai-1.0.2-py3-none-any.whl
4. Download the ResNet Model file trained with the ImageNet-1000 dataset and copy the file to your python project folder.
Https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels.h5
5. Create a file named python (for example "FirstPredicTIon.py") and write the following code into it.
Sample.jpg
Code result:
Code description
Now let's break down the code to see how it works. The above code works as follows:
From imageai.PredicTIon import ImagePredicTIon import os
The above code imports the ImageAI ImagePredicTIon class and the python os class.
Execution_path = os.getcwd()
The above code creates a variable that holds a reference to the path containing the python file (in this case, FirstPrediction.py) and the ResNet model file.
In the above code, we created an instance of the ImagePrediction() class on the first line, then set the model type of the predicted object to ResNet by calling .setModelTypeAsResNet() on the second line, and then setting the model path to predict The object is copied to the path of the model file (resnet50_weights_tf_dim_ordering_tf_kernels.h5) and copied to the project folder folder of the third line.
Predictions, percentage_probabilities = prediction.predictImage("C:UsersMyUserDownloadssample.jpg", result_count=5)
In the above line, we define two variables, which are equal to the function called to predict the image. This function is the .predictImage() function, in which we parse the path of the image, and also indicate the prediction we want. The number of results has a value (from 1 to 1000) parsing result_count = 5 . The .predictImage() function will return a prediction with the first (predicted by the level 2 array of objects) and the second (array percentage_probabilities) is the corresponding percentage probability for each predicted array.
For index in range(len(predictions)): print(predictions[index] + " : †+ percentage_probabilities[index])
The above row gets the predicted array of each object in it, and also gets the results from the corresponding percentage probability percentage_probabilities, and finally prints both to the console.
The .predictImage() function will be the image in the path, or the number of predictions we expect the function to return (optional, default is 5). There are 1000 projects in the ImageNet-1000 dataset, and the ResNet model is trained on this dataset, which means that the .predictImage function will return 1000 possible predictions and rank them by their probability.
With ImageAI, you can easily and easily integrate image prediction code into any application, website or system you build in python. The ImageAI library supports other algorithms and model types, some of which are optimized for speed and others for precision. With ImageAI, we hope to support more specialized aspects of computer vision, including but not limited to image recognition in special environments and special areas, as well as custom image prediction.
T Series Pluggable Connectors,Custom Pluggable Connectors,T Branch Parallel Connectors,Quick Splice Connector
Jiangmen Krealux Electrical Appliances Co.,Ltd. , https://www.krealux-online.com