Skip to content

Instantly share code, notes, and snippets.

View SkalskiP's full-sized avatar
👨‍💻
I open-source stuff

Piotr Skalski SkalskiP

👨‍💻
I open-source stuff
View GitHub Profile
@SkalskiP
SkalskiP / get_cost_value.py
Last active April 20, 2020 07:11
Calculating the value of the cost function and accuracy
def get_cost_value(Y_hat, Y):
m = Y_hat.shape[1]
cost = -1 / m * (np.dot(Y, np.log(Y_hat).T) + np.dot(1 - Y, np.log(1 - Y_hat).T))
return np.squeeze(cost)
def get_accuracy_value(Y_hat, Y):
Y_hat_ = convert_prob_into_class(Y_hat)
return (Y_hat_ == Y).all(axis=0).mean()
@SkalskiP
SkalskiP / single_layer_backward_propagation.py
Last active October 8, 2018 22:47
Single layer backward propagation step
def single_layer_backward_propagation(dA_curr, W_curr, b_curr, Z_curr, A_prev, activation="relu"):
m = A_prev.shape[1]
if activation is "relu":
backward_activation_func = relu_backward
elif activation is "sigmoid":
backward_activation_func = sigmoid_backward
else:
raise Exception('Non-supported activation function')
@SkalskiP
SkalskiP / full_backward_propagation.py
Created October 8, 2018 22:52
Full backward propagation
def full_backward_propagation(Y_hat, Y, memory, params_values, nn_architecture):
grads_values = {}
m = Y.shape[1]
Y = Y.reshape(Y_hat.shape)
dA_prev = - (np.divide(Y, Y_hat) - np.divide(1 - Y, 1 - Y_hat));
for layer_idx_prev, layer in reversed(list(enumerate(nn_architecture))):
layer_idx_curr = layer_idx_prev + 1
activ_function_curr = layer["activation"]
@SkalskiP
SkalskiP / update.py
Last active April 12, 2020 21:28
Updating parameter values
def update(params_values, grads_values, nn_architecture, learning_rate):
for layer_idx, layer in enumerate(nn_architecture):
params_values["W" + str(layer_idx)] -= learning_rate * grads_values["dW" + str(layer_idx)]
params_values["b" + str(layer_idx)] -= learning_rate * grads_values["db" + str(layer_idx)]
return params_values;
@SkalskiP
SkalskiP / train.py
Created October 11, 2018 19:56
Putting things together
def train(X, Y, nn_architecture, epochs, learning_rate):
params_values = init_layers(nn_architecture, 2)
cost_history = []
accuracy_history = []
for i in range(epochs):
Y_hat, cashe = full_forward_propagation(X, params_values, nn_architecture)
cost = get_cost_value(Y_hat, Y)
cost_history.append(cost)
accuracy = get_accuracy_value(Y_hat, Y)
@SkalskiP
SkalskiP / train_batch.py
Created November 1, 2018 10:38
Mini-batch gradient descent
def train_batch(X, Y, nn_architecture, epochs, learning_rate, batch_size = 64, verbose=False, callback=None):
params_values = init_layers(nn_architecture, 2)
cost_history = []
accuracy_history = []
# Beginning of additional code snippet
batch_number = X.shape[1] // batch_size
# Ending of additional code snippet
for i in range(epochs):
@SkalskiP
SkalskiP / setup.sh
Last active January 25, 2020 18:56
# Clone framework
git clone https://github.com/ultralytics/yolov3.git
# Enter framework catalogue [Linux/MacOS]
cd ./yolov3
# Enter framework catalogue [Windows]
dir ./yolov3
# Setup Python environment
pip install -U -r requirements.txt
4 0.360558 0.439186 0.068327 0.250741
7 0.697519 0.701205 0.078643 0.228243
3 0.198589 0.683692 0.076613 0.263441
dataset
├── class_names.txt
├── images
│ ├── image_1.png
│ ├── image_2.png
│ └── image_3.png
│ ...
└── labels
├── image_1.txt
├── image_2.txt
python3 detect.py
--source <test_sample_path>
--cfg <configuration_file_path>
--weights weights/best.py