自定义卷积网络完成分类。图像预处理(直方图均衡化增加对比度)。
使用数据:德国交通信号识别,其中train/test dataset的Images and annotations
及test dataset的Extended annotations including class ids
。
实验结果
数据及代码组织结构:
训练过程与结果:
代码
"""
@file: tranfficSignRec.py
@time: 2018/10/26
"""
import pandas as pd
import numpy as np
from skimage import io, color, exposure, transform
import glob
import h5py
from keras.models import Sequential, model_from_json
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.convolutional import Conv2D
from keras.layers.pooling import MaxPooling2D
from keras.optimizers import SGD
from keras.callbacks import LearningRateScheduler, ModelCheckpoint
from matplotlib import pyplot as plt
import os
from pathlib import PurePath
import warnings
warnings.filterwarnings('ignore') # 忽略警告
NUM_CLASSES = 43 # 43种交通标志
IMG_SIZE = 48 # 图像大小归一化为48
batch_size = 32 # 训练的参数
nb_epoch = 10
lr = 0.01
# 图像直方图均衡化(调整对比度)、取中心、resize
def preprocess_img(img):
hsv = color.rgb2hsv(img)
hsv[:, :, 2] = exposure.equalize_hist(hsv[:, :, 2])
img = color.hsv2rgb(hsv)
ms = min(img.shape[:2])
xx = (img.shape[0] - ms) // 2
yy = (img.shape[1] - ms) // 2
img = img[xx:xx + ms, yy:yy + ms, :]
img = transform.resize(img, (IMG_SIZE, IMG_SIZE))
return img
# 根据路