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
#!/bin/bash | |
echo "INSTALLING SYSTEM DEPENDENCIES" | |
apt-get update -y | |
apt-get install -y wget build-essential git libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev sysstat fio | |
echo "export GOMAXPROCS=128" >> ~/.bashrc | |
echo "INSTALL ROCKSDB" | |
wget https://github.com/facebook/rocksdb/archive/v5.1.4.tar.gz | |
tar -xzvf v5.1.4.tar.gz | |
cd rocksdb-5.1.4 |
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
# This is an implementation of a basic feedforward neural network that uses stochastic gradient | |
# descent as a learning algorithm. It's adapted from an original implementation [1] that is part | |
# of a great online book on deep learning by Michael Nielsen [2]. This is basically the same class | |
# as the original implementation, it just has more explicit variable and method | |
# names, slightly different control flow, and is more heavily commented. I made these changes | |
# to help myself learn about backpropagation and because I think this adapted version | |
# would be easier to understand for people new to backprop. | |
# In addition to the Michael Nielsen book I would recommend the tutorial by Andrej Karpathy on | |
# the math behind backpropagation[3] and the YouTube series by 3Blue1Brown on deep learning [4] |
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_target_network(self): | |
q_network_theta = self.online_network.get_weights() | |
target_network_theta = self.target_network.get_weights() | |
counter = 0 | |
for q_weight, target_weight in zip(q_network_theta,target_network_theta): | |
target_weight = target_weight * (1-TAU) + q_weight * TAU | |
target_network_theta[counter] = target_weight | |
counter += 1 | |
self.target_network.set_weights(target_network_theta) |
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 experience_replay(self): | |
minibatch = random.sample(self.memory, EXPERIENCE_REPLAY_BATCH_SIZE) | |
minibatch_new_q_values = [] | |
for experience in minibatch: | |
state, action, reward, next_state, done = experience | |
state = self._reshape_state_for_net(state) | |
experience_new_q_values = self.online_network.predict(state)[0] | |
if done: |
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 act(self, state): | |
if self.epsilon > np.random.rand(): | |
# explore | |
return np.random.choice(ACTION_SPACE) | |
else: | |
# exploit - only use the online network to decide which action to take | |
# if allowed by epsilon/the exploration factor | |
state = self._reshape_state_for_net(state) | |
q_values = self.online_network.predict(state)[0] | |
return np.argmax(q_values) |
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 cv2 | |
import numpy as np | |
from tensorflow.python.keras.callbacks import EarlyStopping, ModelCheckpoint, TensorBoard | |
from train_generator import train_generator, plot_imgs_from_generator | |
from mae_callback import MAECallback | |
import config | |
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
from tensorflow.python.keras.models import Model | |
from tensorflow.python.keras.applications import ResNet50 | |
from tensorflow.python.keras.layers import Dense | |
import config | |
def get_age_model(): | |
# adapted from https://github.com/yu4u/age-gender-estimation/blob/master/age_estimation/model.py | |
age_model = ResNet50( | |
include_top=False, |
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
from keras.preprocessing.image import ImageDataGenerator | |
import pandas as pd | |
import Augmentor | |
from PIL import Image | |
import random | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import math | |
import config |
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 os | |
import cv2 | |
import dlib | |
from matplotlib import pyplot as plt | |
import numpy as np | |
import config | |
detector = dlib.get_frontal_face_detector() | |