交通路标识别(毕业设计)

2023-11-14

概述:

代码获取:可私信
在TensorFlow中实现单镜头多盒检测器(SSD),用于检测和分类交通标志。该实现能够在具有Intel Core i7-6700K的GTX 1080上实现40-45 fps。
请注意,此项目仍在进行中。现在的主要问题是模型过度拟合。

我目前正在先进行VOC2012的预培训,然后进行交通标志检测的转移学习。目前只检测到停车标志和人行横道标志。检测图像示例如下。

依赖库与代码

Skip to content
Product
Solutions
Open Source
Pricing
Search
Sign in
Sign up
georgesung
/
ssd_tensorflow_traffic_sign_detection
Public
Code
Issues
32
Pull requests
Actions
Projects
Security
Insights
ssd_tensorflow_traffic_sign_detection/inference.py /
@georgesung
georgesung Removed unused function run_inference_old()
Latest commit 88f1781 on Feb 15, 2017
 History
 1 contributor
189 lines (155 sloc)  6.08 KB

'''
Run inference using trained model
'''
import tensorflow as tf
from settings import *
from model import SSDModel
from model import ModelHelper
from model import nms
import numpy as np
from sklearn.model_selection import train_test_split
import cv2
import math
import os
import time
import pickle
from PIL import Image
import matplotlib.pyplot as plt
from moviepy.editor import VideoFileClip
from optparse import OptionParser
import glob


def run_inference(image, model, sess, mode, sign_map):
	"""
	Run inference on a given image
	Arguments:
		* image: Numpy array representing a single RGB image
		* model: Dict of tensor references returned by SSDModel()
		* sess: TensorFlow session reference
		* mode: String of either "image", "video", or "demo"
	Returns:
		* Numpy array representing annotated image
	"""
	# Save original image in memory
	image = np.array(image)
	image_orig = np.copy(image)

	# Get relevant tensors
	x = model['x']
	is_training = model['is_training']
	preds_conf = model['preds_conf']
	preds_loc = model['preds_loc']
	probs = model['probs']

	# Convert image to PIL Image, resize it, convert to grayscale (if necessary), convert back to numpy array
	image = Image.fromarray(image)
	orig_w, orig_h = image.size
	if NUM_CHANNELS == 1:
		image = image.convert('L')  # 8-bit grayscale
	image = image.resize((IMG_W, IMG_H), Image.LANCZOS)  # high-quality downsampling filter
	image = np.asarray(image)

	images = np.array([image])  # create a "batch" of 1 image
	if NUM_CHANNELS == 1:
		images = np.expand_dims(images, axis=-1)  # need extra dimension of size 1 for grayscale

	# Perform object detection
	t0 = time.time()  # keep track of duration of object detection + NMS
	preds_conf_val, preds_loc_val, probs_val = sess.run([preds_conf, preds_loc, probs], feed_dict={x: images, is_training: False})
	if mode != 'video':
		print('Inference took %.1f ms (%.2f fps)' % ((time.time() - t0)*1000, 1/(time.time() - t0)))

	# Gather class predictions and confidence values
	y_pred_conf = preds_conf_val[0]  # batch size of 1, so just take [0]
	y_pred_conf = y_pred_conf.astype('float32')
	prob = probs_val[0]

	# Gather localization predictions
	y_pred_loc = preds_loc_val[0]

	# Perform NMS
	boxes = nms(y_pred_conf, y_pred_loc, prob)
	if mode != 'video':
		print('Inference + NMS took %.1f ms (%.2f fps)' % ((time.time() - t0)*1000, 1/(time.time() - t0)))

	# Rescale boxes' coordinates back to original image's dimensions
	# Recall boxes = [[x1, y1, x2, y2, cls, cls_prob], [...], ...]
	scale = np.array([orig_w/IMG_W, orig_h/IMG_H, orig_w/IMG_W, orig_h/IMG_H])
	if len(boxes) > 0:
		boxes[:, :4] = boxes[:, :4] * scale

	# Draw and annotate boxes over original image, and return annotated image
	image = image_orig
	for box in boxes:
		# Get box parameters
		box_coords = [int(round(x)) for x in box[:4]]
		cls = int(box[4])
		cls_prob = box[5]

		# Annotate image
		image = cv2.rectangle(image, tuple(box_coords[:2]), tuple(box_coords[2:]), (0,255,0))
		label_str = '%s %.2f' % (sign_map[cls], cls_prob)
		image = cv2.putText(image, label_str, (box_coords[0], box_coords[1]), 0, 0.5, (0,255,0), 1, cv2.LINE_AA)

	return image


def generate_output(input_files, mode):
	"""
	Generate annotated images, videos, or sample images, based on mode
	"""
	# First, load mapping from integer class ID to sign name string
	sign_map = {}
	with open('signnames.csv', 'r') as f:
		for line in f:
			line = line[:-1]  # strip newline at the end
			sign_id, sign_name = line.split(',')
			sign_map[int(sign_id)] = sign_name
	sign_map[0] = 'background'  # class ID 0 reserved for background class

	# Create output directory 'inference_out/' if needed
	if mode == 'image' or mode == 'video':
		if not os.path.isdir('./inference_out'):
			try:
				os.mkdir('./inference_out')
			except FileExistsError:
				print('Error: Cannot mkdir ./inference_out')
				return

	# Launch the graph
	with tf.Graph().as_default(), tf.Session() as sess:
		# "Instantiate" neural network, get relevant tensors
		model = SSDModel()

		# Load trained model
		saver = tf.train.Saver()
		print('Restoring previously trained model at %s' % MODEL_SAVE_PATH)
		saver.restore(sess, MODEL_SAVE_PATH)

		if mode == 'image':
			for image_file in input_files:
				print('Running inference on %s' % image_file)
				image_orig = np.asarray(Image.open(image_file))
				image = run_inference(image_orig, model, sess, mode, sign_map)

				head, tail = os.path.split(image_file)
				plt.imsave('./inference_out/%s' % tail, image)
			print('Output saved in inference_out/')

		elif mode == 'video':
			for video_file in input_files:
				print('Running inference on %s' % video_file)
				video = VideoFileClip(video_file)
				video = video.fl_image(lambda x: run_inference(x, model, sess, mode, sign_map))

				head, tail = os.path.split(video_file)
				video.write_videofile('./inference_out/%s' % tail, audio=False)
			print('Output saved in inference_out/')

		elif mode == 'demo':
			print('Demo mode: Running inference on images in sample_images/')
			image_files = os.listdir('sample_images/')

			for image_file in image_files:
				print('Running inference on sample_images/%s' % image_file)
				image_orig = np.asarray(Image.open('sample_images/' + image_file))
				image = run_inference(image_orig, model, sess, mode, sign_map)
				plt.imshow(image)
				plt.show()

		else:
			raise ValueError('Invalid mode: %s' % mode)


if __name__ == '__main__':
	# Configure command line options
	parser = OptionParser()
	parser.add_option('-i', '--input_dir', dest='input_dir',
		help='Directory of input videos/images (ignored for "demo" mode). Will run inference on all videos/images in that dir')
	parser.add_option('-m', '--mode', dest='mode', default='image',
		help='Operating mode, could be "image", "video", or "demo"; "demo" mode displays annotated images from sample_images/')

	# Get and parse command line options
	options, args = parser.parse_args()

	input_dir = options.input_dir
	mode = options.mode

	if mode != 'video' and mode != 'image' and mode != 'demo':
		assert ValueError('Invalid mode: %s' % mode)

	if mode != 'demo':
		input_files = glob.glob(input_dir + '/*.*')
	else:
		input_files = []

	generate_output(input_files, mode)


Python 3.5+
TensorFlow v0.12.0
Pickle
OpenCV Python
Matplotlib(可选)

运用

将此存储库克隆到某处,让我们将其称为$ROOT
从头开始训练模型:
在这里插入图片描述
在这里插入图片描述

代码流程

※Download the LISA Traffic Sign Dataset, and store it in a directory $LISA_DATA
※cd $LISA_DATA
※Follow instructions in the LISA Traffic Sign Dataset to create 'mergedAnnotations.csv' such that only stop signs and pedestrian ※crossing signs are shown
※cp $ROOT/data_gathering/create_pickle.py $LISA_DATA
※python create_pickle.py
※cd $ROOT
※ln -s $LISA_DATA/resized_images_* .
※ln -s $LISA_DATA/data_raw_*.p .
※python data_prep.py
※This performs box matching between ground-truth boxes and default ※boxes, and packages the data into a format used later in the ※pipeline
※python train.py
※This trains the SSD model
※python inference.py -m demo


效果

如上所述,该SSD实现能够在具有Intel Core i7 6700K的GTX 1080上实现40-45 fps。
推理时间是神经网络推理时间和非最大抑制(NMS)时间的总和。总的来说,神经网络推断时间明显小于NMS时间,神经网络推理时间通常在7-8ms之间,而NMS时间在15-16ms之间。这里实现的NMS算法尚未优化,仅在CPU上运行,因此可以在那里进一步努力提高性能。
在这里插入图片描述
在这里插入图片描述

数据集

整个LISA交通标志数据集由47个不同的交通标志类别组成。因为我们只关注这些类的子集,所以我们只使用LISA数据集的子集。此外,我们忽略了没有找到匹配的默认框的所有训练样本,从而进一步减小了数据集的大小。由于这个过程,我们最终只能处理很少的数据。
为了改进这一问题,我们可以执行图像数据增强,和/或在更大的数据集上预训练模型(例如VOC2012、ILSVRC)
下载链接:](https://cvrr.ucsd.edu/LISA/lisa-traffic-sign-dataset.html)

代码可私信
代码可私信
代码可私信

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

交通路标识别(毕业设计) 的相关文章

  • 传统目标检测方法研究(一)

    1 传统算法目标检测 区域选择 gt 特征提取 gt 特征分类 1 1 区域选择 python 实现 图像滑动窗口 区域选取 首先选取图像中可能出现物体的位置 由于物体位置 大小都不固定 因此传统算法通常使用滑动窗口 Sliding Win
  • 目标检测之YOLOv1算法分析

    网络结构 卷积层 池化层 全连接层 输入 448 448 448 448 448 448大小的图片 输出 7 7
  • 使用Stable Diffusion图像修复来生成自己的目标检测数据集

    点击上方 AI公园 关注公众号 选择加 星标 或 置顶 作者 R dig par Gabriel Guerin 编译 ronghuaiyang 导读 有些情况下 收集各种场景下的数据很困难 本文给出了一种方法 深度学习模型需要大量的数据才能
  • yolo v3 fatal : Memory allocation failure

    torch版的 yolov3报错 fatal Memory allocation failure parser add argument n cpu type int default 8 help number of cpu threads
  • 【目标检测】32、让你一文看懂且看全 NMS 及其变体

    文章目录 一 NMS 1 1 背景 1 2 方法 1 3 代码 1 4 不足 二 Soft NMS 2 1 背景 2 2 方法 2 3 效果 2 4 代码 2 5 不足 三 Softer NMS 3 1 背景 3 2 方法 四 IoU Ne
  • 基于51单片机汽车胎压温度监测报警系统(程序+仿真+原理图+元件清单)

    功能介绍 采用51单片机作为主控单片机 通过采集传感器的胎压和DS18b20的温度 显示到LCD1602上面 并且可以通过按键设置温度和压力的阈值 超过此值蜂鸣器进行报警 可以及时的提醒驾驶员胎压或者温度异常 程序采用keil编写 并且有中
  • 基于深度学习实现实时视频目标检测

    前言 实时视频目标检测是计算机视觉领域的研究热点之一 其应用场景包括智能监控 自动驾驶 机器人视觉等多个领域 深度学习技术的快速发展使得实时视频目标检测变得更加可行和准确 本文提出一种基于深度学习实现的实时视频目标检测系统 使用Python
  • SimMIM:一种更简单的MIM方法

    自从何恺明的MAE 点击蓝字查看文章详情 出来之后 基于MIM Masked Image Modeling 的无监督学习方法越来越受到关注 这里介绍一篇和MAE同期的工作 SimMIM A Simple Framework for Mask
  • 如何在linux系统下创建空白文本.txt文件

    如何在linux系统下创建空白文本 txt文件 跳转到要新建文本的目录下 打开终端 输入命令 最后 跳转到要新建文本的目录下 可利用cd命令在终端跳转 或者直接到要新建文件的目录文件夹中 打开终端 输入命令 touch 文本名 txt 例如
  • 【pytorch目标检测】创新之作:Fast R-CNN算法解读

    背景 2015年 提出了Fast RCNN算法 训练步骤实现端到端 CNN 基于VGG6 Fast R CNN是基于R CNN和SPPnets进行的改进 成果 训练速度比RCNN块9倍 测试速度快乐23倍 准确率68 4 SPPnets网络
  • 项目设计:基于YOLO目标检测算法的安全帽/口罩/汽车/行人/交通标志...检测

    本文将详细介绍YOLO目标检测算法 该算法支持各种目标检测 包括 安全帽 汽车 造价 交通标志 等 其他毕业设计题目推荐参考 毕业设计 电子 通信 计算机 物联网专业毕业设计选题参考 嵌入式linux 单片机STM32 web 图像 htt
  • 目标检测算法改进系列之添加变核卷积AKConv模块

    AKConv变核卷积 KConv的主要思想 AKConv 可变核卷积 主要提供一种灵活的卷积机制 允许卷积核具有任意数量的参数和采样形状 这种方法突破了传统卷积局限于固定局部窗口和固定采样形状的限制 从而使得卷积操作能够更加精准地适应不同数
  • Far3D:直接干到150m,视觉3D目标检测新思路(AAAI2024)

    点击下方 卡片 关注 自动驾驶之心 公众号 ADAS巨卷干货 即可获取 gt gt 点击进入 自动驾驶之心 3D目标检测 技术交流群 论文作者 自动驾驶Daily 编辑 自动驾驶之心 近来在 Arxiv 读到一篇纯视觉环视感知的新工作 它延
  • 车载以太网-DoIP

    文章目录 车载以太网DoIP协议 Diagnostics over Internet Protocol DoIP协议的报文格式 DoIP报文类型 DoIP协议的完整流程 车载以太网DoIP协议 Diagnostics over Intern
  • 热烈祝贺怿星科技荣获高工智能汽车产业链TOP100奖

    2023 第七届 高工智能汽车年会 2023 12 14 2023年12月14日 以 寻找拐点 为主题的2023 第七届 高工智能汽车年会在上海隆重举行 怿星科技受邀参加本次会议 并获得智能汽车产业链TOP100创新企业奖 创新企业TOP1
  • 汽车UDS诊断——SecureDataTransmission 加密数据传输(0x84)

    诊断协议那些事儿 诊断协议那些事儿专栏系列文章 本文介绍诊断和通讯管理功能单元下的84服务SecureDataTransmission 在常规诊断通信中 数据极易被第三方获取 所以在一些特殊的数据传输时 标准定义了加密数据传输的服务 简而言
  • ASAM CEO Marius Dupuis 到访深信科创

    2023年12月14日 自动化及测量系统标准协会 以下简称 ASAM 首席执行官CEO Marius Dupuis 到访深信科创研发中心 参观深信科创在CARLA社区 Synkrotron OasisSim商业仿真平台建设方面的成果 并与深
  • <sa8650>sa8650 CDT-之-汽车CDT配置用户指南(下)

    sa8650 sa8650 CDT 之 汽车CDT配置用户指南 下 3 设备树 3 1 匹配CDT与DTS 3 2 修改CDT信息 以选择不同的设备树 4 CDT的使用 4 1 CDT在TZ中的使用 4 2 CDT在主机中的使用 QNX
  • Soul App:来一场始于“兴趣”,轻松自在的“零糖”社交吧

    岁末年终 回顾2023年 这一年你都做了什么呢 记不清楚没关系 互联网都帮你记录好了 2023年 B站的年轻人当 所见所闻 刷新自身认知时 往往会发送弹幕 啊 来抒发惊叹 这一年 支付宝 小荷包 的用户中00后占了4成 近一半更开启了 自动
  • 汽车改装三维扫描抄数3d数据汽车整车上门数据测绘房车改装测量

    在这个汽车改装行业日益兴起的社会 三维扫描技术正逐渐成为汽车改装领域中的一股新势力 它以其独特的优势 为汽车改装带来了前所未有的便利和精准度 CASAIM中科广电三维扫描技术能够快速 准确地获取汽车各个部位的三维数据 为改装工程师提供详细

随机推荐

  • linux usb系统【全面】

    转自 http blog csdn net ljzcom article details 8574411 1 简述 USB 出自豪门 一问世便有 IBM Microsoft compaq 等前呼后拥 不红实在是没有道理 以致于连三岁小毛孩都
  • 利用Git连接远程仓库(详细步骤)

    利用Git连接远程仓库步骤及常见问题 1 先创建一个文件夹 名字为远程仓库的名称 2 在该文件目录下打开Git Bash 3 输入git init 进行初始化 初次连接时 4 连接远程仓库 初次连接是下一次进入该文件夹就不用了 输入下列命令
  • [528]attrib隐藏文件夹

    综述 小伙伴们总要有一些秘密是不能让别人知道的 之前我们使用的设置隐藏文件夹然后在控制面板设置不显示隐藏文件夹的方式都弱爆了 下面我们来用一种更高级的办法来设置隐藏文件夹 感受一下 设置隐藏 首先我们创建一个文件夹 比如名字叫 SECRET
  • 事务的实现原理

    事务的实现 简介 特性 ACID 状态与分类 实现机制 日志机制 redo log undo log 锁机制 如何使用 简介 有许多小伙伴初学事务还不太清楚是干什么的 那么我们在简介中一次性将事务给搞懂 首先我们先来简单的说一下事务是什么
  • nmap命令使用大全,详细清晰

    一 主机发现 全面扫描 综合扫描 nmap A 192 168 1 103 Ping 扫描 nmap sP 192 168 1 1 24 免 Ping 扫描 穿透防火墙 避免被防火墙发现 nmap P0 192 168 1 103 TCP
  • QNX系统+Crank的UI设计方案-qnx的HMI方案

    锋影 e mail 174176320 qq com 今天先把QNX Acceleration Kit验证一下
  • IDEA修改文件名和类名

    结果
  • 深入理解Direct3D9

    String Of Brilliant Blue QQ群 8082814 随笔 34 文章 32 评论 136 博客园 首页 新随笔 联系 管理 深入理解Direct3D9 深入理解D3D9对图形程序员来说意义重大 我把以前的一些学习笔记都
  • 正则高级应用

    案例 最近在使用notepad 做sql格式化 select from 之间的逗号后面的数据进行换行再加一个制表符 直接一个正则表达式搞定 s from SELECT biz date SUM bigorder add consum 1m
  • 索引设计原则

    索引设计原则 代码先行 索引后上 尽量先把业务sql写完 根据sql来看看如何建索引 联合索引尽量覆盖条件 比如可以设计一个或者两三个联合索引 尽量少建单值索引 联合索引尽量覆盖 mysql一般只会选一个索引走 很多where可能只走一个
  • org.apache.shiro.authc.AuthenticationException: Authentication failed for token submission [org.apac

    本人刚接触shiro 自己进行测试 发现报错 小白一个希望大佬们多多指点 在这跟大家说一下可能不是你们的错误 但是是我的错非常稀奇 好博客的解决方法都试了不管用 最后慢慢查慢慢看 我的错是 在走进到realm时的执行dao层方法时报这个错误
  • flutter dio 请求方式为form-data遇到的问题

    在网络中请求body中有三种方式 postbody query formdata 如下图 现在我们用的恰好是第一种方式 因为首次用这种方式 感觉也是比较坑 后面通过摸索 查看源码发现 需要用fromdata方式包装进去放到请求参数中 正确的
  • 电子元器件知识---三极管

    一 三极管 三级管可以实现这样的控制 当基级没有电流时 它是截止的 而当基极有了电流 三极管就导通了 接下来 简单阐述一下 它为什么能够实现这样的功能 下图是NPN型三极管的示意图 我们知道 硅原子外面含有4个电子 纯净的硅晶体并不导电 因
  • 前端面试思维导图,面试流程注意事项

    前端面试思维导图 前端面试有着一图足矣
  • 计算机网络笔记一(计算机网络基本概念、TCP/IP协议体系)

    1 计算机网络基础概念 1 1计算机网络定义 计算机网络就是互连的 自治的计算机集合 自治 无主从关系 互连 互联互通 1 2什么是Internet Internet是最大的计算机网络 1 2 1从组成细节的角度 由很多个ISP网络互连的网
  • Jira实战

    什么是问题类型 问题类型是为了在请求之间起到简单区别的作用 范例 缺陷 任务 功能 等等 属性 名称 描述 类型 标准类型 父 或子类型 子 图标 好处 图标在筛选器 仪表盘 面板和邮件通知上提供了视觉上的区别 你可以为每一个类型设定一个标
  • 学习笔记 JavaScript ES6 ES6中的类与继承

    学习内容 类的定义 类的继承 静态属性和方法的定义 ES6中 用class关键字声明一个类 class Peple constructor name age this name name this age age showName cons
  • C++多继承构造函数调用顺序

    class B1 public B1 int i cout lt lt consB1 lt
  • python的socket通信,实现数据监听,与串口助手连接并且收发

    1 Socket通信 1 Socket原理 Socket是一种网络通信的抽象接口 用于在不同计算机之间进行进程间通信或网络通信 Socket通常基于TCP IP协议栈 通过网络套接字 socket 在网络中传输数据 它允许不同计算机之间的进
  • 交通路标识别(毕业设计)

    概述 代码获取 可私信 在TensorFlow中实现单镜头多盒检测器 SSD 用于检测和分类交通标志 该实现能够在具有Intel Core i7 6700K的GTX 1080上实现40 45 fps 请注意 此项目仍在进行中 现在的主要问题