SSD windows版本配置

1、参考博文中windows版本的配置流程
http://blog.youkuaiyun.com/Chen_yingpeng/article/details/59056245
http://m.blog.youkuaiyun.com/qq_14845119/article/details/53331581
2、编译生成 python 版本的 caffe ,并将其放在 site-packages目录下
3、下载 作者已经训练好的模型
http://www.cs.unc.edu/~wliu/projects/SSD/models_VGGNet_VOC0712_SSD_300x300.tar.gz
4、利用ipython notebook 验证环境配置是否正确
\caffe-master-windows-SSD\examples\ssd_detect.ipynb
修改了一下代码如下:

import numpy as np
import matplotlib.pyplot as plt
import caffe
import numpy as np


plt.rcParams['figure.figsize'] = (10, 10)
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
import caffe
caffe.set_mode_cpu()


from google.protobuf import text_format
from caffe.proto import caffe_pb2

# load PASCAL VOC labels
labelmap_file = 'E:\\deeplearning\\caffe-master-windows-b\\caffe-master\\data\\VOC0712\\labelmap_voc.prototxt'
file = open(labelmap_file, 'r')
labelmap = caffe_pb2.LabelMap()
text_format.Merge(str(file.read()), labelmap)

def get_labelname(labelmap, labels):
    num_labels = len(labelmap.item)
    labelnames = []
    if type(labels) is not list:
        labels = [labels]
    for label in labels:
        found = False
        for i in xrange(0, num_labels):
            if label == labelmap.item[i].label:
                found = True
                labelnames.append(labelmap.item[i].display_name)
                break
        assert found == True
    return labelnames


model_def = 'E:\\deeplearning\\caffe-master-windows-SSD\\models\\VGGNet\\deploy.prototxt'
model_weights = 'E:\\deeplearning\\caffe-master-windows-SSD\\models\\VGGNet\\VGG_VOC0712_SSD_300x300_iter_60000.caffemodel'

net = caffe.Net(model_def,      # defines the structure of the model
                model_weights,  # contains the trained weights
                caffe.TEST)     # use test mode (e.g., don't perform dropout)
# input preprocessing: 'data' is the name of the input blob == net.inputs[0]
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
transformer.set_transpose('data', (2, 0, 1))
transformer.set_mean('data', np.array([104,117,123])) # mean pixel
transformer.set_raw_scale('data', 255)  # the reference model operates on images in [0,255] range instead of [0,1]
transformer.set_channel_swap('data', (2,1,0))  # the reference model has channels in BGR order instead of RGB




image_resize = 300
net.blobs['data'].reshape(1,3,image_resize,image_resize)
image = caffe.io.load_image('E:\\deeplearning\\caffe-master-windows-SSD\\examples\\images\\fish-bike.jpg')
plt.imshow(image)
plt.show()



transformed_image = transformer.preprocess('data', image)
net.blobs['data'].data[...] = transformed_image

# Forward pass.
detections = net.forward()['detection_out']

# Parse the outputs.
det_label = detections[0,0,:,1]
det_conf = detections[0,0,:,2]
det_xmin = detections[0,0,:,3]
det_ymin = detections[0,0,:,4]
det_xmax = detections[0,0,:,5]
det_ymax = detections[0,0,:,6]

# Get detections with confidence higher than 0.6.
top_indices = [i for i, conf in enumerate(det_conf) if conf >= 0.5]

top_conf = det_conf[top_indices]
top_label_indices = det_label[top_indices].tolist()
top_labels = get_labelname(labelmap, top_label_indices)
top_xmin = det_xmin[top_indices]
top_ymin = det_ymin[top_indices]
top_xmax = det_xmax[top_indices]
top_ymax = det_ymax[top_indices]


colors = plt.cm.hsv(np.linspace(0, 1, 21)).tolist()

plt.imshow(image)
currentAxis = plt.gca()

for i in xrange(top_conf.shape[0]):
    xmin = int(round(top_xmin[i] * image.shape[1]))
    ymin = int(round(top_ymin[i] * image.shape[0]))
    xmax = int(round(top_xmax[i] * image.shape[1]))
    ymax = int(round(top_ymax[i] * image.shape[0]))
    score = top_conf[i]
    label = int(top_label_indices[i])
    label_name = top_labels[i]
    display_txt = '%s: %.2f'%(label_name, score)
    coords = (xmin, ymin), xmax-xmin+1, ymax-ymin+1
    color = colors[label]
    currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor=color, linewidth=2))
    currentAxis.text(xmin, ymin, display_txt, bbox={'facecolor':color, 'alpha':0.5})

这里写图片描述

通过以上验证,说明windows环境已经配置正确。

GPU版本

打开

出现错误:

caffe.NetParameter: 938:9: Message type “caffe.PriorBoxParameter” has no
field named “step”.
F0424 10:48:16.574419 8804 upgrade_proto.cpp:79] Check failed: ReadProtoFromTex
tFile(param_file, param) Failed to parse NetParameter file: D:\caffe-ssd-microso
ft\models\VGGNet\SSD_300x300\deploy.prototxt
* Check failure stack trace: *

解决方法,根据linux版本下的caffe.proto,在windows下 中对应的PriorBoxParameter参数中添加step等参数定义。

### SSD模型环境配置教程 为了成功配置SSD模型的运行环境,需综合考虑深度学习框架的支持版本、操作系统的选择以及具体依赖项的安装过程。 #### 1. 操作系统的推荐 对于深度学习项目的开发,优先选择 **Linux 系统**,因为其拥有更完善的社区支持和技术文档[^3]。如果当前使用的操作系统为 Windows,则可以通过 WSL (Windows Subsystem for Linux) 来创建一个兼容的 Linux 开发环境。 #### 2. 深度学习框架及其支持版本 SSD 模型通常基于主流的深度学习框架构建,例如 TensorFlow 和 PyTorch。以下是两种常见框架的具体支持情况: - **TensorFlow**: 建议使用 TensorFlow 的稳定版(如 v2.x),因为它提供了丰富的工具链和优化后的性能表现。确保 GPU 版本与 CUDA/cuDNN 的匹配关系正确。例如,CUDA 11.2 对应 cuDNN 8.1[^1]。 - **PyTorch**: 如果选用 PyTorch 实现 SSD 模型,则建议采用最新稳定版本(如 v1.9 或更高)。同样需要注意的是,GPU 加速功能需要适配特定版本的 CUDA 库。例如,PyTorch v1.9 推荐配合 CUDA 11.1 使用。 #### 3. 安装必要的依赖包 无论选择哪种框架,在搭建环境中都需要完成以下操作: - 安装 Python (推荐版本 >= 3.7) - 利用 pip 工具安装对应框架的核心库及相关扩展模块 ```bash pip install torch torchvision torchaudio ``` 或者针对 TensorFlow 用户, ```bash pip install tensorflow opencv-python ``` #### 4. OpenCV 的集成 由于引用提到结合 OpenCV 进行人脸检测的应用场景,因此还需要单独确认 OpenCV 是否已正确部署到目标平台之上。可以执行如下命令验证并安装缺失组件: ```python import cv2 print(cv2.__version__) ``` 若未发现该库则通过 `pip` 补充加载即可。 --- ### 总结 综上所述,SSD 模型的运行环境配置涉及多方面因素考量,包括但不限于操作系统选型、深度学习框架版本控制及额外软件栈准备等工作环节。务必参照官方指南仔细核验每一步骤中的参数设置准确性以减少潜在错误发生几率。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值