Cheat Sheet
Keras API cheat sheet
Check Library Version
import tensorflow as tf
print(tf.__version__)
from tensorflow import keras
from tensorflow.keras import layers
print(keras.__version__)
import numpy as np
print(np.__version__)
import cv2
print(cv2.__version__)Check GPU
physical_devices = tf.config.list_physical_devices('GPU')
print("Num GPUs:", len(physical_devices))
device_name = tf.test.gpu_device_name()
print('GPU at: {}'.format(device_name))Prepare Datasets
Option1) Use datasets provided by TF/Keras
Option2) Use or create your own database in local storage
Load and Plot Images
Using OpenCV (color mode is B-G-R)
Using Matplotlib
Load and plot using PIL
Convert PIL to Numpy, OpenCV to Numpy
Subplot with matplotlib
Split into train validate database
Option 1) Classes divided by folder name. image_dataset_from_directory
image_dataset_from_directoryOption 2) Train Valid Test are divided by folder names manually flow_from_directory
flow_from_directory
Visualize the dataset
Preprocessing Database
Buffer Prefetch
Rescaling, Cropping - can be included in model
Build Model
* Example 2: Small version of Xception
For other archiectures, go to Tutorial
Visualize model
Train the model
Save and load model in Keras
Option 1) Model and Weight in one file (gives error... )
Option 2) Model (json) and weight separately
Run inference
Test on some data
Test on all validate database
Last updated