• 大小:
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-24
  • 语言: 其他
  • 标签: 无人驾驶  

资源简介

无人驾驶原理与实践书籍中代码-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_01\chapter_10\DDPG-Keras-Torcs-master\actormodel.h5

     文件       2682  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\actormodel.json

     文件       2606  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\ActorNetwork.py

     文件        206  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\autostart.sh

     文件    2232192  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\criticmodel.h5

     文件       2916  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\criticmodel.json

     文件       2438  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\CriticNetwork.py

     文件       5962  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\ddpg.py

     文件   12208354  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\fast.gif

     文件      11140  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\gym_torcs.py

     文件        159  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\OU.py

     文件        614  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\README.md

     文件       1119  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\ReplayBuffer.py

     文件      23823  2016-10-11 22:25  book_code_01\chapter_10\DDPG-Keras-Torcs-master\snakeoil3_gym.py

     文件       3062  2018-04-11 14:19  book_code_01\chapter_2\HuskyPractice-master\CMakeLists.txt

     文件        437  2018-04-11 14:19  book_code_01\chapter_2\HuskyPractice-master\include\husky_high_level_controller\husky_controller.hpp

     文件        471  2018-04-11 14:19  book_code_01\chapter_2\HuskyPractice-master\launch\high_controller.launch

     文件       2808  2018-04-11 14:19  book_code_01\chapter_2\HuskyPractice-master\package.xml

     文件        129  2018-04-11 14:19  book_code_01\chapter_2\HuskyPractice-master\README.md

     文件       1059  2018-04-11 14:19  book_code_01\chapter_2\HuskyPractice-master\src\husky_controller.cpp

     文件        403  2018-04-11 14:19  book_code_01\chapter_2\HuskyPractice-master\src\husky_high_level_controller_node.cpp

     文件         30  2018-07-31 17:01  book_code_01\chapter_3\NDT_PCL_demo\.idea\.name

     文件       1775  2018-07-31 17:01  book_code_01\chapter_3\NDT_PCL_demo\.idea\codestyles\Project.xml

     文件        137  2018-07-31 17:01  book_code_01\chapter_3\NDT_PCL_demo\.idea\misc.xml

     文件        276  2018-07-31 17:01  book_code_01\chapter_3\NDT_PCL_demo\.idea\modules.xml

     文件         97  2018-07-31 17:01  book_code_01\chapter_3\NDT_PCL_demo\.idea\NDT_PCL_demo.iml

     文件      13412  2018-07-31 19:18  book_code_01\chapter_3\NDT_PCL_demo\.idea\workspace.xml

     文件    3620143  2018-07-31 17:39  book_code_01\chapter_3\NDT_PCL_demo\build\cloud3.pcd

     文件      47246  2018-07-31 17:33  book_code_01\chapter_3\NDT_PCL_demo\build\CMakeCache.txt

     文件       2002  2018-07-31 17:33  book_code_01\chapter_3\NDT_PCL_demo\build\CMakeFiles\3.5.1\CMakeCCompiler.cmake

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

评论

共有 条评论