/Convolutional-Neural-Networks-Tensorflow

Implementation of famous convolutional neural networks in Tensorflow

Primary LanguagePythonMIT LicenseMIT

Convolutional Neural Networks

This repository implements the most famous image classification CNN models from scratch in Tensorflow. The implemented models are:

  • ResNet50
  • MobileNetV1
  • MobileNetV2
  • GoogLeNet
  • VGG16
  • VGG11
  • VGG13
  • BN-Inception
  • InceptionV4
  • Inception-ResNetV1
  • Inception-ResNetV2
  • Xception

In the future, this repository will be updated with other convolutional neural networks.

Install

Clone Repository

Clone repo and install requirements.txt in a Python==3.8.3 environment, including Tensorflow==2.7.0.

git clone git@github.com:MrRiahi/Convolutional-Neural-Networks.git
cd Convolutional-Neural-Networks

Virtual Environment

Python virtual environment will keep dependant Python packages from interfering with other Python projects on your system.

python -m venv venv
source venv/bin/activate

Requirements

Install python requirements.

pip install --upgrade pip
pip install -r requirements.txt

Train

Set your model name, number of epochs, dataset details in utils/config.py and run the following command:

python train.py

Evaluation

To evaluate your model, set your dataset path in evaluate.py and run the following command in terminal:

python evaluate.py

Inference

To infer your model, set your image directory in predict.py and run the following command in terminal:

python predict.py

Result

The result of models on test dataset are reported in the following table.

loss_test acc_test
InceptionV4 0.4403 88.81
BNInception 0.4681 87.50
MobileNetV2 0.5142 87.88
Inception-ResNetV1 0.5611 87.96
GoogLeNet 0.6244 81.03
ResNet50 0.6503 81.94
MobileNetV1 0.6547 82.54

Convert to TFLite

You can convert the tensorflow model to TFLite by using the following command:

python convert.py

Afterward, you can infer the TFLite model using the following command:

python infer_tflite.py

Convert to Onnx

You can convert the tensorflow model to Onnx by using the following command in terminal:

python -m tf2onnx.convert --saved-model models/cifar-10/ResNet50 \
       --output models/cifar-10/ResNet50.onnx --opset 11 --verbos

Afterward, you can infer the Onnx model using the following command:

python infer_onnx.py

TODO

  • Implement and train ResNet50
  • Implement and train MobileNetV1
  • Implement and train MobileNetV2
  • Create a data generator for GoogLeNet
  • Implement and train GoogleNet
  • Add evaluation
  • Add Inference
  • Convert models to TFLite
  • Convert models to Onnx
  • Inference with TFLite
  • Inference with Onnx
  • Implement and train VGG16
  • Implement and train BN-Inception
  • Implement and train Inception-V3
  • Implement and train Inception-V4
  • Implement and train Inception-ResNet-V1
  • Implement and train Inception-ResNet-V2
  • Implement and train Xception
  • Implement and train ResNeXt-50

References