Skip to content

Instantly share code, notes, and snippets.

@islem-esi
islem-esi / cnn_arch.py
Created February 14, 2021 22:34
model instant
model = Sequential()
#Conv2D Layers
model.add(Conv2D(12, (25, 25), padding='same',input_shape=img_list.shape[1:], activation = 'relu'))
model.add(Conv2D(12, (25, 25), activation = 'relu'))
#Max Pooling Layer
model.add(MaxPooling2D(pool_size=(2, 2)))
#Conv2D Layer
model.add(Conv2D(12, (13, 13), padding='same', activation = 'relu'))
model.add(Conv2D(12, (13, 13), activation = 'relu'))
#Max Pooling
@islem-esi
islem-esi / prepare.py
Created February 14, 2021 22:32
prepare images for cnn
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv2D, MaxPooling2D
import numpy as np
#reshape images to fit into the CNN model
img_list = np.zeros(shape = (len(images), h,w,1), dtype = np.uint8)
for j in range(len(images)):
img_list[j,:,:,0] = np.reshape(list(images[j]), (h,w))
from os import listdir
from PIL import Image
import os.path
import numpy as np
path = 'path/to/folder/containing/exe/files'
h = 256 #height of image
w = 256 #width of image
@islem-esi
islem-esi / loop.py
Created February 14, 2021 21:32
try configs
for config in configs:
model = feed_forward_builder(config)
###
#here you can train and evaluate you model and choose best configuraiton
###
@islem-esi
islem-esi / getconifgs.py
Created February 14, 2021 21:29
build configs
configs = configs_builder(input_dim, output_dim, layers_configs, training_algorithms,
losses, dropouts, regularizers,
hidden_activations, output_activations,
callbacks, metrics, initializers)
@islem-esi
islem-esi / configinstance.py
Created February 14, 2021 21:27
config example
input_dim = 5 #input dimension for the network, adapte this to your use case
output_dim = 1 #ouput dimension
layers_configs = [[2]] #you can have multiple layers configs, if you want multiple neural networks,
#for now this example will create a neural network with one hidden layer of two nodes.
#[[10, 5]] this will create a neural network with two hidden layers of 10 and 5 nodes respectively
#[[9],[3,2]] using this will create two configurations for two different networks
#ignore the rest of parameters, they are generic, we need them so the builder works fine
training_algorithms = ['rmsprop'] #you can specify multiple training algorithms each config will have one
losses = ['binary_crossentropy'] #you can also define one or more loss functions
@islem-esi
islem-esi / feedforwardbuilder.py
Created February 14, 2021 21:18
feed forward builder function
def feed_forward_builder(config):
input_layer = Input(shape=(config['layers']['input dim'],1), dtype = config['layers']['dtype'], name = 'InputLayer')
if config['layers']['number'] == 0:
print('No Hidden Layers')
else:
layer = Dense(config['layers']['dims'][0],
dtype = config['layers']['dtype'],
name = config['layers']['names'][0],
activation = config['layers']['activations'][0],
kernel_initializer = config['layers']['initializers'][0],
@islem-esi
islem-esi / configbuilder.py
Created February 14, 2021 21:16
build config
def configs_builder(input_dim, output_dim, layers_configs, training_algorithms,
losses, dropouts, regularizers,
hidden_activations, output_activations,
callbacks, metrics, initializers):
configs = []
for layers_config in layers_configs:
for training_algorithm in training_algorithms:
for loss in losses:
for dropout in dropouts:
for regularizer in regularizers_v:
@islem-esi
islem-esi / importsfnn.py
Created February 14, 2021 21:12
imports for fnn
import keras
from keras.layers import Dense, Input, Dropout
from keras.models import Model
@islem-esi
islem-esi / find_features.py
Created October 24, 2020 20:14
open and find features
#define the minimum matching keypoints to consider an object as a match
MIN_MATCH_COUNT = 10
#read the letter we are looking for
img1 = cv2.imread('a4.png',0)
#read the captcha
img2 = cv2.imread('aydpat.jpg',0) # trainImage