-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data Input by MemoryDataLayer example? #1168
Comments
@longjon the people need a Python solving + MemoryDataLayer example... once our models are serenely training of course. |
The #1665 pull request should be merged to enable MemoryDataLayer for loading data from Python.
then convert it into data base
Second we should create prototxt nets specification - one for python, next for caffe test command
Second prototxt - place it into examples/cifar10/cifar10_quick_data.prototxt
The one could check how small they are differ from their origin examples/cifar10/cifar10_quick.prototxt. Third part of prerequisites it the cifar-10 training should be ran to get examples/cifar10/cifar10_quick_iter_5000.caffemodel. For more info how to do that see Caffe docs link mport numpy as np
import lmdb
import sys
sys.path.insert(0, './python') # just to import caffe python library
import caffe
import caffe.proto
import caffe.io
# init caffe classifier
net = caffe.Classifier('examples/cifar10/cifar10_quick_deploy.prototxt',
'examples/cifar10/cifar10_quick_iter_5000.caffemodel')
net.set_phase_test()
net.set_mode_cpu()
# read image from database
env = lmdb.open('examples/cifar10/test_lmdb')
with env.begin() as txn:
with txn.cursor() as curs:
for key, value in curs:
dat = value
datum = caffe.proto.caffe_pb2.Datum()
datum.ParseFromString(dat)
arr = np.array(caffe.io.datum_to_array(datum))
env.close()
# assign input
net.add_datum_vector(np.array([arr], dtype=np.float32),
np.array([0], dtype=np.float32))
# run
net._forward(0, len(net.layers) - 1)
# print result
print net.blobs[net.outputs[-1]].data.squeeze(axis=(2,3)) It will print this at the end:
At last we this print can be compared with:
However program crashes due to existence of SOFTMAX layer at the end of prototxt BUT it is still able to output the correct log, which indicates that Python and C++ versions match, Hurrray!
|
Closing as solved by the Python layer interface. With Python layers almost all of these special data format issues are moot since if you have a line of Python that can load your data you can make a Python data layer to load it too. |
Hi,
Could someone please explain how I could convert say an .csv file with 20 columns, out of which first 15 are features and last 5 are outputs into something caffe would accept?
I am trying to use the Windows version, where, it appears, hdf5 data layer has not been ported.
Using MemoryDataLayer? But how do I specify number of inputs, outputs?
Thanks,
Slawek
The text was updated successfully, but these errors were encountered: