【问题标题】:how to test mnist on my own dataset images如何在我自己的数据集图像上测试 mnist
【发布时间】:2015-06-21 22:03:57
【问题描述】:

我正在尝试使用我自己的数字图像数据集来测试 mnist。
我为此编写了一个 python 脚本,但它给出了一个错误。错误在代码的第 16 行。实际上我无法发送图像进行测试。给我一些建议。提前致谢。

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

caffe_root = '../caffe-master/'
MODEL_FILE = './examples/mnist/lenet.prototxt'
PRETRAINED = './examples/mnist/lenet_iter_10000.caffemodel'
IMAGE_FILE = '/home/hemant/OpenCVProject/grey/img001-00001.png'#image path

input_image = caffe.io.load_image(IMAGE_FILE)

net = caffe.Net(MODEL_FILE, PRETRAINED,caffe.TEST)
caffe.set_mode_cpu()
out = net.forward([input_image])
print out['prob']

【问题讨论】:

    标签: python opencv neural-network deep-learning caffe


    【解决方案1】:

    为什么不使用python包装类Classifier

    net = caffe.Classifier( MODEL_FILE, PRETRAINED )
    net.predict( [input_image], oversmaple=False )
    

    我不是 100% 确定,但我认为 LeNeT 模型需要灰度图像,您可能需要读取图像

    input_image = caffe.io.load_image(IMAGE_FILE, color=False)
    

    【讨论】:

      【解决方案2】:
      import caffe
      import os
      
      model_file = '../examples/mnist/lenet.prototxt'
      pretrained_file = '../examples/mnist/lenet_iter_10000.caffemodel'
      net = caffe.Classifier(model_file, pretrained_file, image_dims=(28, 28), raw_scale=255)
      score = net.predict([caffe.io.load_image('img/1.bmp', color=False)], oversample=False)
      print score
      

      这段代码对我有用,输出是这样的:

      ...
      [[ 0.  0.  1.  0.  0.  0.  0.  0.  0.  0.]]
      

      【讨论】:

        猜你喜欢
        • 2018-08-06
        • 1970-01-01
        • 2017-03-03
        • 2019-06-28
        • 1970-01-01
        • 2016-10-16
        • 1970-01-01
        相关资源
        最近更新 更多