Commit b47c184e authored by Yuxin Wu's avatar Yuxin Wu

huber loss

parent 212cfd90
......@@ -90,7 +90,7 @@ class Evaluator(Callback):
self.output_names = output_names
def _setup_graph(self):
NR_PROC = min(multiprocessing.cpu_count() // 2, 8)
NR_PROC = min(multiprocessing.cpu_count() // 2, 20)
self.pred_funcs = [self.trainer.get_predict_func(
self.input_names, self.output_names)] * NR_PROC
......
......@@ -126,7 +126,6 @@ class SimulatorMaster(threading.Thread):
def f():
msg = self.send_queue.get()
# slow
self.s2c_socket.send_multipart(msg, copy=False)
self.send_thread = LoopThread(f)
self.send_thread.daemon = True
......@@ -142,11 +141,7 @@ class SimulatorMaster(threading.Thread):
def run(self):
self.clients = defaultdict(self.ClientState)
#cnt = 0
while True:
#cnt += 1
#if cnt % 3000 == 0:
#print_total_timer()
msg = loads(self.c2s_socket.recv(copy=False).bytes)
ident, state, reward, isOver = msg
client = self.clients[ident]
......@@ -179,7 +174,6 @@ class SimulatorMaster(threading.Thread):
def __del__(self):
self.context.destroy(linger=0)
class SimulatorProcessDF(SimulatorProcessBase):
""" A simulator which contains a forward model itself, allowing
it to produce data points directly """
......@@ -208,7 +202,6 @@ class SimulatorProcessDF(SimulatorProcessBase):
def get_data(self):
pass
class SimulatorProcessSharedWeight(SimulatorProcessDF):
""" A simulator process with an extra thread waiting for event,
and take shared weight from shm.
......
# -*- coding: utf-8 -*-
# File: summary.py
# File: stat.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import tensorflow as tf
......
......@@ -78,12 +78,16 @@ def rms(x, name=None):
return tf.sqrt(tf.reduce_mean(tf.square(x)), name=name)
return tf.sqrt(tf.reduce_mean(tf.square(x)), name=name)
def clipped_l2_loss(x, name=None):
def huber_loss(x, delta=1, name=None):
if name is None:
name = 'clipped_l2_loss'
name = 'huber_loss'
sqrcost = tf.square(x)
abscost = tf.abs(x)
return tf.select(abscost < 1, sqrcost, abscost, name=name)
return tf.reduce_sum(
tf.select(abscost < delta,
sqrcost * 0.5,
abscost * delta - 0.5 * delta ** 2),
name=name)
def get_scalar_var(name, init_value):
return tf.get_variable(name, shape=[],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment