数据集:
UIUC Image Database for Car Detection。下载解压之后文件目录如图所示,这里我们所需的是TrainImages这个文件夹和TestImages文件夹。
The download package contains the following:
- 1050 training images (550 car and 500 non-car images)
- 170 single-scale test images, containing 200 cars at roughly the same scale as in the training images
- 108 multi-scale test images, containing 139 cars at various scales
- Evaluation files
- README file
The images are all grey-scale and are available in raw PGM format.
算法模型
采用的是CNN网络,各层参数如下所示。输入是一幅40*100*1
的灰度图片,经过多次卷积和池化之后得到1*1*1
的结果。
input : [None, 40, 100, 1]
conv-pool1 :
f : 5*5
strides : 1
nc : 6
padding : VALID
maxpool : 2
conv-pool2:
f : 5*5
strides : 1
nc : 16
padding : VALID
maxpool : 2
conv3:
f : 5*5
strides : 1
nc : 32
padding : VALID
conv4:
f : 3*18
strides : 1
nc : 64
padding : VALID
conv5:
f : 1*1
strides : 1
nc : 1
padding : VALID
output : [None, 1, 1, 1]
代码
我的文件目录组织结构:
-CarDetect
--CarDetect.py
--datas
---CarData
--models
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
#定义加载数据的函数,注意训练数据的存储位置
def load_carDats