SSD windows版本配置

1、参考博文中windows版本的配置流程
http://blog.csdn.net/Chen_yingpeng/article/details/59056245
http://m.blog.csdn.net/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等参数定义。

您可以按照以下步骤配置 PyTorch 环境以使用 SSD(Single Shot MultiBox Detector): 1. 首先,确保您已经安装了 Python 和 pip。您可以在命令行中输入以下命令检查是否已正确安装: ``` python --version pip --version ``` 2. 创建一个新的虚拟环境(可选但推荐),这样可以隔离您的项目。在命令行中输入以下命令创建和激活虚拟环境: ``` python -m venv ssd_env source ssd_env/bin/activate # Linux / macOS ssd_env\Scripts\activate # Windows ``` 3. 安装 PyTorch。根据您的操作系统、CUDA 版本和 Python 版本,选择相应的安装命令。您可以在 https://pytorch.org/get-started/locally/ 页面上找到适合您的命令。 例如,如果您使用的是 Linux、CUDA 10.2 和 Python 3.7,请输入以下命令: ``` pip install torch==1.7.1+cu102 torchvision==0.8.2+cu102 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html ``` 请根据您的配置进行相应的调整。 4. 安装其他依赖项。SSD 还依赖于其他一些库,如 NumPy、OpenCV 和 matplotlib。您可以使用以下命令安装这些库: ``` pip install numpy opencv-python matplotlib ``` 5. 下载 SSD 的源代码。您可以从 GitHub 上的相关存储库中获取 SSD 的源代码。请确保您已经安装了 Git,并在命令行中输入以下命令: ``` git clone https://github.com/weiliu89/caffe.git ``` 这将克隆 SSD 源代码到当前目录。 6. 配置 SSD。进入 SSD 源代码的根目录,并根据 README 中的说明进行配置和设置。 这样,您就可以在 PyTorch 中配置 SSD 环境了。请注意,SSD 是一个复杂的模型,需要较高的计算资源和训练数据。在运行 SSD 之前,您可能需要进一步了解 SSD 的使用方法和训练流程。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值