Skip to content

Instantly share code, notes, and snippets.

View joannapurosto's full-sized avatar
🐜

Joanna Purosto joannapurosto

🐜
View GitHub Profile
@joannapurosto
joannapurosto / deep_fashion_to_tfrecord.py
Created June 8, 2018 10:52
deep_fashion_to_tfrecord.py
def create_tf_example(example, path_root):
# import image
f_image = Image.open(path_root + example["image_name"])
# get width and height of image
width, height = f_image.size
# crop image randomly around bouding box within a 0.15 * bbox extra range
if FLAGS.evaluation_status != "test":
@joannapurosto
joannapurosto / instead.py
Created December 19, 2018 14:47
Example for notebook example
from IPython.core.magic import Magics, magics_class, cell_magic
import os
@magics_class
class HelloMagics(Magics):
@cell_magic
def hello(self, line='', cell=None):
print('We executed this instead')
ip = get_ipython()
@joannapurosto
joannapurosto / vh-execute.py
Created December 19, 2018 14:51
Example for notebook blog
from IPython.core.magic import Magics, magics_class, cell_magic
import os
@magics_class
class ValohaiMagics(Magics):
@cell_magic
def valohai(self, line='', cell=None):
path = os.path.expanduser('~/%s/execute.py' % project)
with open(path, 'w+') as f:
@joannapurosto
joannapurosto / dungeon_simulator.py
Last active February 12, 2019 10:17
Q-learning tutorial part 2: dungeon simulator
from enums import *
import random
class DungeonSimulator:
def __init__(self, length=5, slip=0.1, small=2, large=10):
self.length = length # Length of the dungeon
self.slip = slip # probability of 'slipping' an action
self.small = small # payout for BACKWARD action
self.large = large # payout at end of chain for FORWARD action
self.state = 0 # Start at beginning of the dungeon
from enums import *
import random
class Drunkard:
def __init__(self):
self.q_table = None
def get_next_action(self, state):
# Random walk
return FORWARD if random.random() < 0.5 else BACKWARD
@joannapurosto
joannapurosto / train.py
Last active February 12, 2019 10:24
Q-learning tutorial part 2: training code
import random
import json
import argparse
import time
from drunkard import Drunkard
from accountant import Accountant
from gambler import Gambler
from dungeon_simulator import DungeonSimulator
def main():
@joannapurosto
joannapurosto / accountant.py
Created February 12, 2019 10:22
Q-learning tutorial part 2: agent named accountant
from enums import *
import random
class Accountant:
def __init__(self):
# Spreadsheet (Q-table) for rewards accounting
self.q_table = [[0,0,0,0,0], [0,0,0,0,0]]
def get_next_action(self, state):
# Is FORWARD reward is bigger?
@joannapurosto
joannapurosto / gambler.py
Created February 12, 2019 10:27
Q learning tutorial part 2: agent named gambler
from enums import *
import random
class Gambler:
def __init__(self, learning_rate=0.1, discount=0.95, exploration_rate=1.0, iterations=10000):
self.q_table = [[0,0,0,0,0], [0,0,0,0,0]] # Spreadsheet (Q-table) for rewards accounting
self.learning_rate = learning_rate # How much we appreciate new q-value over current
self.discount = discount # How much we appreciate future reward over current
self.exploration_rate = 1.0 # Initial exploration rate
self.exploration_delta = 1.0 / iterations # Shift from exploration to explotation
@joannapurosto
joannapurosto / deep_gambler.py
Last active October 30, 2019 14:01
Q-learning tutorial part 3 and Deep Learning
from enums import *
import random
import tensorflow as tf
import numpy as np
class DeepGambler:
def __init__(self, learning_rate=0.1, discount=0.95, exploration_rate=1.0, iterations=10000):
self.learning_rate = learning_rate
self.discount = discount # How much we appreciate future reward over current
self.exploration_rate = 1.0 # Initial exploration rate
@joannapurosto
joannapurosto / simple.py
Created March 28, 2019 05:47
TensorBoard + Valohai Tutorial on Valohai blog
import tensorflow as tf
import time
tf.reset_default_graph()
myvar = tf.get_variable('myvar', shape=[])
myvar_summary = tf.summary.scalar(name='Myvar', tensor=myvar)
init = tf.global_variables_initializer()
with tf.Session() as sess:
writer = tf.summary.FileWriter('./logs/run1', sess.graph)