无人驾驶原理与实践书籍中代码-part1


无人驾驶原理与实践书籍中代码-part1
资源截图
代码片段和文件信息
import numpy as np
import math
from keras.initializations import normal identity
from keras.models import model_from_json
from keras.models import Sequential Model
from keras.engine.training import collect_trainable_weights
from keras.layers import Dense Flatten Input merge Lambda
from keras.optimizers import Adam
import tensorflow as tf
import keras.backend as K

HIDDEN1_UNITS = 300
HIDDEN2_UNITS = 600

class ActorNetwork(object):
    def __init__(self sess state_size action_size BATCH_SIZE TAU LEARNING_RATE):
        self.sess = sess
        self.BATCH_SIZE = BATCH_SIZE
        self.TAU = TAU
        self.LEARNING_RATE = LEARNING_RATE

        K.set_session(sess)

        #Now create the model
        self.model  self.weights self.state = self.create_actor_network(state_size action_size)   
        self.target_model self.target_weights self.target_state = self.create_actor_network(state_size action_size) 
        self.action_gradient = tf.placeholder(tf.float32[None action_size])
        self.params_grad = tf.gradients(self.model.output self.weights -self.action_gradient)
        grads = zip(self.params_grad self.weights)
        self.optimize = tf.train.AdamOptimizer(LEARNING_RATE).apply_gradients(grads)
        self.sess.run(tf.initialize_all_variables())

    def train(self states action_grads):
        self.sess.run(self.optimize feed_dict={
            self.state: states
            self.action_gradient: action_grads
        })

    def target_train(self):
        actor_weights = self.model.get_weights()
        actor_target_weights = self.target_model.get_weights()
        for i in xrange(len(actor_weights)):
            actor_target_weights[i] = self.TAU * actor_weights[i] + (1 - self.TAU)* actor_target_weights[i]
        self.target_model.set_weights(actor_target_weights)

    def create_actor_network(self state_sizeaction_dim):
        print(“Now we build the model“)
        S = Input(shape=[state_size])   
        h0 = Dense(HIDDEN1_UNITS activation=‘relu‘)(S)
        h1 = Dense(HIDDEN2_UNITS activation=‘relu‘)(h0)
        Steering = Dense(1activation=‘tanh‘init=lambda shape name: normal(shape scale=1e-4 name=name))(h1)  
        Acceleration = Dense(1activation=‘sigmoid‘init=lambda shape name: normal(shape scale=1e-4 name=name))(h1)   
        Brake = Dense(1activation=‘sigmoid‘init=lambda shape name: normal(shape scale=1e-4 name=name))(h1) 
        V = merge([SteeringAccelerationBrake]mode=‘concat‘)          
        model = Model(input=Soutput=V)
        return model model.trainable_weights S


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     779336  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-masteractormodel.h5

     文件       2682  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-masteractormodel.json

     文件       2606  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-masterActorNetwork.py

     文件        206  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-masterautostart.sh

     文件    2232192  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-mastercriticmodel.h5

     文件       2916  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-mastercriticmodel.json

     文件       2438  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-masterCriticNetwork.py

     文件       5962  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-masterddpg.py

     文件   12208354  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-masterfast.gif

     文件      11140  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-mastergym_torcs.py

     文件        159  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-masterOU.py

     文件        614  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-masterREADME.md

     文件       1119  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-masterReplayBuffer.py

     文件      23823  2016-10-11 22:25  book_code_01chapter_10DDPG-Keras-Torcs-mastersnakeoil3_gym.py

     文件       3062  2018-04-11 14:19  book_code_01chapter_2HuskyPractice-masterCMakeLists.txt

     文件        437  2018-04-11 14:19  book_code_01chapter_2HuskyPractice-masterincludehusky_high_level_controllerhusky_controller.hpp

     文件        471  2018-04-11 14:19  book_code_01chapter_2HuskyPractice-masterlaunchhigh_controller.launch

     文件       2808  2018-04-11 14:19  book_code_01chapter_2HuskyPractice-masterpackage.xml

     文件        129  2018-04-11 14:19  book_code_01chapter_2HuskyPractice-masterREADME.md

     文件       1059  2018-04-11 14:19  book_code_01chapter_2HuskyPractice-mastersrchusky_controller.cpp

     文件        403  2018-04-11 14:19  book_code_01chapter_2HuskyPractice-mastersrchusky_high_level_controller_node.cpp

     文件         30  2018-07-31 17:01  book_code_01chapter_3NDT_PCL_demo.idea.name

     文件       1775  2018-07-31 17:01  book_code_01chapter_3NDT_PCL_demo.ideacodestylesProject.xml

     文件        137  2018-07-31 17:01  book_code_01chapter_3NDT_PCL_demo.ideamisc.xml

     文件        276  2018-07-31 17:01  book_code_01chapter_3NDT_PCL_demo.ideamodules.xml

     文件         97  2018-07-31 17:01  book_code_01chapter_3NDT_PCL_demo.ideaNDT_PCL_demo.iml

     文件      13412  2018-07-31 19:18  book_code_01chapter_3NDT_PCL_demo.ideaworkspace.xml

     文件    3620143  2018-07-31 17:39  book_code_01chapter_3NDT_PCL_demouildcloud3.pcd

     文件      47246  2018-07-31 17:33  book_code_01chapter_3NDT_PCL_demouildCMakeCache.txt

     文件       2002  2018-07-31 17:33  book_code_01chapter_3NDT_PCL_demouildCMakeFiles3.5.1CMakeCCompiler.cmake

............此处省略94个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)