Skip to content

Commit

Permalink
updated main README and image recognition README
Browse files Browse the repository at this point in the history
  • Loading branch information
OlafenwaMoses committed Jan 4, 2021
1 parent fedb335 commit 2b56e73
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 119 deletions.
67 changes: 41 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ImageAI (v2.1.5)
# ImageAI (v2.1.6)

![Discourse status](https://img.shields.io/discourse/https/forum.imageai.org/status) [![Build Status](https://travis-ci.com/OlafenwaMoses/ImageAI.svg?branch=master)](https://travis-ci.com/OlafenwaMoses/ImageAI) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/OlafenwaMoses/ImageAI/blob/master/LICENSE) [![PyPI version](https://badge.fury.io/py/imageai.svg)](https://badge.fury.io/py/imageai) [![Downloads](https://pepy.tech/badge/imageai/month)](https://pepy.tech/project/imageai/month) [![Downloads](https://pepy.tech/badge/imageai/week)](https://pepy.tech/project/imageai/week) [![codecov](https://codecov.io/gh/TechnionYP5777/project-name/branch/master/graph/badge.svg)](https://codecov.io/gh/OlafenwaMoses/ImageAI)


[![Build Status](https://travis-ci.com/OlafenwaMoses/ImageAI.svg?branch=master)](https://travis-ci.com/OlafenwaMoses/ImageAI) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/OlafenwaMoses/ImageAI/blob/master/LICENSE) [![PyPI version](https://badge.fury.io/py/imageai.svg)](https://badge.fury.io/py/imageai) [![Downloads](https://pepy.tech/badge/imageai/month)](https://pepy.tech/project/imageai) [![Downloads](https://pepy.tech/badge/imageai/week)](https://pepy.tech/project/imageai)

An open-source python library built to empower developers to build applications and systems with self-contained Deep Learning and Computer Vision capabilities using simple
and few lines of code.
Expand All @@ -9,7 +11,9 @@ An open-source python library built to empower developers to build applications

<span class="badge-patreon"><a href="https://patreon.com/OlafenwaMoses" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a></span>

[ Click here](#sponsors) to see all [sponsors](#sponsors) for the **ImageAI** project!
## ---------------------------------------------------
## ImageAI will switch to PyTorch backend starting from June, 2021.
## ---------------------------------------------------

![](logo1.png)

Expand All @@ -29,16 +33,18 @@ Eventually, **ImageAI** will provide support for a wider
recognition in special environments and special fields.


**New Release : ImageAI 2.1.5**
**New Release : ImageAI 2.1.6**

What's new:

- **Tensorboard** logging for all prediction and detection model training.
- **Progress bar** for detection training
- Allow prediction and detection in multi-threaded code
- Automatic **Multi-GPU** utilization for detection training
- Custom detection model **metrics** retrieval
- Bug fix: change custom model probability from **string to float**
- **Support Tensorflow 2.4.0**
- **SqueezeNet replaced with MobileNetV2**
- **Added TF 2.x compatible pre-trained models for ResNet recognition and RetinaNet detection**
- **Deprecates '.predictImage()' function for '.classifyImage()'**
- **Renames Model types as below:**
- ResNet >> ResNet50
- DenseNet >> DenseNet121
-


### TABLE OF CONTENTS
Expand Down Expand Up @@ -70,13 +76,26 @@ What's new:
To use **ImageAI** in your application developments, you must have installed the following
dependencies before you install **ImageAI** :

- Python 3.5.1 (and later versions)
- Tensorflow 1.4.0 (and later versions) **(Tensorflow 2.0 coming soon)**
- Python 3.7.6
- Tensorflow 2.4.0
- OpenCV
- Keras 2.x

```bash
pip install -U tensorflow keras opencv-python
- Keras 2.4.3

You can install all the dependencies by running the commands below

**Tensorflow**
```bash
pip install tensorflow==2.4.0
```

or **Tensorflow GPU** if you have NVIDIA GPU with CUDA and cuDNN installed.
```bash
pip install tensorflow-gpu==2.4.0
```

**Other Dependencies**
```bash
pip install keras==2.4.3 numpy==1.19.3 pillow==7.0.0 scipy==1.4.1 h5py==2.10.0 matplotlib==3.3.2 opencv-python keras-resnet==0.2.0
```

### Installation
Expand All @@ -85,7 +104,7 @@ pip install -U tensorflow keras opencv-python
To install ImageAI, run the python installation instruction below in the command line:

```bash
pip3 install imageai --upgrade
pip install imageai --upgrade
```

### Image Prediction
Expand All @@ -102,11 +121,11 @@ minivan : 1.7487050965428352
```

**ImageAI** provides 4 different algorithms and model types to perform image prediction, trained on the ImageNet-1000 dataset.
The 4 algorithms provided for image prediction include **SqueezeNet**, **ResNet**, **InceptionV3** and **DenseNet**.
The 4 algorithms provided for image prediction include **MobileNetV2**, **ResNet50**, **InceptionV3** and **DenseNet121**.

Click the link below to see the full sample codes, explanations and best practices guide.

[>>> Tutorial & Guide](imageai/Prediction/README.md)
[>>> Tutorial & Guide](imageai/Classification/README.md)


### Object Detection
Expand Down Expand Up @@ -179,7 +198,7 @@ _A sample from the IdenProf Dataset used to train a Model for predicting profess
You can train your custom models using SqueezeNet, ResNet50, InceptionV3 and DenseNet in **5** lines of code.
Click the link below to see the guide to preparing training images, sample training codes, explanations and best practices.

[>>> Tutorials & Documentation](imageai/Prediction/CUSTOMTRAINING.md)
[>>> Tutorials & Documentation](imageai/Classification/CUSTOMTRAINING.md)


### Custom Image Prediction
Expand Down Expand Up @@ -360,12 +379,6 @@ You can cite **ImageAI** in your projects and research papers via the **BibTeX**
```


<div id="sponsors"></div>

### >>> Basic Sponsors

[<img src="https://avatars1.githubusercontent.com/u/46119184?s=460&v=" alt="David Lopez" style="width:50px;"/>](https://github.com/daviddbarrero)


### References
<div id="ref"></div>
Expand Down Expand Up @@ -398,3 +411,5 @@ You can cite **ImageAI** in your projects and research papers via the **BibTeX**
[https://arxiv.org/abs/1804.02767](https://arxiv.org/abs/1804.02767)
14. Experiencor, Training and Detecting Objects with YOLO3
[https://github.com/experiencor/keras-yolo3](https://github.com/experiencor/keras-yolo3)
15. MobileNetV2: Inverted Residuals and Linear Bottlenecks
[https://arxiv.org/abs/1801.04381](https://arxiv.org/abs/1801.04381)
114 changes: 22 additions & 92 deletions imageai/Prediction/README.md → imageai/Classification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ A **DeepQuest AI** project [https://deepquestai.com](https://deepquestai.com)
- <a href="#firstprediction" > :white_square_button: First Prediction</a>
- <a href="#predictionspeed" > :white_square_button: Prediction Speed</a>
- <a href="#inputtype" > :white_square_button: Image Input Types</a>
- <a href="#multiprediction" > :white_square_button: Multiple Images Prediction</a>
- <a href="#threadprediction" > :white_square_button: Prediction in MultiThreading</a>
- <a href="#documentation" > :white_square_button: Documentation</a>

ImageAI provides 4 different algorithms and model types to perform image prediction.
To perform image prediction on any picture, take the following simple steps. The 4 algorithms provided for
image prediction include **SqueezeNet**, **ResNet**, **InceptionV3** and **DenseNet**. Each of these
image prediction include **MobileNetV2**, **ResNet50**, **InceptionV3** and **DenseNet121**. Each of these
algorithms have individual model files which you must use depending on the choice of your algorithm. To download the
model file for your choice of algorithm, click on any of the links below:

- **[SqueezeNet](https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/squeezenet_weights_tf_dim_ordering_tf_kernels.h5)** _(Size = 4.82 mb, fastest prediction time and moderate accuracy)_
- **[ResNet50](https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/resnet50_weights_tf_dim_ordering_tf_kernels.h5)** by Microsoft Research _(Size = 98 mb, fast prediction time and high accuracy)_
- **[MobileNetV2](https://github.com/OlafenwaMoses/ImageAI/releases/download/essentials-v5/mobilenet_v2.h5)** _(Size = 4.82 mb, fastest prediction time and moderate accuracy)_
- **[ResNet50](https://github.com/OlafenwaMoses/ImageAI/releases/download/essentials-v5/resnet50_imagenet_tf.2.0.h5)** by Microsoft Research _(Size = 98 mb, fast prediction time and high accuracy)_
- **[InceptionV3](https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/inception_v3_weights_tf_dim_ordering_tf_kernels.h5)** by Google Brain team _(Size = 91.6 mb, slow prediction time and higher accuracy)_
- **[DenseNet121](https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/DenseNet-BC-121-32.h5)** by Facebook AI Research _(Size = 31.6 mb, slower prediction time and highest accuracy)_

Expand All @@ -31,17 +30,17 @@ To perform image prediction on any picture, take the following simple steps. Th
<div id="firstprediction" ></div>

```python
from imageai.Prediction import ImagePrediction
from imageai.Classification import ImageClassification
import os

execution_path = os.getcwd()

prediction = ImagePrediction()
prediction.setModelTypeAsResNet()
prediction.setModelPath(os.path.join(execution_path, "resnet50_weights_tf_dim_ordering_tf_kernels.h5"))
prediction = ImageClassification()
prediction.setModelTypeAsResNet50()
prediction.setModelPath(os.path.join(execution_path, "resnet50_imagenet_tf.2.0.h5"))
prediction.loadModel()

predictions, probabilities = prediction.predictImage(os.path.join(execution_path, "1.jpg"), result_count=5 )
predictions, probabilities = prediction.classifyImage(os.path.join(execution_path, "1.jpg"), result_count=5 )
for eachPrediction, eachProbability in zip(predictions, probabilities):
print(eachPrediction , " : " , eachProbability)
```
Expand All @@ -59,7 +58,7 @@ minivan : 1.7487050965428352

The code above works as follows:
```python
from imageai.Prediction import ImagePrediction
from imageai.Classification import ImageClassification
import os
```
The code above imports the `ImageAI` library and the python `os` class.
Expand All @@ -69,17 +68,17 @@ execution_path = os.getcwd()
The above line obtains the path to the folder that contains your python file (in this example, your FirstPrediction.py).

```python
prediction = ImagePrediction()
prediction.setModelTypeAsResNet()
prediction.setModelPath(os.path.join(execution_path, "resnet50_weights_tf_dim_ordering_tf_kernels.h5"))
prediction = ImageClassification()
prediction.setModelTypeAsResNet50()
prediction.setModelPath(os.path.join(execution_path, "resnet50_imagenet_tf.2.0.h5"))
```
In the lines above, we created and instance of the `ImagePrediction()` class in the first line, then we set the model type of the prediction object to ResNet by caling the `.setModelTypeAsResNet()` in the second line and then we set the model path of the prediction object to the path of the model file (`resnet50_weights_tf_dim_ordering_tf_kernels.h5`) we copied to the python file folder in the third line.
In the lines above, we created and instance of the `ImagePrediction()` class in the first line, then we set the model type of the prediction object to ResNet by caling the `.setModelTypeAsResNet50()` in the second line and then we set the model path of the prediction object to the path of the model file (`resnet50_imagenet_tf.2.0.h5`) we copied to the python file folder in the third line.

```python
predictions, probabilities = prediction.predictImage(os.path.join(execution_path, "1.jpg"), result_count=5 )
predictions, probabilities = prediction.classifyImage(os.path.join(execution_path, "1.jpg"), result_count=5 )
```

In the above line, we defined 2 variables to be equal to the function called to predict an image, which is the `.predictImage()` function, into which we parsed the path to our image and also state the number of prediction results we want to have (values from 1 to 1000) parsing `result_count=5`. The `.predictImage()` function will return 2 array objects with the first (**predictions**) being an array of predictions and the second (**percentage_probabilities**) being an array of the corresponding percentage probability for each prediction.
In the above line, we defined 2 variables to be equal to the function called to predict an image, which is the `.classifyImage()` function, into which we parsed the path to our image and also state the number of prediction results we want to have (values from 1 to 1000) parsing `result_count=5`. The `.classifyImage()` function will return 2 array objects with the first (**predictions**) being an array of predictions and the second (**percentage_probabilities**) being an array of the corresponding percentage probability for each prediction.

```python
for eachPrediction, eachProbability in zip(predictions, probabilities):
Expand All @@ -88,75 +87,6 @@ for eachPrediction, eachProbability in zip(predictions, probabilities):
The above line obtains each object in the **predictions** array, and also obtains the corresponding percentage probability from the **percentage_probabilities**, and finally prints the result of both to console.


### Multiple Images Prediction
<div id="multiprediction"></div>

You can run image prediction on more than one image using a single function, which is the `.predictMultipleImages()` function. It works by doing the following:
- Define your normal `ImagePrediction` instance
- Set the model type and model path
- Call the `.loadModel()` function
- Create an array and add all the string path to each of the images you want to predict to the array.
- You then perform prediction by calling the `.predictMultipleImages()` function and parse in the array of images, and also set the number predictions you want per image by parsing `result_count_per_image=5` (default value is 2)

Find the sample code below:

```python
from imageai.Prediction import ImagePrediction
import os

execution_path = os.getcwd()

multiple_prediction = ImagePrediction()
multiple_prediction.setModelTypeAsResNet()
multiple_prediction.setModelPath(os.path.join(execution_path, "resnet50_weights_tf_dim_ordering_tf_kernels.h5"))
multiple_prediction.loadModel()

all_images_array = []

all_files = os.listdir(execution_path)
for each_file in all_files:
if(each_file.endswith(".jpg") or each_file.endswith(".png")):
all_images_array.append(each_file)

results_array = multiple_prediction.predictMultipleImages(all_images_array, result_count_per_image=5)

for each_result in results_array:
predictions, percentage_probabilities = each_result["predictions"], each_result["percentage_probabilities"]
for index in range(len(predictions)):
print(predictions[index] , " : " , percentage_probabilities[index])
print("-----------------------")
```

In the above code, the `.predictMultipleImages()` function will return an array which contains a dictionary per image.
Each dictionary contains the arrays for predictions and percentage probability for each prediction.

Sample Result:
![](../../data-images/1.jpg)
![](../../data-images/2.jpg)
![](../../data-images/3.jpg)

```
convertible : 52.459555864334106
sports_car : 37.61284649372101
pickup : 3.1751200556755066
car_wheel : 1.817505806684494
minivan : 1.7487050965428352
-----------------------
toilet_tissue : 13.99008333683014
jeep : 6.842949986457825
car_wheel : 6.71963095664978
seat_belt : 6.704962253570557
minivan : 5.861184373497963
-----------------------
bustard : 52.03368067741394
vulture : 20.936034619808197
crane : 10.620515048503876
kite : 10.20539253950119
white_stork : 1.6472270712256432
-----------------------
```


### Prediction Speed
<div id="predictionspeed"></div>

Expand Down Expand Up @@ -269,11 +199,11 @@ This means you can now perform image prediction in production applications such
that returns file in any of the above stated formats.

To perform image prediction with numpy array or file stream input, you just need to state the input type
in the `.predictImage()` function or the `.predictMultipleImages()` function. See example below.
in the `.classifyImage()` function. See example below.

```python
predictions, probabilities = prediction.predictImage(image_array, result_count=5 , input_type="array" ) # For numpy array input type
predictions, probabilities = prediction.predictImage(image_stream, result_count=5 , input_type="stream" ) # For file stream input type
predictions, probabilities = prediction.classifyImage(image_array, result_count=5 , input_type="array" ) # For numpy array input type
predictions, probabilities = prediction.classifyImage(image_stream, result_count=5 , input_type="stream" ) # For file stream input type
```

### Prediction in MultiThreading
Expand All @@ -284,19 +214,19 @@ When developing programs that run heavy task on the deafult thread like User Int
a new thread, you must take note the following:
- You can create your prediction object, set its model type, set model path and json path
outside the new thread.
- The `.loadModel()` must be in the new thread and image prediction (`predictImage()`) must take place in th new thread.
- The `.loadModel()` must be in the new thread and image prediction (`classifyImage()`) must take place in th new thread.

Take a look of a sample code below on image prediction using multithreading:
```python
from imageai.Prediction import ImagePrediction
from imageai.Prediction import ImageClassification
import os
import threading

execution_path = os.getcwd()

prediction = ImagePrediction()
prediction = ImageClassification()
prediction.setModelTypeAsResNet()
prediction.setModelPath( os.path.join(execution_path, "resnet50_weights_tf_dim_ordering_tf_kernels.h5"))
prediction.setModelPath( os.path.join(execution_path, "resnet50_imagenet_tf.2.0.h5"))

picturesfolder = os.environ["USERPROFILE"] + "\\Pictures\\"
allfiles = os.listdir(picturesfolder)
Expand Down
1 change: 0 additions & 1 deletion test/test_image_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cv2
import pytest
from os.path import dirname
import keras

main_folder = os.getcwd()

Expand Down

0 comments on commit 2b56e73

Please sign in to comment.