This file contains 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
import numpy as np | |
def sigmoid(x): | |
s = 1. / (1 + np.exp(-x)) | |
return s |
This file contains 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 relu(x): | |
""" | |
Compute the relu of x | |
Arguments: | |
x -- A scalar or numpy array of any size. | |
Return: | |
s -- relu(x) | |
""" | |
s = np.maximum(0,x) | |
This file contains 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 softmax(x): | |
"""Compute softmax values for each sets of scores in x.""" | |
e_x = np.exp(x - np.max(x)) | |
s = e_x / e_x.sum() | |
return s |
This file contains 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
import numpy as np | |
def initialization(): | |
# ইউনপুট ভেক্টর | |
X = np.array([.10,.30,.50]).reshape(3,1) | |
# ওয়েট ম্যাট্রিক্স | |
W1 = np.array([ | |
[0.15,0.20,0.25], |
This file contains 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 compute_error(a3, Y): | |
m = Y.shape[0] | |
logprobs = np.multiply(-np.log(a3),Y) + np.multiply(-np.log(1 - a3), 1 - Y) | |
cost = 1./m * np.sum(logprobs) | |
return cost |
This file contains 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 forward_prop(x,y,w1,w2,bias1,bias2): | |
Z1 = np.dot(w1,x) + bias1 | |
A1 = sigmoid(Z1) | |
Z2 = np.dot(w2,A1) + bias2 | |
A2 = sigmoid(Z2) | |
error = compute_error(A2,y) |
This file contains 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 backward_prop(x, y, w1, w2, bias1, bias2, z1,a1,z2,a2): | |
da2 = a2 * (1-a2) | |
dz2 = (a2-y) | |
dw2 = np.multiply(a1.T, dz2) | |
db2 = dz2 | |
da1 = a1 * (1-a1) |
This file contains 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_parameters(w1,w2,bias1,bias2, dw1,dw2,dz1,dz2,db1,db2,learning_rate=0.5): | |
w1 = w1 - (learning_rate * dw1) | |
bias1 = bias1 - (learning_rate * dz1) | |
w2 = w2 - (learning_rate * dw2) | |
bias2 = bias2 - (learning_rate * dz2) | |
return w1,w2,bias1,bias2 |
This file contains 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 Network(iteration): | |
X, Y, W1, W2, b1, b2 = initialization() | |
for i in range(iteration): | |
Z1,A1,Z2,A2,error = forward_prop(X,Y,W1,W2,b1,b2) | |
da1,da2,dz1,dz2,dw1,dw2,db1,db2 = backward_prop(X, Y, W1, W2, b1, b2, Z1,A1,Z2,A2) |
This file contains 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
# Requirements: | |
# OS: Ubuntu18.04 LTS | |
# Python >= 3.8 | |
# Cuda: 10.2, | |
# CudaNN 8.1.1 | |
# Download TensorRT 7.2.3 for Linux and CUDA 10.2 from https://developer.nvidia.com/nvidia-tensorrt-7x-download for ubuntu 18.04 | |
# or from this link https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.2.3/local_repos/nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.2.3.4-ga-20210226_1-1_amd64.deb | |
# OPEN terminal |
OlderNewer