mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00

* wip * Sat Dec 30 15:07:28 PST 2017 * log video * video doesn't work well * scenario integration * Sat Dec 30 17:30:22 PST 2017 * Sat Dec 30 17:31:05 PST 2017 * Sat Dec 30 17:31:32 PST 2017 * Sat Dec 30 17:32:16 PST 2017 * Sat Dec 30 17:34:11 PST 2017 * Sat Dec 30 17:34:50 PST 2017 * Sat Dec 30 17:35:34 PST 2017 * Sat Dec 30 17:38:49 PST 2017 * Sat Dec 30 17:40:39 PST 2017 * Sat Dec 30 17:43:00 PST 2017 * Sat Dec 30 17:43:04 PST 2017 * Sat Dec 30 17:45:56 PST 2017 * Sat Dec 30 17:46:26 PST 2017 * Sat Dec 30 17:47:02 PST 2017 * Sat Dec 30 17:51:53 PST 2017 * Sat Dec 30 17:52:54 PST 2017 * Sat Dec 30 17:56:43 PST 2017 * Sat Dec 30 18:27:07 PST 2017 * Sat Dec 30 18:27:52 PST 2017 * fix train * Sat Dec 30 18:41:51 PST 2017 * Sat Dec 30 18:54:11 PST 2017 * Sat Dec 30 18:56:22 PST 2017 * Sat Dec 30 19:05:04 PST 2017 * Sat Dec 30 19:05:23 PST 2017 * Sat Dec 30 19:11:53 PST 2017 * Sat Dec 30 19:14:31 PST 2017 * Sat Dec 30 19:16:20 PST 2017 * Sat Dec 30 19:18:05 PST 2017 * Sat Dec 30 19:18:45 PST 2017 * Sat Dec 30 19:22:44 PST 2017 * Sat Dec 30 19:24:41 PST 2017 * Sat Dec 30 19:26:57 PST 2017 * Sat Dec 30 19:40:37 PST 2017 * wip models * reward bonus * test prep * Sun Dec 31 18:45:25 PST 2017 * Sun Dec 31 18:58:28 PST 2017 * Sun Dec 31 18:59:34 PST 2017 * Sun Dec 31 19:03:33 PST 2017 * Sun Dec 31 19:05:05 PST 2017 * Sun Dec 31 19:09:25 PST 2017 * fix train * kill * add tuple preprocessor * Sun Dec 31 20:38:33 PST 2017 * Sun Dec 31 22:51:24 PST 2017 * Sun Dec 31 23:14:13 PST 2017 * Sun Dec 31 23:16:04 PST 2017 * Mon Jan 1 00:08:35 PST 2018 * Mon Jan 1 00:10:48 PST 2018 * Mon Jan 1 01:08:31 PST 2018 * Mon Jan 1 14:45:44 PST 2018 * Mon Jan 1 14:54:56 PST 2018 * Mon Jan 1 17:29:29 PST 2018 * switch to euclidean dists * Mon Jan 1 17:39:27 PST 2018 * Mon Jan 1 17:41:47 PST 2018 * Mon Jan 1 17:44:18 PST 2018 * Mon Jan 1 17:47:09 PST 2018 * Mon Jan 1 20:31:02 PST 2018 * Mon Jan 1 20:39:33 PST 2018 * Mon Jan 1 20:40:55 PST 2018 * Mon Jan 1 20:55:06 PST 2018 * Mon Jan 1 21:05:52 PST 2018 * fix env path * merge richards fix * fix hash * Mon Jan 1 22:04:00 PST 2018 * Mon Jan 1 22:25:29 PST 2018 * Mon Jan 1 22:30:42 PST 2018 * simplified reward function * add framestack * add env configs * simplify speed reward * Tue Jan 2 17:36:15 PST 2018 * Tue Jan 2 17:49:16 PST 2018 * Tue Jan 2 18:10:38 PST 2018 * add lane keeping simple mode * Tue Jan 2 20:25:26 PST 2018 * Tue Jan 2 20:30:30 PST 2018 * Tue Jan 2 20:33:26 PST 2018 * Tue Jan 2 20:41:42 PST 2018 * ppo lane keep * simplify discrete actions * Tue Jan 2 21:41:05 PST 2018 * Tue Jan 2 21:49:03 PST 2018 * Tue Jan 2 22:12:23 PST 2018 * Tue Jan 2 22:14:42 PST 2018 * Tue Jan 2 22:20:59 PST 2018 * Tue Jan 2 22:23:43 PST 2018 * Tue Jan 2 22:26:27 PST 2018 * Tue Jan 2 22:27:20 PST 2018 * Tue Jan 2 22:44:00 PST 2018 * Tue Jan 2 22:57:58 PST 2018 * Tue Jan 2 23:08:51 PST 2018 * Tue Jan 2 23:11:32 PST 2018 * update dqn reward * Thu Jan 4 12:29:40 PST 2018 * Thu Jan 4 12:30:26 PST 2018 * Update train_dqn.py * fix
96 lines
3.5 KiB
Python
96 lines
3.5 KiB
Python
from __future__ import absolute_import
|
|
from __future__ import division
|
|
from __future__ import print_function
|
|
|
|
import numpy as np
|
|
import tensorflow as tf
|
|
import tensorflow.contrib.slim as slim
|
|
from tensorflow.contrib.layers import xavier_initializer
|
|
|
|
from ray.rllib.models.catalog import ModelCatalog
|
|
from ray.rllib.models.misc import normc_initializer
|
|
from ray.rllib.models.model import Model
|
|
|
|
|
|
class CarlaModel(Model):
|
|
"""Carla model that can process the observation tuple.
|
|
|
|
The architecture processes the image using convolutional layers, the
|
|
metrics using fully connected layers, and then combines them with
|
|
further fully connected layers.
|
|
"""
|
|
|
|
def _init(self, inputs, num_outputs, options):
|
|
# Parse options
|
|
image_shape = options["custom_options"]["image_shape"]
|
|
convs = options.get("conv_filters", [
|
|
[16, [8, 8], 4],
|
|
[32, [5, 5], 3],
|
|
[32, [5, 5], 2],
|
|
[512, [10, 10], 1],
|
|
])
|
|
hiddens = options.get("fcnet_hiddens", [64])
|
|
fcnet_activation = options.get("fcnet_activation", "tanh")
|
|
if fcnet_activation == "tanh":
|
|
activation = tf.nn.tanh
|
|
elif fcnet_activation == "relu":
|
|
activation = tf.nn.relu
|
|
|
|
# Sanity checks
|
|
image_size = np.product(image_shape)
|
|
expected_shape = [image_size + 5 + 2]
|
|
assert inputs.shape.as_list()[1:] == expected_shape, \
|
|
(inputs.shape.as_list()[1:], expected_shape)
|
|
|
|
# Reshape the input vector back into its components
|
|
vision_in = tf.reshape(
|
|
inputs[:, :image_size], [tf.shape(inputs)[0]] + image_shape)
|
|
metrics_in = inputs[:, image_size:]
|
|
print("Vision in shape", vision_in)
|
|
print("Metrics in shape", metrics_in)
|
|
|
|
# Setup vision layers
|
|
with tf.name_scope("carla_vision"):
|
|
for i, (out_size, kernel, stride) in enumerate(convs[:-1], 1):
|
|
vision_in = slim.conv2d(
|
|
vision_in, out_size, kernel, stride,
|
|
scope="conv{}".format(i))
|
|
out_size, kernel, stride = convs[-1]
|
|
vision_in = slim.conv2d(
|
|
vision_in, out_size, kernel, stride,
|
|
padding="VALID", scope="conv_out")
|
|
vision_in = tf.squeeze(vision_in, [1, 2])
|
|
|
|
# Setup metrics layer
|
|
with tf.name_scope("carla_metrics"):
|
|
metrics_in = slim.fully_connected(
|
|
metrics_in, 64,
|
|
weights_initializer=xavier_initializer(),
|
|
activation_fn=activation,
|
|
scope="metrics_out")
|
|
|
|
print("Shape of vision out is", vision_in.shape)
|
|
print("Shape of metric out is", metrics_in.shape)
|
|
|
|
# Combine the metrics and vision inputs
|
|
with tf.name_scope("carla_out"):
|
|
i = 1
|
|
last_layer = tf.concat([vision_in, metrics_in], axis=1)
|
|
print("Shape of concatenated out is", last_layer.shape)
|
|
for size in hiddens:
|
|
last_layer = slim.fully_connected(
|
|
last_layer, size,
|
|
weights_initializer=xavier_initializer(),
|
|
activation_fn=activation,
|
|
scope="fc{}".format(i))
|
|
i += 1
|
|
output = slim.fully_connected(
|
|
last_layer, num_outputs,
|
|
weights_initializer=normc_initializer(0.01),
|
|
activation_fn=None, scope="fc_out")
|
|
|
|
return output, last_layer
|
|
|
|
|
|
def register_carla_model():
|
|
ModelCatalog.register_custom_model("carla", CarlaModel)
|