Any simple example?
Hi,
I started with Caffe and the mnist example ran well. However, I can not understand how am I suppose to use this for my own data for a classification task. What should be the data format? Where should I specify the files? How do I see the results for a test set? All of these are not mentioned at all in the documentation. Any pointers will be appreciated, thanks.
Hi rmanor,
I'm not very knowledgeable as I just got started using Caffe as well, so folks should feel free to jump in and correct me. The documentation for the general procedure of training with your data is here: http://caffe.berkeleyvision.org/imagenet_training.html , and you will be able to do all your training by copying and modifying the files in CAFFE_ROOT_DIR/examples/imagenet, which we will call the imagenet directory. Using the imagenet architecture should yield decent out of the box results for categorizing images.
To summarize, the steps I followed to train Caffe were:
- Group your data into a training folder and a testing folder. Caffe will train on one set of images and test it's accuracy on the other set of images. Your data should be formatted to be 256x256 color jpeg files. For each set, create a text file specifying the categories that the pictures belong to. This text file is formatted like so,
/home/my_test_dir/picture-foo.jpg 0 /home/my_test_dir/picture-foo1.jpg 1
where picture-foo belongs to category 0 and picture-foo1 belongs to category 1.
- Now copy and modify
create_imagenet.shfrom the imagenet directory, changing the arguments to point to your folders and text files. Run create_imagenet.sh and it will generate training and testing leveldb directories. Caffe will work with these leveldb directories from now on. - Copy and modify
make_imagenet_mean.shfrom the imagenet directory, changing the arguments to point at your spanking new leveldb folders. This will generate mean.prototxt files that caffe uses to normalize images, improving your results. I would recommend specifying absolute paths for everything to minimize headaches. - Copy and modify imagenet_{deploy,solver,train,val}.prototxt. You'll want to change the source and mean_file parameters in imagenet_{train,val} to point to your leveldbs and your mean.prototxt files (again, absolute paths). You may also want to change the batch_size parameter based on the hardware that you'll be running caffe on. Lastly, change the solver.prototxt file to point to your newly modified train and val prototxt files! I believe you can leave deploy.prototxt alone.
- Take a step back and make sure you haven't missed anything. You will have deploy, solver, train, and val prototxt files; two image mean binaryproto files; one train_leveldb folder, and one val_leveldb folder. That's two folders and six files in total.
- You guessed it- copy and modify train_imagenet.sh! Point it to your solver prototxt file.
- Run the modified train_imagenet script. This will periodically spit out solverstate files and data files with names like caffe_train_iter_#.
- After training terminates, you can find a script in
CAFFE_ROOT_DIR/build/toolscalled test_net.bin. test_net.bin will take your val.prototxt, a caffe_train_iter_# data file, and the number of testing iterations as arguments. It will tell you how your trained network is doing.
Best of luck!
Thanks, I read imagenet example, a bit clearer. I'm trying to write some code now that converts my data into leveldb for caffe. How should I compile it? When I do g++ it doesn't find the caffee include files for some reason. Thanks.
Hi rmanor, I would recommend against writing your own code to convert your data into a leveldb. convert_imageset.bin in the CAFFE_ROOT_DIR/build/tools directory will do this for you automatically. To see how to use convert_imageset to convert your data, take a look at the contents of create_imagenet.sh in the CAFFE_ROOT_DIR/examples/imagenet directory. If you follow the first two steps in my post above and copy and modify the create_imagenet shell script, you shouldn't have to compile anything and you will save yourself a lot of time. That said, if you truly intend to write your own code to replicate or extend the functionality of convert_imageset, I'm afraid I can't help you because I've only used built in caffe tools so far.
I need to write my own code because my data isn't images... but if conver_imageset doesn't do any image processing then maybe I can use it anyway. I'll try, thanks.
What kind of data do you have? Please disregard all the instructions above if you aren't using images/this isn't for computer vision purposes. I am curious because I was under the impression that convoluted neural nets were designed to recognize visual patterns. Are you re-purposing caffe for something else?
I think convnets were designed for images, but they had success in recent years with speech, electroencephalography and more types of data. I'm looking at the source of convert_imageset and indeed it has no image-specific processing. I'll try to use it as is. Thank you. :)
- Ran
On Sat, Jun 28, 2014 at 7:24 PM, dennis-chen [email protected] wrote:
What kind of data do you have? Please disregard all the instructions above if you aren't using images/this isn't for computer vision purposes. I am curious because I was under the impression that convoluted neural nets were designed to recognize visual patterns. Are you re-purposing caffe for something else?
— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/550#issuecomment-47431804.
You could also use the HDF5 layer to save and read data.
Sergio
2014-06-28 10:11 GMT-07:00 rmanor [email protected]:
I think convnets were designed for images, but they had success in recent years with speech, electroencephalography and more types of data. I'm looking at the source of convert_imageset and indeed it has no image-specific processing. I'll try to use it as is. Thank you. :)
- Ran
On Sat, Jun 28, 2014 at 7:24 PM, dennis-chen [email protected] wrote:
What kind of data do you have? Please disregard all the instructions above if you aren't using images/this isn't for computer vision purposes. I am curious because I was under the impression that convoluted neural nets were designed to recognize visual patterns. Are you re-purposing caffe for something else?
— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/550#issuecomment-47431804.
— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/550#issuecomment-47433046.
@sguada I see that I create HDF5 files from MATLAB, cool! Any examples on how to use this type of layer? Thanks!
@sergeyk could you post a simple example using a HDF5 data layer
Thanks. Specifically I would like to now how the hdf5 should be built. I looked at the code and it seemed like there should be a dataset "data" and a dataset "label" in the same file, and Matlab wouldn't let me create that. Am I correct? Thanks.
Okay, will PR an example to master soon.
Thanks. Btw: my data doesn't have to be images, right? Just checking before I invest too much time :) Thanks.
- Ran
On Tue, Jul 1, 2014 at 11:43 PM, Sergey Karayev [email protected] wrote:
Okay, will PR an example to master soon.
— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/550#issuecomment-47707505.
Correct, it can be anything.
On Tue, Jul 1, 2014 at 1:46 PM, rmanor [email protected] wrote:
Thanks. Btw: my data doesn't have to be images, right? Just checking before I invest too much time :) Thanks.
- Ran
On Tue, Jul 1, 2014 at 11:43 PM, Sergey Karayev [email protected]
wrote:
Okay, will PR an example to master soon.
— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/550#issuecomment-47707505.
— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/550#issuecomment-47707759.
Thank you, I appreciate the help from all of you.
- Ran
On Tue, Jul 1, 2014 at 11:47 PM, Sergey Karayev [email protected] wrote:
Correct, it can be anything.
On Tue, Jul 1, 2014 at 1:46 PM, rmanor [email protected] wrote:
Thanks. Btw: my data doesn't have to be images, right? Just checking before I invest too much time :) Thanks.
- Ran
On Tue, Jul 1, 2014 at 11:43 PM, Sergey Karayev < [email protected]>
wrote:
Okay, will PR an example to master soon.
— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/550#issuecomment-47707505.
— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/550#issuecomment-47707759.
— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/550#issuecomment-47707937.
@rmanor sorry i haven't got to packaging up a notebook example, but please consider https://github.com/BVLC/caffe/blob/master/src/caffe/test/test_data/generate_sample_data.py
Running python generate_sample_data.py will generate the test hdf5 files that you're interested in.
This example creates a simple dataset and is used in https://github.com/BVLC/caffe/blob/master/src/caffe/test/test_hdf5data_layer.cpp
I am not sure how to create this example in Matlab, but it should be equally easy.
@sergeyk Thanks!
Hey, Look at the first post by dennis-chen, I used his method of using test_net.bin . That worked for me... I'm trying now to also classify by using a python script in hope that it will be easier.
- Ran
On Wed, Jul 9, 2014 at 5:02 AM, wusx11 [email protected] wrote:
@rmanor https://github.com/rmanor Hi rmanor, which step are you reaching now? I get into using caffe recently and have similar confusion... I have already use caffe to train my own data, and I have already got a .solverstate file. But I'm not sure how to use this file to classify a new input? I mean how to use the system I have already trained? Thanks!
— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/550#issuecomment-48421716.
Will be resolved by #691
The documentation link in @dennis-chen's first post is broken. I think it should be http://caffe.berkeleyvision.org/gathered/examples/imagenet.html
Thanks a lot @dennis-chen for your post. It was really helpful! Do you any similar post for testing the data? I want to test an image with the learned model using python wrapper. I am editing the classifier.py file in CAFFE_ROOT/python to classify the test image, but there are some strange errors. Any help in this regard would be really useful.