Skip to content

Instantly share code, notes, and snippets.

from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, GlobalAveragePooling2D, Dense
from keras.callbacks import EarlyStopping
################################################################################
# Build the model
################################################################################
model = Sequential()
model.add(Conv2D(32, (3, 3), activation='relu', padding='same', input_shape=input_shape_img))
file_name one_hot_encoding ordered_labels ordered_categories
----------------------------------------------------------------------------------------------------
0.png [0, 1, 1, 1, 0, 0, 1, 0, 0, 0] [6, 3, 2, 1] [Shirt, Dress, Pullover, Trouser]
1.png [1, 0, 0, 0, 1, 1, 1, 0, 0, 0] [5, 4, 0, 6] [Sandal, Coat, T-shirt/top, Shirt]
2.png [1, 1, 0, 1, 0, 0, 0, 0, 0, 0] [1, 3, 0, 3] [Trouser, Dress, T-shirt/top, Dress]
3.png [0, 0, 0, 0, 0, 1, 1, 1, 0, 0] [5, 5, 7, 6] [Sandal, Sandal, Sneaker, Shirt]
@f-rumblefish
f-rumblefish / Training_Epoch15.txt
Last active June 9, 2018 13:26
Trainging for Multi-Label Classification
Train on 9000 samples, validate on 1000 samples
Epoch 1/15
9000/9000 [==============================] - 1865s 207ms/step - loss: 0.6278 - acc: 0.6629 - val_loss: 0.5947 - val_acc: 0.6845
Epoch 2/15
9000/9000 [==============================] - 1810s 201ms/step - loss: 0.5216 - acc: 0.7424 - val_loss: 0.4472 - val_acc: 0.7916
Epoch 3/15
9000/9000 [==============================] - 1789s 199ms/step - loss: 0.4024 - acc: 0.8191 - val_loss: 0.3396 - val_acc: 0.8529
Epoch 4/15
9000/9000 [==============================] - 1817s 202ms/step - loss: 0.3204 - acc: 0.8646 - val_loss: 0.3059 - val_acc: 0.8740
Epoch 5/15
MLP (3 layers, 32 neurons, 30 epochs) ...
accuracy = 0.9986 time = 14.8910531305
[[3378 0 0]
[ 0 3407 0]
[ 13 1 3201]]
Naive Bayes ...
accuracy = 0.9874 time = 1.30055759897
[[3252 0 126]
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense_1 (Dense) (None, 32) 16032
_________________________________________________________________
activation_1 (Activation) (None, 32) 0
_________________________________________________________________
dense_2 (Dense) (None, 32) 1056
_________________________________________________________________
activation_2 (Activation) (None, 32) 0
# import library from Scikit-Learn ---------------------------------------------
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix
# algorithm 1 ------------------------------------------------------------------
print(" Naive Bayes ... ")
start = timeit.default_timer()
from sklearn import naive_bayes
classifier = naive_bayes.GaussianNB()
60, 67, 63, 60, 65, 62, 60, 67, 63, 60, 65, 62, 60, 67, 63, 60, 65, 62, 60, 67, ...
@f-rumblefish
f-rumblefish / train_data.txt
Created August 5, 2017 09:32
Training Data
train( [60, 67, 63, 60, 65, 62, 60, 67, 63, 60] ) -> label( 65 )
train( [67, 63, 60, 65, 62, 60, 67, 63, 60, 65] ) -> label( 62 )
train( [63, 60, 65, 62, 60, 67, 63, 60, 65, 62] ) -> label( 60 )
train( [60, 65, 62, 60, 67, 63, 60, 65, 62, 60] ) -> label( 67 )
train( [65, 62, 60, 67, 63, 60, 65, 62, 60, 67] ) -> label( 63 )
train( [62, 60, 67, 63, 60, 65, 62, 60, 67, 63] ) -> label( 60 )
train( [60, 67, 63, 60, 65, 62, 60, 67, 63, 60] ) -> label( 65 )
train( [67, 63, 60, 65, 62, 60, 67, 63, 60, 65] ) -> label( 62 )
train( [63, 60, 65, 62, 60, 67, 63, 60, 65, 62] ) -> label( 60 )
train( [60, 65, 62, 60, 67, 63, 60, 65, 62, 60] ) -> label( 67 )
@f-rumblefish
f-rumblefish / Keras_sample.py
Last active August 4, 2017 09:56
Recurrent Neural Network (LSTM) in Keras
# Import library in Keras 1.2.0
from keras.layers.recurrent import SimpleRNN, GRU, LSTM
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.callbacks import EarlyStopping
from keras.utils.visualize_util import plot
# Define parameters
HIDDEN_SIZE = 128
BATCH_SIZE = 10
@f-rumblefish
f-rumblefish / hello_simple_player.py
Last active January 7, 2023 01:50
Using pygame to play notes
# import library ---------------------------------------------------------------
import pygame.midi
import time
# define all the constant values -----------------------------------------------
device = 0 # device number in win10 laptop
instrument = 9 # http://www.ccarh.org/courses/253/handout/gminstruments/
note_Do = 48 # http://www.electronics.dit.ie/staff/tscarff/Music_technology/midi/midi_note_numbers_for_octaves.htm
note_Re = 50
note_Me = 52