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 run(): | |
# Download pretrained vgg model | |
helper.maybe_download_pretrained_vgg(data_dir) | |
# A function to get batches | |
get_batches_fn = helper.gen_batch_function(training_dir, image_shape) | |
with tf.Session() as session: | |
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
#-------------------------- | |
# USER-SPECIFIED DATA | |
#-------------------------- | |
# Tune these parameters | |
num_classes = 2 | |
image_shape = (160, 576) | |
EPOCHS = 40 | |
BATCH_SIZE = 16 |
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 get_best_squad_n(formation, nationality, measurement = 'Overall'): | |
FIFA18_copy = FIFA18.copy() | |
FIFA18_copy = FIFA18_copy[FIFA18_copy['Nationality'] == nationality] | |
store = [] | |
for i in formation: | |
store.append([ | |
FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'].str.contains(i)][measurement].idxmax()]]['Position'].to_string(index = False), | |
FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'].str.contains(i)][measurement].idxmax()]]['Name'].to_string(index = False), | |
FIFA18_copy[FIFA18_copy['Position'].str.contains(i)][measurement].max(), |
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 get_summary_n(squad_list, squad_name, nationality_list): | |
summary = [] | |
for i in nationality_list: | |
count = 0 | |
for j in squad_list: | |
# for overall rating | |
O_temp_rating, _ = get_best_squad_n(formation = j, nationality = i, measurement = 'Overall') | |
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
class MultiplyGate: | |
def forward(self,W, x): | |
return np.dot(W, x) | |
def backward(self, W, x, dz): | |
dW = np.asarray(np.dot(np.transpose(np.asmatrix(dz)), np.asmatrix(x))) | |
dx = np.dot(np.transpose(W), dz) | |
return dW, dx | |
class AddGate: | |
def forward(self, x1, x2): |
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
class Tanh: | |
def forward(self, x): | |
return np.tanh(x) | |
def backward(self, x, top_diff): | |
output = self.forward(x) | |
return (1.0 - np.square(output)) * top_diff |
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
mulGate = MultiplyGate() | |
addGate = AddGate() | |
activation = Tanh() | |
class RNNLayer: | |
def forward(self, x, prev_s, U, W, V): | |
self.mulu = mulGate.forward(U, x) | |
self.mulw = mulGate.forward(W, prev_s) | |
self.add = addGate.forward(self.mulw, self.mulu) | |
self.s = activation.forward(self.add) |
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
class Model: | |
def __init__(self, word_dim, hidden_dim=100, bptt_truncate=4): | |
self.word_dim = word_dim | |
self.hidden_dim = hidden_dim | |
self.bptt_truncate = bptt_truncate | |
self.U = np.random.uniform(-np.sqrt(1. / word_dim), np.sqrt(1. / word_dim), (hidden_dim, word_dim)) | |
self.W = np.random.uniform(-np.sqrt(1. / hidden_dim), np.sqrt(1. / hidden_dim), (hidden_dim, hidden_dim)) | |
self.V = np.random.uniform(-np.sqrt(1. / hidden_dim), np.sqrt(1. / hidden_dim), (word_dim, hidden_dim)) |
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_propagation(self, x): | |
# The total number of time steps | |
T = len(x) | |
layers = [] | |
prev_s = np.zeros(self.hidden_dim) | |
# For each time step... | |
for t in range(T): | |
layer = RNNLayer() | |
input = np.zeros(self.word_dim) | |
input[x[t]] = 1 |
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
class Softmax: | |
def predict(self, x): | |
exp_scores = np.exp(x) | |
return exp_scores / np.sum(exp_scores) | |
def loss(self, x, y): | |
probs = self.predict(x) | |
return -np.log(probs[y]) | |
def diff(self, x, y): | |
probs = self.predict(x) | |
probs[y] -= 1.0 |