Skip to content

Instantly share code, notes, and snippets.

from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
# parameters for architecture
input_shape = (224, 224, 3)
num_classes = 6
conv_size = 32
# parameters for training
batch_size = 32
@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
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]
# 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()
@f-rumblefish
f-rumblefish / autoencoder.py
Last active March 3, 2021 07:10
Autoencoder
from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D
from keras.models import Model
input_img = Input(shape=(28, 28, 1))
x = Conv2D(32, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
@f-rumblefish
f-rumblefish / performance.csv
Last active April 5, 2020 08:37
Audio Dog/Cat Classification
Model No SMOTE & No nlpaug SMOTE & No nlpaug SMOTE & nlpaug
Naive Bayes 73.1% 81.1% 81.9%
Random Forest 73.1% 87.8% 95.9%
Gradient Boosting 79.0% 89.5% 97.3%
XGBoost 88.3% 94.1% 97.3%
@f-rumblefish
f-rumblefish / library.csv
Last active April 5, 2020 04:52
Library
Library Descritption Usage in This Project
Librosa audio analysis
scikit-learn machine learning data split/Naive Bayes
imbalanced-learn ...
nlpaug data augmentation
@f-rumblefish
f-rumblefish / AudioModel.py
Last active April 5, 2020 02:48
Audio Model Selection
# algorithm 1 ------------------------------------------------------------------
print(" Naive Bayes ... ")
from sklearn import naive_bayes
classifier = naive_bayes.GaussianNB()
nb_model = classifier.fit(X, Y)
prediction = nb_model.predict(X_test)
print(" accuracy = ", accuracy_score(Y_test, prediction))
@f-rumblefish
f-rumblefish / AudioBalancing.py
Last active April 5, 2020 02:20
Audio Balancing
# import library
from imblearn.over_sampling import SMOTE
# define the environment variable
seed = 100
k = 1
# apply SMOTE to create the new dataset
sm = SMOTE(sampling_strategy='auto', k_neighbors=k, random_state=seed)
X_res, y_res = sm.fit_resample(pd_mfcc, pd_label)
@f-rumblefish
f-rumblefish / AudioAugmentation.py
Last active April 5, 2020 02:02
Audio Augmentation
# import library
import nlpaug
import nlpaug.augmenter.audio as naa
# loudness augmenter (where file_data is the output of librosa.load)
aug = naa.LoudnessAug(factor=(2, 5))
augmented_data = aug.augment(file_data)
# MFCC feature extraction for the new data ...