用caffe训练好的lenet_iter_10000.caffemodel测试单张mnist图片

接上个博客:http://blog.csdn.net/lanxuecc/article/details/52474476,前面已经生成了deploy.proto.txt。下面具体记录用lenet_iter_10000.caffemodel测试图片。

准备一张手写数字图片

这里写图片描述

注意在depoy.prototxt文件中指定正确的该图片的通道数。

准备一个均值文件

因为classify.py中的测试接口caffe.Classifier需要训练图片的均值文件作为输入参数,而实际lenet-5训练时并未计算均值文件,所以这里创建一个全0的均值文件输入。编写一个zeronp.py文件如下
这里写图片描述
执行

python zeronp.py

生成均值文件 meanfile.npy。
这里注意宽高要与输入测试的图片宽高一致。这里参考:https://github.com/BVLC/caffe/issues/320

修改classify.py保存为classifymnist.py文件

#!/usr/bin/env python
"""
classify.py is an out-of-the-box image classifer callable from the command line.

By default it configures and runs the Caffe reference ImageNet model.
"""
import numpy as np
import os
import sys
import argparse
import glob
import time
import pandas as pd #插入数据分析包

import caffe

def main(argv):
    pycaffe_dir = os.path.dirname(__file__)

    parser = argparse.ArgumentParser()
    # Required arguments: input and output files.
    parser.add_argument(
        "input_file",
        help="Input image, directory, or npy."
    )
    parser.add_argument(
        "output_file",
        help="Output npy filename."
    )
    # Optional arguments.
    parser.add_argument(
        "--model_def",
        default=os.path.join(pycaffe_dir,
                "../examples/mnist/deploy.prototxt"), #指定lenet-5的deploy.prototxt模型位置
        help=
  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 43
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 43
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值