Training a Neural Network
Training a Shape Classifier
- Shape Classifier that distinguishes between circles and rectangles using 28x28 thumbnails. Similar method for more advanced types of classifiers.
- Process:
- Data Gathering
- Data Cleaning & Preprocessing
- Removing dogs from scraped set of cat pictures
- Data Augmentation (For training data)
- Geometric transformation
- Color/Brightness adjustment
- Synthetic Noise addition
- Dataset Splitting
- Training Set (70-80%)
- Validation Set (10-15%)
- Test Set (10-15%)
- Final Datasets (Training, Validation, Test)
- Deep Learning Model Training -> this is iterative
- Model Evaluation & Testing
- When developing a deep learning model - use 80% for training and 20% for validation.
- Labeling & Splitting Training Data
- predict
- train
- CIRCLE
- the image itself, and the label (/CIRCLE, the name itself doesn’t matter circle_0000.png)
- RECTANGLE
- Natural vs Synthetic Data
- Natural - is data out in the world, gathered through observation
- Synthetic - generated in various ways, can be using AI or just simple scripts (Processing, etc.)
- Getting Started
import os // just bringing in the os
import numpy as np // numpy is common for vector and matrix math
import pandas as pd // pandas is tabular data
import cv2 // standard machine vision library, image manipulation
import tensorflow as tf // deep learning and AI
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dropout, Dense // simpler interface for deep learning / AI
from tensorflow.keras.models import Sequential
from sklearn.model_selection import train_test_split // scikit Classical Machine learning
from sklearn.preprocessing import LabelEncoder
- Machine Learning vs. AI
- Machine Learning is glorified statistics - clustering, dimension reduction, finding correlations in data, light pattern recognition
- Whereas “deep learning” is machine learning x 1000, using the same techniques but stacking it sequentially so you can do deeper analysis
- To initiate the process
def start(self, retrain=True); // Train a model or load existing
def prepare_data(self); // Map labels to integers, split training and testing data
def train_model(self); // Train the model
def predict(self, path); // Classify an image, with trained model
def predict_all(self); // Classify all images in a folder
def process_prediction(self, image_path); // executes prediction and finds the label
def image_to_input(self, image_path); // resize and grayscale images to prep into same format
def read_images(self); //
def images_to_csv(self, image_path, label) // transform an image to numberic matrix
- An Epoch is the retraining to he model through every element of the data set
- Training creates an .h5 file
- For javascript -> need an onyx file
- For Swift?
- scikit-learn, opencv-python,
- Processing can be very useful for generating and transforming image based datasets