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 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": |
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 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() |
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 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: |
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 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 |
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 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 |
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 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(): |
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 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? |
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 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 |
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 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 |
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 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) |
OlderNewer