mirror of
https://github.com/wassname/ray.git
synced 2026-07-11 13:07:47 +08:00
4374ad1453
* add tf metrics * comments * fix network scopes * add doc * initial work * try with 3 virtual cpus * clean up metrics * use format string * fix trace level * back to pong * always run summary on cpu * plot intermediate and final sgd stats * add back a global step * update * add timeline * use staging area and reuse weights properly * stage at cpu * whoops, stage only the batch * clean up a bit * fix py flake * wip * create an optimizer graph per device * print timeline on 5th batch instead * print examples per second * log placement for training ops * force placement on cpu:0 * try separating weights onto different gpus * try using nccl * add cpu fallback * remove space from date * check has gpu device * fix flag config * checkpoint * wip * update * add some timing * trace loading * try cpu * revert that * remove expensive test * lint * cleanups * clean up timers * clean it up a bit * fix code for non-scalar action spaces * address some nits * fix quotes * efficient shuffling between sgd epochs
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
from __future__ import absolute_import
|
|
from __future__ import division
|
|
from __future__ import print_function
|
|
|
|
import tensorflow as tf
|
|
import tensorflow.contrib.slim as slim
|
|
|
|
import numpy as np
|
|
|
|
|
|
def normc_initializer(std=1.0):
|
|
def _initializer(shape, dtype=None, partition_info=None):
|
|
out = np.random.randn(*shape).astype(np.float32)
|
|
out *= std / np.sqrt(np.square(out).sum(axis=0, keepdims=True))
|
|
return tf.constant(out)
|
|
return _initializer
|
|
|
|
|
|
def fc_net(inputs, num_classes=10, logstd=False):
|
|
with tf.name_scope("fc_net"):
|
|
fc1 = slim.fully_connected(inputs, 128,
|
|
weights_initializer=normc_initializer(1.0),
|
|
scope="fc1")
|
|
fc2 = slim.fully_connected(fc1, 128,
|
|
weights_initializer=normc_initializer(1.0),
|
|
scope="fc2")
|
|
fc3 = slim.fully_connected(fc2, 128,
|
|
weights_initializer=normc_initializer(1.0),
|
|
scope="fc3")
|
|
fc4 = slim.fully_connected(fc3, num_classes,
|
|
weights_initializer=normc_initializer(0.01),
|
|
activation_fn=None, scope="fc4")
|
|
if logstd:
|
|
logstd = tf.get_variable(name="logstd", shape=[num_classes],
|
|
initializer=tf.zeros_initializer)
|
|
return tf.concat(1, [fc4, logstd])
|
|
else:
|
|
return fc4
|