#coding:utf-8
import os
import random
import skimage.data
import skimage.transform
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
import time
import argparse
import sys
import tempfile
from skimage import color
from PIL import Image
print (__doc__)
EPOCH_SIZE = 500
BATCH_SIZE = 40
IMAGE_SIZE =32
HIDDEN_SIZE = 256
CLASS_LABELS = 62
CROP_SIZE = 32
LEARNING_RATE = tf.Variable(0.0001, dtype=tf.float32)
train_data_dir = r"C:\Users\metro_miccall\eclipse-workspace\CNN_tensorflow\CNN_traffic\datasets\BelgiumTS\Training"
test_data_dir = r"C:\Users\metro_miccall\eclipse-workspace\CNN_tensorflow\CNN_traffic\datasets\BelgiumTS\Testing"
#参数概要
def variable_summaries(var):
with tf.name_scope('summaries'):
mean = tf.reduce_mean(var)
tf.summary.scalar('mean', mean)#平均值
with tf.name_scope('stddev'):
stddev = tf.sqrt(tf.reduce_mean(tf.square(var - mean)))
tf.summary.scalar('stddev', stddev)#标准差
tf.summary.scalar('max', tf.reduce_max(var))#最大值
tf.summary.scalar('min', tf.reduce_min(var))#最小值
tf.summary.histogram('histogram', var)#直方图
def load_datasets(data_dir,img_crop_size):
directories = [d for d in os.listdir(data_dir) if os.path.isdir(os.path.join(data_dir, d))]
#print("load_datasets directories:%s"%(directories))
images = []
labels = []
for d in directories:
label_dir = os.path.join(data_dir, d)
file_names = [os.path.join(label_dir, f) for f in os.listdir(label_dir) if f.endswith(".ppm")]
for f in file_names:
img = skimage.data.imread(f)
image = skimage.transform.resize(img, (img_crop_size,img_crop_size ))
image=color.rgb2gray(image)
images.append(image)
id = int(d)
#print("\nid:%s"%id)
labels.append(id)
return images, labels
def load_datasets_norm(data_dir,img_crop_size):
directories = [d for d in os.listdir(data_dir) if os.path.isdir(os.path.join(data_dir, d))]
#print("load_datasets directories:%s"%(directories))
images = []
labels = []
for d in directories:
label_dir = os.path.join(data_dir, d)
file_names = [os.path.join(label_dir, f) for f in os.listdir(label_dir) if f.endswith(".ppm")]
for f in file_names:
img = skimage.data.imread(f)
image = skimage.transform.resize(img, (img_crop_size,img_crop_size))
image=color.rgb2gray(image)
images.append(image)
id = int(d)
#print("\nid:%s"%id)
label =[0]*CLASS_LABELS
for i in range(CLASS_LABELS):
if i == id:
label[i] = 1
labels.append(label)
images_a = np.array(images)
images = images_a.reshape([-1,IMAGE_SIZE,IMAGE_SIZE,1])
labels_a = np.array(labels)
labels = labels_a.reshape([-1,CLASS_LABELS])
print("\nload_datasets_norm images shape:", images.shape)
print("\nload_datasets_norm labels shape:", labels.shape)
return images, labels
def display_images_and_labels(images, labels):
#print("\ndisplay_images_and_labels labels:",labels)
unique_labels = set(labels)
print("\ndisplay_images_and_labels unique_labels:%s"%(unique_labels))
plt.figure(figsize=(15, 15))
i = 1
for label in unique_labels:
image = images[labels.index(label)]
plt.subplot(8, 8, i)
plt.axis('off')
plt.title("Label {0} ({1})".format(label, labels.count(label)))
i += 1
_ = plt.imshow(image)
plt.show()
def predict_testimages(data_dir,sess,predicted_labels,images_ph,imagesize=IMAGE_SIZE):
# Load the test dataset.
pred_labels =[]
test_images, test_labels = load_datasets(data_dir,CROP_SIZE)
test_images_a = np.array(test_images)
test_images_a = test_images_a.reshape([-1,IMAGE_SIZE,IMAGE_SIZE,1])
display_images_and_labels(test_images, test_labels)
# Run predictions against the full test set.
prediction = sess.run([predicted_labels],feed_dict={images_ph: test_images_a})
#predlen = prediction.shape[1]
'''
print("predict_testimages predlen:%s"%(predlen))
testlen = len(test_labels)
print("predict_testimages testlen:%s"%(testlen))
for i in range(testlen):
predicted = prediction[i]
pred = np.argmax(predicted)
pred_labels.append(pred)
match_count = sum([int(y == y_) for y, y_ in zip(test_labels, pred_labels)])
test_len = len(test_labels)
accuracy = match_count / test_len
print("match_count: {:.3f}".format(match_count),"test_len: {:.3f}".format(test_len))
print("Accuracy: {:.3f}".format(accuracy))
print("time_duration: {:.5f}s".format(time_duration))
'''
def input_layer():
x = tf.placeholder(tf.float32, [None, IMAGE_SIZE,IMAGE_SIZE,1], name="x-input")
y_ = tf.placeholder(tf.float32, [None, CLASS_LABELS], name="y-input")
keep_prob = tf.placeholder(tf.float32)
return x,y_,keep_prob
def compute_cross_entropy(x,y):
diff = -(x * tf.log(y))
cross_entropy = tf.reduce_mean(diff)
return cross_entropy
def train_optimizer(cross_entropy):
train_opt = tf.train.AdamOptimizer(LEARNING_RATE).minimize(cross_entropy)
return train_opt
def correct_prediction(x,y):
correct_prediction = tf.equal(tf.argmax(x, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
return accuracy
def cnn_model(input_x,input_y,keep_prob):
weight1=tf.Variable(tf.truncated_normal(shape=[3,3,1,32],stddev=5e-2))
kernel1=tf.nn.conv2d(input_x,weight1,[1,1,1,1],padding='SAME')
bias1=tf.Variable(tf.constant(0.0,shape=[32]))
conv1=tf.nn.relu(tf.nn.bias_add(kernel1,bias1))
pool1=tf.nn.max_pool(conv1,ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')
weight2=tf.Variable(tf.truncated_normal(shape=[3,3,32,64],stddev=5e-2))
kernel2=tf.nn.conv2d(pool1,weight2,[1,1,1,1],padding='SAME')
bias2=tf.Variable(tf.constant(0.0,shape=[64]))
conv2=tf.nn.relu(tf.nn.bias_add(kernel2,bias2))
pool2=tf.nn.max_pool(conv2,ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')
pool2_flat = tf.reshape(pool2, [-1, 8*8*64])
weight3=tf.Variable(tf.truncated_normal(shape=[8*8*64,1024],stddev=0.04))
bias3=tf.Variable(tf.constant(0.1,shape=[1024]))
local3=tf.nn.relu(tf.matmul(pool2_flat,weight3)+bias3)
weight4=tf.Variable(tf.truncated_normal(shape=[1024,CLASS_LABELS],stddev=5e-2))
bias4=tf.Variable(tf.constant(0.1,shape=[CLASS_LABELS]))
y=tf.nn.softmax(tf.matmul(local3,weight4)+bias4)
cross_entropy = compute_cross_entropy(input_y,y)
train_opt = train_optimizer(cross_entropy)
accuracy = correct_prediction(y,input_y)
return train_opt,accuracy,y
def predict_testrandomimages(data_dir,sess,predicted_labels,images_ph,imagesize=IMAGE_SIZE):
# Load the test dataset.
images, labels = load_datasets(data_dir,CROP_SIZE)
# Pick 10 random images
sample_indexes = random.sa
没有合适的资源?快使用搜索试试~ 我知道了~
Traffic recognition.rar_shakingj2k_tensorflow_traffic_交通_神经网络
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共658个文件
ppm:616个
csv:41个
py:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 98 浏览量
2022-07-13
22:50:15
上传
评论
收藏 12.9MB RAR 举报
温馨提示
使用卷积神经网络来实现交通标志识别,其中使用tensorflow框架
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 658 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/6a7aa99d23544fe38965063dcf203f49_weixin_42664597.jpg!1)
小贝德罗
- 粉丝: 71
- 资源: 1万+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- 高分毕设-基于Python+OpenCV人脸识别考勤打卡系统源代码(95分以上).zip
- opencv项目实战:使用OpenCV实现哈哈镜效果(包含源码+说明文档+教程.zip)
- 微软运行库2024.exe
- Axure RP 9是一款专业的快速原型设计工具,安装即用
- 基于JSP+Servlet+Tomcat9.0+IDEA+Mysql实现的Javaweb图书管理系统
- Toon Boom Storyboard Pro 是一款专业的故事板制作软件,专为动画制作和影视前期制作而设计
- Serif Affinity Designer 是一款专业的矢量图形设计软件,旨在提供强大的创意工具和无与伦比的性能
- dbeaver exe安装脚本
- 基于Python+OpenCV人脸识别考勤管理系统+源代码(高分毕业设计).zip
- Photoshop 900个矢量和Photoshop画笔
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)