rzarno / phpcnn

Training convolutional neural network model in PHP to predict actions of self-driving car.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Training Convolutional Neural Network in PHP

This project is about training convolutional neural network model (CNN) for use cases:

  • I self-driving vehicle
  • II captcha image recognition

Setup

You can run project locally or using docker.

Local

  1. Install PHP 8.1 with dependencies: php8.1-imagick php8.1-gd php8.1-sqlite3
  2. Install composer
  3. Install Rindow OpenBLAS PHP extension
  4. Install project dependencies: composer install
  5. Set memory_limit = -1 in php.ini

I self-driving vehicle

Setup

To train and test model run:

bin/cli self-driving-image-classification-cnn-pipeline

or using docker:

docker run --rm rzarno/phpcnn \
  self-driving-image-classification-cnn-pipeline

About

The goal for a trained model is to lead self-driving vehicle to choose proper action (go forward, turn left, turn right) based on image from front camera. Car has to follow track inside created lane.

Project base components

CNN model is based on Nvidia "DAVE 2" proposed architecture

https://arxiv.org/pdf/1604.07316v1.pdf

model implementation and training was handled thanks to Rindow Neural Networks

https://github.com/rindow/rindow-neuralnetworks

data distribution:

main program is based on chain of responsibility design pattern implemented using league/pipeline and containing stages:

  1. Import data
  2. Analyze dataset
  3. Impute more data based on imported images
  4. Split data to training and test set
  5. Preprocess images - scale and flatten
  6. Build convolutional neural network model from specified layers
  7. Train model
  8. Export model
  9. Evaluate model

Results

Model trained with 42000 images and 20 epochs achieves 72% accuracy.

Results for specific classes: correct predictions 1: 73/102 72% correct predictions 2: 37/57 65% correct predictions 3: 34/42 81%


II captcha image recognition

Setup

To train and test model run:

bin/cli captcha-image-classification-cnn-pipeline

or using docker:

docker run --rm rzarno/phpcnn \
  captcha-image-classification-cnn-pipeline

About

The goal for trained model is to recognize 6 characters from captcha images like below.

Captcha can contain any of 28 characters below. Letters are skewed, transformed and rotated. ['6', '2', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'W', 'V', 'X', 'Y', 'Z']

data distribution:

Pipeline

  1. Import data
  2. Analyze dataset
  3. Crop and adjust image, extract single chars
  4. Split data to training and test set
  5. Preprocess images - scale and flatten
  6. Build convolutional neural network model from specified layers
  7. Train model
  8. Export model
  9. Evaluate model

Results

Model trained with 42000 images and 20 epochs achieves 87% accuracy.

Prediction has good accuracy for all 28 classes.

About

Training convolutional neural network model in PHP to predict actions of self-driving car.

License:GNU General Public License v3.0


Languages

Language:PHP 95.5%Language:Dockerfile 4.5%