• Stars
    star
    178
  • Rank 214,989 (Top 5 %)
  • Language
    Jupyter Notebook
  • License
    MIT License
  • Created about 6 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CNN image classifier implemented in Keras Notebook ๐Ÿ–ผ๏ธ.

Image Classifier

Python Jupyter Notebook with Convolutional Neural Network image classifier implemented in Keras ๐Ÿ–ผ๏ธ. It's Google Colab ready.

Check out corresponding Medium article:

Image Classifier - Cats๐Ÿฑ vs Dogs๐Ÿถ with Convolutional Neural Networks (CNNs) and Google Colabโ€™s Free GPU

Usage

Structure your data as follows:

data/
	training/
		class_a/
			class_a01.jpg
			class_a02.jpg
			...
		class_b/
			class_b01.jpg
			class_b02.jpg
			...
	validation/
		class_a/
			class_a01.jpg
			class_a02.jpg
			...
		class_b/
			class_b01.jpg
			class_b02.jpg
			...

For binary classifications you are good to go!

For non-binary classifications:

  • add other classes to training and validation directories
  • change class_mode from "binary" to "categorical"
  • change loss function from "binary_crossentropy" to "categorical_crossentropy"

Performance

Dataset: Dogs vs Cats

Description: Binary classification. Two classes two distinguish - dogs and cats.

Training: 10 000 images per class

Validation: 2 500 images per class

model_1

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_5 (Conv2D)            (None, 198, 198, 32)      896       
_________________________________________________________________
activation_9 (Activation)    (None, 198, 198, 32)      0         
_________________________________________________________________
max_pooling2d_5 (MaxPooling2 (None, 99, 99, 32)        0         
_________________________________________________________________
conv2d_6 (Conv2D)            (None, 97, 97, 32)        9248      
_________________________________________________________________
activation_10 (Activation)   (None, 97, 97, 32)        0         
_________________________________________________________________
max_pooling2d_6 (MaxPooling2 (None, 48, 48, 32)        0         
_________________________________________________________________
flatten_3 (Flatten)          (None, 73728)             0         
_________________________________________________________________
dense_5 (Dense)              (None, 16)                1179664   
_________________________________________________________________
activation_11 (Activation)   (None, 16)                0         
_________________________________________________________________
dropout_3 (Dropout)          (None, 16)                0         
_________________________________________________________________
dense_6 (Dense)              (None, 1)                 17        
_________________________________________________________________
activation_12 (Activation)   (None, 1)                 0         
=================================================================
Total params: 1,189,825
Trainable params: 1,189,825
Non-trainable params: 0
_________________________________________________________________


model_2

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_4 (Conv2D)            (None, 198, 198, 32)      896       
_________________________________________________________________
activation_6 (Activation)    (None, 198, 198, 32)      0         
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 99, 99, 32)        0         
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 97, 97, 32)        9248      
_________________________________________________________________
activation_7 (Activation)    (None, 97, 97, 32)        0         
_________________________________________________________________
max_pooling2d_5 (MaxPooling2 (None, 48, 48, 32)        0         
_________________________________________________________________
conv2d_6 (Conv2D)            (None, 46, 46, 64)        18496     
_________________________________________________________________
activation_8 (Activation)    (None, 46, 46, 64)        0         
_________________________________________________________________
max_pooling2d_6 (MaxPooling2 (None, 23, 23, 64)        0         
_________________________________________________________________
flatten_2 (Flatten)          (None, 33856)             0         
_________________________________________________________________
dense_3 (Dense)              (None, 64)                2166848   
_________________________________________________________________
activation_9 (Activation)    (None, 64)                0         
_________________________________________________________________
dropout_2 (Dropout)          (None, 64)                0         
_________________________________________________________________
dense_4 (Dense)              (None, 1)                 65        
_________________________________________________________________
activation_10 (Activation)   (None, 1)                 0         
=================================================================
Total params: 2,195,553
Trainable params: 2,195,553
Non-trainable params: 0
_________________________________________________________________


model_3

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_4 (Conv2D)            (None, 198, 198, 32)      896       
_________________________________________________________________
activation_6 (Activation)    (None, 198, 198, 32)      0         
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 99, 99, 32)        0         
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 97, 97, 64)        18496     
_________________________________________________________________
activation_7 (Activation)    (None, 97, 97, 64)        0         
_________________________________________________________________
max_pooling2d_5 (MaxPooling2 (None, 48, 48, 64)        0         
_________________________________________________________________
conv2d_6 (Conv2D)            (None, 46, 46, 128)       73856     
_________________________________________________________________
activation_8 (Activation)    (None, 46, 46, 128)       0         
_________________________________________________________________
max_pooling2d_6 (MaxPooling2 (None, 23, 23, 128)       0         
_________________________________________________________________
flatten_2 (Flatten)          (None, 67712)             0         
_________________________________________________________________
dense_3 (Dense)              (None, 64)                4333632   
_________________________________________________________________
activation_9 (Activation)    (None, 64)                0         
_________________________________________________________________
dropout_2 (Dropout)          (None, 64)                0         
_________________________________________________________________
dense_4 (Dense)              (None, 1)                 65        
_________________________________________________________________
activation_10 (Activation)   (None, 1)                 0         
=================================================================
Total params: 4,426,945
Trainable params: 4,426,945
Non-trainable params: 0
_________________________________________________________________


model_4

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_7 (Conv2D)            (None, 198, 198, 32)      896       
_________________________________________________________________
activation_11 (Activation)   (None, 198, 198, 32)      0         
_________________________________________________________________
max_pooling2d_7 (MaxPooling2 (None, 99, 99, 32)        0         
_________________________________________________________________
conv2d_8 (Conv2D)            (None, 97, 97, 64)        18496     
_________________________________________________________________
activation_12 (Activation)   (None, 97, 97, 64)        0         
_________________________________________________________________
max_pooling2d_8 (MaxPooling2 (None, 48, 48, 64)        0         
_________________________________________________________________
conv2d_9 (Conv2D)            (None, 46, 46, 128)       73856     
_________________________________________________________________
activation_13 (Activation)   (None, 46, 46, 128)       0         
_________________________________________________________________
max_pooling2d_9 (MaxPooling2 (None, 23, 23, 128)       0         
_________________________________________________________________
flatten_3 (Flatten)          (None, 67712)             0         
_________________________________________________________________
dense_5 (Dense)              (None, 128)               8667264   
_________________________________________________________________
activation_14 (Activation)   (None, 128)               0         
_________________________________________________________________
dropout_3 (Dropout)          (None, 128)               0         
_________________________________________________________________
dense_6 (Dense)              (None, 1)                 129       
_________________________________________________________________
activation_15 (Activation)   (None, 1)                 0         
=================================================================
Total params: 8,760,641
Trainable params: 8,760,641
Non-trainable params: 0
_________________________________________________________________


model_5

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_1 (Conv2D)            (None, 200, 200, 32)      896       
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 200, 200, 32)      9248      
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 100, 100, 32)      0         
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 100, 100, 64)      18496     
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 100, 100, 64)      36928     
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 50, 50, 64)        0         
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 50, 50, 128)       73856     
_________________________________________________________________
conv2d_6 (Conv2D)            (None, 50, 50, 128)       147584    
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 25, 25, 128)       0         
_________________________________________________________________
conv2d_7 (Conv2D)            (None, 25, 25, 256)       295168    
_________________________________________________________________
conv2d_8 (Conv2D)            (None, 25, 25, 256)       590080    
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 12, 12, 256)       0         
_________________________________________________________________
flatten_1 (Flatten)          (None, 36864)             0         
_________________________________________________________________
dense_1 (Dense)              (None, 256)               9437440   
_________________________________________________________________
dropout_1 (Dropout)          (None, 256)               0         
_________________________________________________________________
dense_2 (Dense)              (None, 256)               65792     
_________________________________________________________________
dropout_2 (Dropout)          (None, 256)               0         
_________________________________________________________________
dense_3 (Dense)              (None, 1)                 257       
_________________________________________________________________
activation_1 (Activation)    (None, 1)                 0         
=================================================================
Total params: 10,675,745
Trainable params: 10,675,745
Non-trainable params: 0
_________________________________________________________________


Author

Greg (Grzegorz) Surma

PORTFOLIO

GITHUB

BLOG

Support via PayPal

More Repositories

1

style_transfer

CNN image style transfer ๐ŸŽจ.
Jupyter Notebook
272
star
2

atari

AI research environment for the Atari 2600 games ๐Ÿค–.
Python
247
star
3

image_generator

DCGAN image generator ๐Ÿ–ผ๏ธ.
Jupyter Notebook
214
star
4

face_generator

DCGAN face generator ๐Ÿง‘.
Jupyter Notebook
200
star
5

cartpole

OpenAI's cartpole env solver.
Python
143
star
6

text_predictor

Char-level RNN LSTM text generator๐Ÿ“„.
Python
113
star
7

slitherin

AI research environment for the game of Snake ๐Ÿ .
Python
90
star
8

jetson

Self-driving AI toy car ๐Ÿค–๐Ÿš—.
Jupyter Notebook
80
star
9

metal_camera

iOS metal camera with GPU shaders.
Swift
73
star
10

pixelizator

Swift/Python image pixelizer ๐Ÿ–ผ๏ธ.
Swift
68
star
11

deep_traffic

MIT DeepTraffic top 2% solution (75.01 mph) ๐Ÿš—.
JavaScript
56
star
12

password_cracker

Char-level RNN LSTM password cracker ๐Ÿ”‘๐Ÿ”“.
55
star
13

stereo_depth_estimator

Stereo depth estimation for self-driving cars ๐Ÿš—
Python
49
star
14

edge_detector

HED real-time iOS edge detector.
Swift
43
star
15

deep_dream

DeepDream psychodelic image generator.
Python
39
star
16

sliding_puzzle

Swift implementation of the Sliding Puzzle game with Iterative Deepening A* AI Solver.
Swift
35
star
17

street_lanes_finder

Street lanes finder for self-driving cars๐Ÿš—.
Jupyter Notebook
34
star
18

gsurma.github.io

Greg's Portfolio ๐ŸŒŽ.
HTML
31
star
19

digit_recognizer

CNN digit recognizer implemented in Keras Notebook, Kaggle/MNIST (0.995).
Jupyter Notebook
30
star
20

meta_intelligence

AI research environment for program generation.
Python
27
star
21

histopathologic_cancer_detector

CNN histopathologic tumor identifier.
Jupyter Notebook
27
star
22

mono_depth_estimator

Mono depth estimation for self-driving cars ๐Ÿš—
Jupyter Notebook
24
star
23

image_tagger

CNN multi-label image classifier ๐Ÿ–ผ๏ธ.
Jupyter Notebook
20
star
24

twitter_data_parser

Python scripts that download metadata and tweets for given users.
Python
18
star
25

prison_escape

Prisoner's Dilemma research environment.
Jupyter Notebook
16
star
26

cnn_explainer

Making CNNs interpretable.
Jupyter Notebook
15
star
27

newstagram

Simple iOS news feed app where you can customize categories and regions.
Swift
15
star
28

diffie_hellman_key_exchange

Swift implementation of classic cryptographic key exchange method.
Swift
15
star
29

prime_numbers_generator

Eratosthenes Sieve based prime numbers generator written in Swift.
Swift
11
star
30

sleepless_mac

Status bar app that prevents your mac from sleeping.
Swift
10
star
31

rpi_lcd_system_monitoring

Python scripts that display sytem data on i2c LCD screen.
Python
7
star
32

pong

iOS implementation of the classic Atari Pong game.
Swift
6
star
33

xcode_project_cleaner

Shell script that quickly cleans up xcode project.
Shell
6
star
34

game_of_life

NetLogo implementation of Conway's Game Of Life.
NetLogo
6
star
35

github_feed

Visually simple yet powerful github feed app.
Swift
4
star
36

stellar

Astronomy Photo of the Day ๐Ÿš€.
Swift
4
star
37

gsurma

3
star