Trouble calling SGDSolver from Python with MEMORY_DATA layer

1,085 views
Skip to first unread message

Tim Heidmann

unread,
Nov 9, 2014, 8:56:14 PM11/9/14
to caffe...@googlegroups.com
I'm trying to call the solver for a very simple net from within Python.  I'd like to supply the inputs and labels from Python arrays.  Here's the idea

import caffe
import numpy

my_sgd=caffe.SGDSolver('my_solver.prototext')

# solver file references a net file whose 1st layer looks like this:
# layers {
#   name: "mem_data"
#   type: MEMORY_DATA
#   top: "data"
#   top: "label"
#   memory_data_param {
#     batch_size: 10
#     channels: 4
#     height: 1
#     width: 1
#   }
# }

# numpy.shape(my_data) returns (100, 4, 1, 1)
# numpy.shape(my_labels) returns (100, 1, 1, 1)
my_sgd.net.set_input_arrays( my_data, my_labels )

my_sgd.solve()
# outputs:
# I1109 16:25:52.994668  4896 solver.cpp:160] Solving LogisticRegressionNet
# I1109 16:25:52.994711  4896 solver.cpp:247] Iteration 0, Testing net (#0)
# F1109 16:25:52.994727  4896 memory_data_layer.cpp:70] Check failed: data_ MemoryDataLayer needs to be initalized by calling Reset
# *** Check failure stack trace: ***
# Aborted (core dumped)

I know the set_input_arrays() call is having an effect, because if I change the num of the input arrays from 100 to 101, it complains that the length is not a multiple of the batch size.

What am I doing wrong?  I'm a novice with Caffe and Python, so I'm not sure I'm following the wrappings into the c++ code correctly, but I don't see anything obviously wrong.

Thanks!

Mike Mills

unread,
Dec 24, 2014, 1:35:12 AM12/24/14
to caffe...@googlegroups.com
Hi All

I'm having the same issue is there any fix for this?

Caffe_User

unread,
Dec 26, 2014, 3:59:44 AM12/26/14
to caffe...@googlegroups.com
I remember that if we want to using the Python or MATLAB wraper to call Caffe, then the net config files should be deploy version, that's say the configurations for data part like this:
name:"LeNet"
input: "data"
input_dim: 64
input_dim: 1
input_dim: 28
input_dim: 28

And the rest parts of network configs are the same as normal configuration in C+++ version.
A reference for this: https://github.com/BVLC/caffe/blob/master/examples/mnist/lenet.prototxt

Simon Klotz

unread,
Feb 2, 2016, 4:06:53 AM2/2/16
to Caffe Users
I am having the same issue. I want to train a network with input arrays and their corresponding labels. This is the code I used:

train_set_x = np.float32([[[[1.0,2.0]]]])
train_set_y = np.float32([[[[0.0]]]])
solver = caffe.get_solver('models/bvlc_reference_caffenet1/solver.prototxt')
solver.net.set_input_arrays(train_set_x ,train_set_y)
solver.solve()

and this is my MemoryData layer:

layer {
  name: "data"
  type: "MemoryData"
  top: "data"
  top: "label"
  memory_data_param {
    batch_size: 1
    channels: 1
    height: 1 
    width: 2
  }
}

If I use the deploy version of the configuration I can't specify a label for my classification. How can avoid this error and still specify the data and label?
Reply all
Reply to author
Forward
0 new messages