当前位置: 首页 > news >正文

绍兴网站建设服务网络空间安全考研

绍兴网站建设服务,网络空间安全考研,做旅游网站的设计感想,上海人才市场招聘#x1f4ad; 写在前面#xff1a;本篇是关于 OpenAI Gym-CarRacing 自动驾驶项目的博客#xff0c;面向掌握 Python 并有一定的深度强化学习基础的读者。GYM-Box2D CarRacing 是一种在 OpenAI Gym 平台上开发和比较强化学习算法的模拟环境。它是流行的 Box2D 物理引擎的一个…      写在前面本篇是关于 OpenAI Gym-CarRacing 自动驾驶项目的博客面向掌握 Python 并有一定的深度强化学习基础的读者。GYM-Box2D CarRacing 是一种在 OpenAI Gym 平台上开发和比较强化学习算法的模拟环境。它是流行的 Box2D 物理引擎的一个版本经过修改以支持模拟汽车在赛道上行驶的物理过程。本篇是 CarRacing 系列博客的代码篇提供 lane_dection 部分的完整代码。  本章目录 Ⅰ. 项目环境准备 0x00 实验说明 0x01 模板下载 Ⅱ. 代码车道检测功能的实现 0x00 引入lane_dection 部分的实现 0x01 完整代码 0x01 运行结果演示 0x02 转灰度图像cur_gray 0x03 边缘检测edge_detection 0x04 寻找边缘检测结果中的局部最大值find_maxima_gradient_rowwise OpenAI Gym-CarRacing 系列博客 Ⅰ. 项目环境准备 0x00 实验说明 Conda 安装【Python】前置Conda 安装教学 项目环境安装Gym-CarRacing 环境安装 实践目标实现一个模块化组件框架落实简化版的模块化流水线。了解基本概念并积累开发一个简单的自驱应用程序的经验。 环境选用OpenAI GYM https://www.gymlibrary.ml/我们将基于 Box2D CarRacing 实现Box2D CarRacing 基本信息如下 Action转向、加速、刹车Sensor input96x96x3​​  屏幕显示汽车的状态和路径信息 ​​ 0x01 模板下载 * 提供基础框架只需要在 TODO 位置填写代码即可 模板下载CSDN资源Box2D CarRacing lane-dection 项目模板 Ⅱ. 代码车道检测功能的实现 0x00 引入lane_dection 部分的实现 实践目标 实现一个模块化组件框架落实简化版的模块化流水线。了解基本概念并积累开发一个简单的自驱应用程序的经验。 ​​​​​​​ ​ 尝试 为汽车上方的部分找到一个好的裁剪一个好的方法来分配车道边界的边缘一个好的梯度阈值和样条平滑度的参数选择。尝试找到失败的案例。 ​ 0x01 完整代码 参考代码lane_detection.py from turtle import distance import numpy as np import matplotlib.pyplot as plt from scipy.signal import find_peaks from scipy.interpolate import splprep, splev from scipy.optimize import minimize import timeclass LaneDetection:Lane detection module using edge detection and b-spline fittingargs: cut_size (cut_size65) cut the image at the front of the carspline_smoothness (default10)gradient_threshold (default14)distance_maxima_gradient (default3)使用边缘检测和b样条拟合的车道检测模块参数cut_sizecut_size65在汽车前部剪切图像spline_smoothness默认值10gradient_threshold默认值14distance_maxima_gradient默认值3def __init__(self, cut_size65, spline_smoothness10, gradient_threshold14, distance_maxima_gradient3):self.car_position np.array([48,0])self.spline_smoothness spline_smoothnessself.cut_size cut_sizeself.gradient_threshold gradient_thresholdself.distance_maxima_gradient distance_maxima_gradientself.lane_boundary1_old 0self.lane_boundary2_old 0## 将状态图像转化为灰度图像def cut_gray(self, state_image_full):##### TODO #####This function should cut the image at the front end of the car (e.g. pixel row 65) and translate to gray scaleinput:state_image_full 96x96x3output:gray_state_image 65x96x1此功能应在汽车前端切割图像例如像素行65并转换为灰度输入状态图像完整96x96x3输出灰度_状态_图像65x96x1copy_img state_image_full[:self.cut_size, :] red, green, blue 0.2989, 0.5870, 0.1140return np.dot(copy_img[...,:3], [red, green, blue])[::-1]def edge_detection(self, gray_image):##### TODO #####In order to find edges in the gray state image, this function should derive the absolute gradients of the gray state image.Derive the absolute gradients using numpy for each pixel. To ignore small gradients, set all gradients below a threshold (self.gradient_threshold) to zero. input:gray_state_image 65x96x1output:gradient_sum 65x96x1为了在灰度图像中找到边缘该函数应导出灰度图像的绝对梯度。使用numpy为每个像素导出绝对梯度。要忽略小渐变请将阈值self.gradient_threshold以下的所有渐变设置为0。gradient np.gradient(gray_image)gradient_sum abs(gradient[0]) abs(gradient[1])gradient gradient_sum self.gradient_thresholdgradient_sum[gradient] 0return gradient_sumdef find_maxima_gradient_rowwise(self, gradient_sum):##### TODO #####This function should output arguments of local maxima for each row of the gradient image.You can use scipy.signal.find_peaks to detect maxima. Hint: Use distance argument for a better robustness.input:gradient_sum 65x96x1output:maxima (np.array) shape : (Number_maxima, 2)这个函数应该为渐变图像的每一行输出局部最大值的参数。您可以使用scipy.signal。查找峰值以检测最大值。提示使用距离参数可以获得更好的鲁棒性。# 距离参数cuz车道应至少相隔3像素# find_peaks返回x中满足所有给定条件的峰值指数。argmaxima []pixel 3 # 相隔参数i 0while (i gradient_sum.shape[0]):top, _ find_peaks(gradient_sum[i], distance pixel)argmaxima.append(top)i 1return argmaximadef find_first_lane_point(self, gradient_sum):Find the first lane_boundaries points above the car.Special cases like just detecting one lane_boundary or more than two are considered. Even though there is space for improvement ;) input:gradient_sum 65x96x1output: lane_boundary1_startpointlane_boundary2_startpointlanes_found true if lane_boundaries were found找到汽车上方的第一个车道边界点。特殊情况下如只检测一个或两个以上的车道边界。尽管还有改进的空间输入梯度_总和65x96x1输出车道边界1_起点车道边界2起点如果找到车道边界则lanes_found为true# Variable if lanes were found or notlanes_found Falserow 0# loop through the rowswhile not lanes_found:# Find peaks with min distance of at least 3 pixel argmaxima find_peaks(gradient_sum[row],distance3)[0]# if one lane_boundary is foundif argmaxima.shape[0] 1:lane_boundary1_startpoint np.array([[argmaxima[0], row]])if argmaxima[0] 48:lane_boundary2_startpoint np.array([[0, row]])else: lane_boundary2_startpoint np.array([[96, row]])lanes_found True# if 2 lane_boundaries are foundelif argmaxima.shape[0] 2:lane_boundary1_startpoint np.array([[argmaxima[0], row]])lane_boundary2_startpoint np.array([[argmaxima[1], row]])lanes_found True# if more than 2 lane_boundaries are foundelif argmaxima.shape[0] 2:# if more than two maxima then take the two lanes next to the car, regarding least squareA np.argsort((argmaxima - self.car_position[0])**2)lane_boundary1_startpoint np.array([[argmaxima[A[0]], 0]])lane_boundary2_startpoint np.array([[argmaxima[A[1]], 0]])lanes_found Truerow 1# if no lane_boundaries are foundif row self.cut_size:lane_boundary1_startpoint np.array([[0, 0]])lane_boundary2_startpoint np.array([[0, 0]])breakreturn lane_boundary1_startpoint, lane_boundary2_startpoint, lanes_founddef lane_detection(self, state_image_full):##### TODO #####This function should perform the road detection args:state_image_full [96, 96, 3]out:lane_boundary1 splinelane_boundary2 spline此功能应执行道路检测参数state_image_full [96, 96, 3]输出lane_boundary1 splinelane_boundary2 spline# to graygray_state self.cut_gray(state_image_full)# edge detection via gradient sum and thresholdinggradient_sum self.edge_detection(gray_state)maxima self.find_maxima_gradient_rowwise(gradient_sum)# first lane_boundary pointslane_boundary1_points, lane_boundary2_points, lane_found self.find_first_lane_point(gradient_sum)# if no lane was found,use lane_boundaries of the preceding step# l1 lane_boundary1_points# l2 lane_boundary2_pointsif lane_found:##### TODO ###### in every iteration: # 1- find maximum/edge with the lowest distance to the last lane boundary point # 2- append maximum to lane_boundary1_points or lane_boundary2_points# 3- delete maximum from maxima# 4- stop loop if there is no maximum left # or if the distance to the next one is too big (100)#在每次迭代中#1-查找到最后一个车道边界点的最小距离的最大/边缘#2-将最大值附加到lane_boundary1_points或lane_boondary2_point斯#3-从maxima中删除maximum#4-如果没有最大剩余# 则停止循环#或者如果到下一个的距离太大100l1 lane_boundary1_pointsl2 lane_boundary2_pointsrow 1lim 65while (row lim): max_row maxima[row]if len(max_row) 2:break#根据与先前车道预测的距离对点进行排序#此外argsort还返回可以按顺序迭代的索引#因此我们在排序后使用A[0]和B[0]arrayA, arrayB np.argsort(pow(max_row - l1[0][0], 2)), np.argsort(pow(max_row - l2[0][0], 2))p1, p2 np.array([[max_row[arrayA[0]], row]]), np.array([[max_row[arrayB[0]], row]])lane_boundary1_points, lane_boundary2_points np.append(lane_boundary1_points, p1, axis0), np.append(lane_boundary2_points, p2, axis0)l1, l2 p1, p2row 1# lane_boundary 1# lane_boundary 2##################### TODO ###### spline fitting using scipy.interpolate.splprep # and the arguments self.spline_smoothness# # if there are more lane_boundary points points than spline parameters # else use perceding spline使用 scipy.interpolate.splprep 进行样条拟合#以及自变量self.spline_splity#如果车道边界点比样条曲线参数多#否则使用perceding样条线if lane_boundary1_points.shape[0] 4 and lane_boundary2_points.shape[0] 4:# Pay attention: the first lane_boundary point might occur twice# lane_boundary 1lane_boundary1, _ splprep([lane_boundary1_points[1:,0], lane_boundary1_points[1:,1]], sself.spline_smoothness, k2)# lane_boundary 2lane_boundary2, _ splprep([lane_boundary2_points[1:,0], lane_boundary2_points[1:,1]], sself.spline_smoothness, k2)else:lane_boundary1 self.lane_boundary1_oldlane_boundary2 self.lane_boundary2_old################else:lane_boundary1 self.lane_boundary1_oldlane_boundary2 self.lane_boundary2_oldself.lane_boundary1_old lane_boundary1self.lane_boundary2_old lane_boundary2# output the splinereturn lane_boundary1, lane_boundary2def plot_state_lane(self, state_image_full, steps, fig, waypoints[]):Plot lanes and way points# evaluate spline for 6 different spline parameters.t np.linspace(0, 1, 6)lane_boundary1_points_points np.array(splev(t, self.lane_boundary1_old))lane_boundary2_points_points np.array(splev(t, self.lane_boundary2_old))plt.gcf().clear()plt.imshow(state_image_full[::-1])plt.plot(lane_boundary1_points_points[0], lane_boundary1_points_points[1]96-self.cut_size, linewidth5, colororange)plt.plot(lane_boundary2_points_points[0], lane_boundary2_points_points[1]96-self.cut_size, linewidth5, colororange)if len(waypoints):plt.scatter(waypoints[0], waypoints[1]96-self.cut_size, colorwhite)plt.axis(off)plt.xlim((-0.5,95.5))plt.ylim((-0.5,95.5))plt.gca().axes.get_xaxis().set_visible(False)plt.gca().axes.get_yaxis().set_visible(False)fig.canvas.flush_events()# t np.linspace(0, 1, 5) # t [0, 0.25, 0.5, 0.75, 1] # Interpolated_lane_boundary_points np.array(splev(t, self.lane_boundary)) 0x01 运行结果演示 cd 到 skeleton 文件夹的路径下输入 python test_lane_detection 运行代码 运行结果 GIF 0x02 转灰度图像cur_gray cut_gray 函数需要我们实现将状态图像转化为灰度图像。 参考代码 def cut_gray(self, state_image_full):copy_img state_image_full[:self.cut_size, :] red, green, blue 0.2989, 0.5870, 0.1140return np.dot(copy_img[...,:3], [red, green, blue])[::-1] 0x03 边缘检测edge_detection 参考代码 def edge_detection(self, gray_image):##### TODO #####In order to find edges in the gray state image, this function should derive the absolute gradients of the gray state image.Derive the absolute gradients using numpy for each pixel. To ignore small gradients, set all gradients below a threshold (self.gradient_threshold) to zero. input:gray_state_image 65x96x1output:gradient_sum 65x96x1gradient np.gradient(gray_image)gradient_sum abs(gradient[0]) abs(gradient[1])gradient gradient_sum self.gradient_thresholdgradient_sum[gradient] 0return gradient_sum0x04 寻找边缘检测结果中的局部最大值find_maxima_gradient_rowwise 为渐变图像的每一行输出局部最大值的参数可以使用 scipy.signal 查找峰值以检测最大值。 * 提示使用距离参数distance可以获得更好的鲁棒性。 距离参数 cuz 车道应至少相隔 3 像素find_peaks 返回 x 中满足所有给定条件的峰值指数。 参考代码 def find_maxima_gradient_rowwise(self, gradient_sum):##### TODO #####This function should output arguments of local maxima for each row of the gradient image.You can use scipy.signal.find_peaks to detect maxima. Hint: Use distance argument for a better robustness.input:gradient_sum 65x96x1output:maxima (np.array) shape : (Number_maxima, 2)argmaxima []pixel 3 # 相隔参数i 0while (i gradient_sum.shape[0]):top, _ find_peaks(gradient_sum[i], distance pixel)argmaxima.append(top)i 1return argmaximaOpenAI Gym-CarRacing 系列博客 【OpenAI】Python基于 Gym-CarRacing 的自动驾驶项目1 | 前置知识介绍 | 项目环境准备 | 手把手带你一步步实现 【OpenAI】Python基于 Gym-CarRacing 的自动驾驶项目2| 车道检测功能的实现 | 边缘检测与分配 | 样条拟合 【OpenAI】Python基于 Gym-CarRacing 的自动驾驶项目3 | 路径训练功能的实现 | 规划与决策 | 路径平滑 | 利用公式进行目标速度预测 【OpenAI】Python基于 Gym-CarRacing 的自动驾驶项目4 | 车辆控制功能的实现 | 开环控制 | 闭环控制 | 启停式控制 | PID 控制 | Stanley 控制器 ​​ [ 笔者 ]   foxny, Akam[ 更新 ]   2023.7.8recently ❌ [ 勘误 ]   /* 暂无 */[ 声明 ]   由于作者水平有限本文有错误和不准确之处在所难免本人也很想知道这些错误恳望读者批评指正 参考资料  [6] Montemerlo M, Becker J, Bhat S, et al. Junior: The Stanford entry in the Urban Challenge Slide Credit: Steven Waslander LaValle: Rapidly-exploring random trees: A new tool for path planning. Techical Report, 1998 Dolgov et al.: Practical Search Techniques in Path Planning for Autonomous Driving. STAIR, 2008. Microsoft. MSDN(Microsoft Developer Network)[EB/OL]. []. . 百度百科[EB/OL]. []. https://baike.baidu.com/. . [EB/OL]. []. https://blog.waymo.com/2021/10/the-waymo-driver-handbook-perception.html.
http://www.pierceye.com/news/272556/

相关文章:

  • 本地电脑静态网站建设游戏代理平台免费
  • 网站建设公司的成本有哪些内容wordpress admin空白
  • 高端网站建设如何收费济南行业网站建设
  • 昆明网站制作专业麦当劳订餐网站 是谁做的
  • 网站代备案公司名称网页游戏怎么搭建
  • 教师在哪些网站可以做兼职做平面的公司网站
  • php网站后台程序做游戏ppt下载网站有哪些
  • 柳州正规网站制作公司佛山企业名录黄页
  • 企业网站做备案网站换域名 百度收录
  • 平面网站模版网站建设需要的费用
  • 营销型网站案例展示如何做网赌网站
  • 商融交通建设工程有限公司网站wordpress的伪静太文件
  • 网站rar文件做sorry动图的网站
  • 有合作社做网站得不备案期间关网站吗
  • 南京城乡住房建设厅网站wordpress文章模板下载
  • 有一个做搞笑英语视频网站外贸建站优化
  • 苏州公司建设网站深圳品牌蛋糕店有哪些品牌排行
  • 手机网站建设视频教程、网站建设项目功能需求分析报告
  • 纸 技术支持 东莞网站建设wordpress 手机 自建站
  • 网站后台 搜索广告发布合同模板
  • 手机网站设计教程网站建设 职位
  • 外贸网站图片素材谷歌seo和百度seo区别
  • 龙华网站 建设深圳信科潍坊网站建设培训
  • 域名网站平台qq在线登录
  • 成都做网站建设公司网站建设公司销售技巧
  • 打开网站是iis7三亚最新发布
  • php外贸网站中山网站建设方案报价
  • 好网站建设公司开发方案广告传媒公司加盟
  • 郑州膏药网站建设石家庄seo管理
  • 做国外产品描述的网站营销wordpress