Giter VIP home page Giter VIP logo

cat-classifier-dnn's Introduction

Cat Classifier

This is a tiny experiment to visualize the activations of each unit of a neural network based image classifier as a graphical plot.

The image classifier in this experiment is based on a deep neural network that has 3 hidden layers with 10 units each and a single output layer. The hidden layers use the ReLU activation function and the output layer uses the sigmoid activation function.

Although the model trained in this experiment works with about 80% accuracy, that's not the primary concern of this experiment. The primary concern of this experiment is to visualize the activations in each unit of a trained model.

Development Setup

The development steps here are written for a Linux or Mac system. All steps mentioned below assume that Python 3 is installed and you are at the top-level directory of this project.

  1. Enter the following command to create a Python 3 virtual environment with numpy, matplotlib and h5py.

    make venv
    
  2. Enter the following command to enter the virtual environment.

    . venv
    
  3. Enter the following command to train a model, test it and write the model to a file named model.json.

    ./model.py
    

    To alter the learning parameters, look for the train() function in this file, edit the values of iterations and alpha variables and run this script again.

  4. Classify arbitrary 64x64 PNG images in the extra-set directory with the following command. You can copy any image into this directory as long as it is a 64x64 PNG and run the following command.

    ./classify.py
    
  5. To generate graphical plots of the learned model, enter the following command.

    ./plotmodel.py
    

    This generates activation plots for each unit in the neural network. This is explained further in the next section.

Activation Plots

Here are the graphical plots of the activations in each unit in each layer for every pixel component (i.e. R, G and B components). Each image is a visualization of what the activations in a specific unit looks like. For example, the first image for layer 1 is the visualization of the activations of the first unit in the first hidden layer.

Each pixel in an image below represents the activation in a specific unit for the corresponding pixel in the input image. The activation for each component (red, green and blue) for each pixel in each unit is computed separately. Then the activations of red, green and blue components in each pixel is combined and shown as a single pixel in an image below.

Layer 1 Activations

Layer 1 Unit 01 Activations Layer 1 Unit 02 Activations Layer 1 Unit 03 Activations Layer 1 Unit 04 Activations Layer 1 Unit 05 Activations Layer 1 Unit 06 Activations Layer 1 Unit 07 Activations Layer 1 Unit 08 Activations Layer 1 Unit 09 Activations Layer 1 Unit 10 Activations

Layer 2 Activations

Layer 2 Unit 01 Activations Layer 2 Unit 02 Activations Layer 2 Unit 03 Activations Layer 2 Unit 04 Activations Layer 2 Unit 05 Activations Layer 2 Unit 06 Activations Layer 2 Unit 07 Activations Layer 2 Unit 08 Activations Layer 2 Unit 09 Activations Layer 2 Unit 10 Activations

Layer 3 Activations

Layer 3 Unit 01 Activations Layer 3 Unit 02 Activations Layer 3 Unit 03 Activations Layer 3 Unit 04 Activations Layer 3 Unit 05 Activations Layer 3 Unit 06 Activations Layer 3 Unit 07 Activations Layer 3 Unit 08 Activations Layer 3 Unit 09 Activations Layer 3 Unit 10 Activations

Layer 4 Activations

Layer 4 Unit 01 Activations

Training Images

Training Image 0

Training Image 1

Training Image 2

Training Image 3

Training Image 4

Training Image 5

Training Image 6

Training Image 7

Training Image 8

Training Image 9

Training Image 10

Training Image 11

Training Image 12

Training Image 13

Training Image 14

Training Image 15

Training Image 16

Training Image 17

Training Image 18

Training Image 19

Training Image 20

Training Image 21

Training Image 22

Training Image 23

Training Image 24

Training Image 25

Training Image 26

Training Image 27

Training Image 28

Training Image 29

Training Image 30

Training Image 31

Training Image 32

Training Image 33

Training Image 34

Training Image 35

Training Image 36

Training Image 37

Training Image 38

Training Image 39

Training Image 40

Training Image 41

Training Image 42

Training Image 43

Training Image 44

Training Image 45

Training Image 46

Training Image 47

Training Image 48

Training Image 49

Training Image 50

Training Image 51

Training Image 52

Training Image 53

Training Image 54

Training Image 55

Training Image 56

Training Image 57

Training Image 58

Training Image 59

Training Image 60

Training Image 61

Training Image 62

Training Image 63

Training Image 64

Training Image 65

Training Image 66

Training Image 67

Training Image 68

Training Image 69

Training Image 70

Training Image 71

Training Image 72

Training Image 73

Training Image 74

Training Image 75

Training Image 76

Training Image 77

Training Image 78

Training Image 79

Training Image 80

Training Image 81

Training Image 82

Training Image 83

Training Image 84

Training Image 85

Training Image 86

Training Image 87

Training Image 88

Training Image 89

Training Image 90

Training Image 91

Training Image 92

Training Image 93

Training Image 94

Training Image 95

Training Image 96

Training Image 97

Training Image 98

Training Image 99

Training Image 100

Training Image 101

Training Image 102

Training Image 103

Training Image 104

Training Image 105

Training Image 106

Training Image 107

Training Image 108

Training Image 109

Training Image 110

Training Image 111

Training Image 112

Training Image 113

Training Image 114

Training Image 115

Training Image 116

Training Image 117

Training Image 118

Training Image 119

Training Image 120

Training Image 121

Training Image 122

Training Image 123

Training Image 124

Training Image 125

Training Image 126

Training Image 127

Training Image 128

Training Image 129

Training Image 130

Training Image 131

Training Image 132

Training Image 133

Training Image 134

Training Image 135

Training Image 136

Training Image 137

Training Image 138

Training Image 139

Training Image 140

Training Image 141

Training Image 142

Training Image 143

Training Image 144

Training Image 145

Training Image 146

Training Image 147

Training Image 148

Training Image 149

Training Image 150

Training Image 151

Training Image 152

Training Image 153

Training Image 154

Training Image 155

Training Image 156

Training Image 157

Training Image 158

Training Image 159

Training Image 160

Training Image 161

Training Image 162

Training Image 163

Training Image 164

Training Image 165

Training Image 166

Training Image 167

Training Image 168

Training Image 169

Training Image 170

Training Image 171

Training Image 172

Training Image 173

Training Image 174

Training Image 175

Training Image 176

Training Image 177

Training Image 178

Training Image 179

Training Image 180

Training Image 181

Training Image 182

Training Image 183

Training Image 184

Training Image 185

Training Image 186

Training Image 187

Training Image 188

Training Image 189

Training Image 190

Training Image 191

Training Image 192

Training Image 193

Training Image 194

Training Image 195

Training Image 196

Training Image 197

Training Image 198

Training Image 199

Training Image 200

Training Image 201

Training Image 202

Training Image 203

Training Image 204

Training Image 205

Training Image 206

Training Image 207

Training Image 208

Test Results

Test Image 0
cat (pass)

Test Image 1
cat (pass)

Test Image 2
cat (pass)

Test Image 3
cat (pass)

Test Image 4
not (fail)

Test Image 5
not (pass)

Test Image 6
cat (pass)

Test Image 7
cat (pass)

Test Image 8
cat (pass)

Test Image 9
cat (pass)

Test Image 10
cat (pass)

Test Image 11
cat (pass)

Test Image 12
cat (pass)

Test Image 13
not (pass)

Test Image 14
not (pass)

Test Image 15
cat (pass)

Test Image 16
not (pass)

Test Image 17
cat (pass)

Test Image 18
not (fail)

Test Image 19
not (fail)

Test Image 20
cat (pass)

Test Image 21
not (pass)

Test Image 22
not (pass)

Test Image 23
cat (pass)

Test Image 24
cat (pass)

Test Image 25
cat (pass)

Test Image 26
cat (pass)

Test Image 27
not (pass)

Test Image 28
not (fail)

Test Image 29
cat (fail)

Test Image 30
cat (pass)

Test Image 31
cat (pass)

Test Image 32
cat (pass)

Test Image 33
cat (pass)

Test Image 34
not (pass)

Test Image 35
not (pass)

Test Image 36
not (pass)

Test Image 37
cat (pass)

Test Image 38
cat (fail)

Test Image 39
not (pass)

Test Image 40
cat (pass)

Test Image 41
not (fail)

Test Image 42
cat (pass)

Test Image 43
not (pass)

Test Image 44
cat (fail)

Test Image 45
not (pass)

Test Image 46
not (fail)

Test Image 47
cat (pass)

Test Image 48
cat (pass)

Test Image 49
not (pass)

Test Accuracy

Out of 50 test samples, 41 were correctly classified.

The test accuracy is: 82.00%.

Alter the learning parameters in iterations and alpha variables in train() and backward functions, respectively, of model.py to alter the test accuracy.

Training and Test Sets

The training images and test images are present in train-set and test-set directories.

The training and test data were obtained from a few HDF5 files shared by Andrew Ng. The original H5 files are present in the h5data directory.

The script h5toimg.py converts this data to separate PNG image files and writes them to train-set and test-set directories.

cat-classifier-dnn's People

Contributors

susam avatar

Stargazers

Dwayne Campbell avatar  avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.