Prediction in Caffe - Exception: Input blob arguments do not match net inputs

后端 未结 4 1112
忘了有多久
忘了有多久 2021-02-14 02:02

I\'m using Caffe for classifying non-image data using a quite simple CNN structure. I\'ve had no problems training my network on my HDF5-data with dimensions n x 1 x 156 x 12. H

4条回答
  •  猫巷女王i
    2021-02-14 02:32

    Here is the answer from Evan Shelhamer I got on the Caffe Google Groups:

    self._inputs is indeed for the manual or "deploy" inputs as defined by the input fields in a prototxt. To run a net with data layers in through pycaffe, just call net.forward() without arguments. No need to change the definition of your train or test nets.

    See for instance code cell [10] of the Python LeNet example.

    In fact I think it's clearer in the Instant Recognition with Caffe tutorial, cell 6:

    # Feed in the image (with some preprocessing) and classify with a forward pass.
    net.blobs['data'].data[...] = transformer.preprocess('data', caffe.io.load_image(caffe_root + 'examples/images/cat.jpg'))
    out = net.forward()
    print("Predicted class is #{}.".format(out['prob'].argmax()))
    

    In other words, to generate the predicted outputs as well as their probabilities using pycaffe, once you have trained your model, you have to first feed the data layer with your input, then perform a forward pass with net.forward().


    Alternatively, as pointed out in other answers, you can use a deploy prototxt that is similar to the one you use to define the trained network but removing the input and output layers, and add the following at the beginning (obviously adapting according to your input dimension):

    name: "your_net"
    input: "data"
    input_dim: 1
    input_dim: 1
    input_dim: 1
    input_dim: 250
    

    That's what they use in the CIFAR10 tutorial.

    (pycaffe really ought to be better documented…)

提交回复
热议问题