This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dataset | |
| ├── class_names.txt | |
| ├── images | |
| │ ├── image_1.png | |
| │ ├── image_2.png | |
| │ └── image_3.png | |
| │ ... | |
| └── labels | |
| ├── image_1.txt | |
| ├── image_2.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| python3 detect.py | |
| --source <test_sample_path> | |
| --cfg <configuration_file_path> | |
| --weights weights/best.py |