Closed rmanor closed 10 years ago
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:
/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.
create_imagenet.sh
from 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.make_imagenet_mean.sh
from 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. CAFFE_ROOT_DIR/build/tools
called test_net.bin. test_net.bin will take your val.prototxt, a caffe_trainiter# 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. :)
On Sat, Jun 28, 2014 at 7:24 PM, dennis-chen notifications@github.com 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 notifications@github.com:
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 notifications@github.com 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.
On Tue, Jul 1, 2014 at 11:43 PM, Sergey Karayev notifications@github.com 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 notifications@github.com 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 notifications@github.com
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.
On Tue, Jul 1, 2014 at 11:47 PM, Sergey Karayev notifications@github.com wrote:
Correct, it can be anything.
On Tue, Jul 1, 2014 at 1:46 PM, rmanor notifications@github.com 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 < notifications@github.com>
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.
On Wed, Jul 9, 2014 at 5:02 AM, wusx11 notifications@github.com 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.
@pulkit1991 , I'm very glad you found it helpful! Below are instructions I wrote on testing the learn model with the python wrapper when I was documenting this earlier this summer, hope it helps!
Compiling the python wrapper on futuregrid is a uphill battle that you will have to fight alone, brave warrior. I got the wrapper working on my personal computer but couldn't do it on futuregrid. Not a terrible thing because classification tasks don't take that much computing power once the model itself has been generated, so I'd recommend getting caffe and the python wrapper installed elsewhere if futuregrid is too tough of a nut to crack.
That said, if you import numpy and add "CAFFE_HOME_DIR/python" to your system path, you should be able to import and use caffe without a problem in your python programs. Initiating a caffe classifier looks like this:
self.net = caffe.Classifier(DEPLOY_PROTOTXT,TRAINED_NET) self.net.set_phase_test() self.net.set_mode_cpu() self.net.set_mean('data', IMAGE_MEAN) self.net.set_channel_swap('data', (2,1,0)) self.net.set_input_scale('data', 255)
As stated previously, your DEPLOY_PROTOTXT, TRAINED_NET, and IMAGE_MEAN should've been generated by training. Just plug in their file paths and caffe does the rest of the magic. To do classification on a specific image, call:
scores = self.net.predict([caffe.io.load_image(img_path)])
Where scores is a vector of length 1000. The index of a score indicates caffe's confidence that the image is of class index. For example, if scores looks like [.999,.1,...], then caffe has a high confidence that the image is of class 0. You defined the classes and labels earlier on in a text file when generating the leveldbs for training.
But I trained on 2 classes, not 1000. What's going on? Don't worry, if you copied the imagenet model, it has 1000 outputs at its final layer. Caffe is smart enough to only map to the outputs that you specified, so the vector will still map to the numbers that you used to label your classes. All the "unused" classes consistently evaluate to some obscenely small number, as expected. To eliminate this annoying but harmless result, dig into your val and train prototxt files. FC8, the inner product layer, should say that it has 1000 outputs. Change this to the relevant amount of classes that you have and you're all done. Remember that numbering starts at 0!
Hey @dennis-chen ! Thanks a lot for this help! I have a good idea now as to how to proceed. There is one small thing I would like to ask. In the MEAN_FILE file you need .npy file, but I dont have it yet for my data. I am using my own data for training and testing. What should I do for the mean file issue? Thanks.
Just found out!
Thanks! :)
Thanks for detailed tutorial! You're awesome!
btw, can you tell more about how you get DEPLOY_PROTOTXT? I cp one from caffe/models/bvlc_reference_caffenet/deploy.prototxt. I try to adjust it and use it with python wrapper you mentioned above but end up with some strange errors Any comment? Thanks!
To write a deploy.prototxt, copy this to a new file called deploy.prototxt in
name: "<the name in the train_val.prototxt>"
input: "data"
input_dim: 10
input_dim: 3
input_dim: 224 # or whatever the crop_size is in train_val.prototxt
input_dim: 224
Append to that all layers in train_val.prototxt. Delete the first few layers that don't have a "bottom" field. Delete all paramaters that have to do exclusively with learning. e.g.:
Change the value of the layer that contains a "num_output" field to the number of categories.
You guys are my hero
Better to generate the deploy.prototxt automatically, and leave it accessible.
https://github.com/BVLC/caffe/pull/1746 shows how to create HDF5 files for the HDF5_DATA_LAYER from Matlab.
Hi, In @dennis-chen's original post I could do steps 1 & 2, but after that I couldn't find any of the .prototxt files mentioned i.e. imagenet_{deploy,solver,train,val}.prototxt. Are they supposed to be generated by some script? Or should they be inside the /examples/imagenet folders by default? I don't have them. Please help.
Also the make_imagenet_mean.sh script only generated data/ilsvrc12/imagenet_mean.binaryproto file for me. Is that all it should generate? Or am I missing something?
Sorry if I sound dumb, I have just started using Caffe.
@dennis-chen could you please let me know how to include data layer( all files including mean, val, train, lmdv have been created). When I do below changes to prototxt, I am getting error "Opening file ilsvrc12_train_lmdb libc++abi.dylib: terminate called throwing an exception""…
Am I missing anything?
name: "CaffeNetConvCustom" layers { name: "images" type: IMAGE_DATA top: "data" top: "label" image_data_param { source: "custom_train_lmdb" batch_size: 4 crop_size: 227 shuffle: true } include: { phase: TRAIN } }
layers { name: "images" type: IMAGE_DATA top: "data" top: "label" image_data_param { source: "custom_val_lmdb" batch_size: 100 shuffle: true crop_size: 227
} transform_param { scale: 0.00390625 mirror: true crop_size: 227 } include: { phase: TEST } }
layer { name: "conv1" type: "Convolution" …….
amazing tutorial thanks guys
Hi Steven, thanks for getting in touch. I’m afraid that I have no clue what’s up with that error, and I haven’t used caffe in several months. I’m sure someone else on github will know though. Wishing you the best of luck Steven! Sorry I can’t help!
From: StevenLobo2 [mailto:notifications@github.com] Sent: Sunday, February 22, 2015 12:52 PM To: BVLC/caffe Cc: Dennis Chen Subject: Re: [caffe] Any simple example? (#550)
@dennis-chenhttps://github.com/dennis-chen could you please let me know how to include data layer( all files including mean, val, train, lmdv have been created). When I do below changes to prototxt, I am getting error "Opening file ilsvrc12_train_lmdb libc++abi.dylib: terminate called throwing an exception""…
Am I missing anything?
This file is for the net_surgery.ipynb example notebook.
name: "CaffeNetConvCustom" layers { name: "images" type: IMAGE_DATA top: "data" top: "label" image_data_param { source: "custom_train_lmdb" batch_size: 4 crop_size: 227 shuffle: true } include: { phase: TRAIN } }
layers { name: "images" type: IMAGE_DATA top: "data" top: "label" image_data_param { source: "custom_val_lmdb" batch_size: 100 shuffle: true crop_size: 227
} transform_param { scale: 0.00390625 mirror: true crop_size: 227 } include: { phase: TEST } }
layer { name: "conv1" type: "Convolution" …….
— Reply to this email directly or view it on GitHubhttps://github.com/BVLC/caffe/issues/550#issuecomment-75447712.
Hi guys,
I did everything exactly the way @dennis-chen explained, but my training stops at Iteration 0, with neither warnings nor errors. I am stuck with this problem for quite a while.
0409 11:36:47.162365 8707 net.cpp:217] Network initialization done.
I0409 11:36:47.162372 8707 net.cpp:218] Memory required for data: 343607608
I0409 11:36:47.162487 8707 solver.cpp:42] Solver scaffolding done.
I0409 11:36:47.162520 8707 solver.cpp:222] Solving CaffeNet
I0409 11:36:47.162528 8707 solver.cpp:223] Learning Rate Policy: step
I0409 11:36:47.162539 8707 solver.cpp:266] Iteration 0, Testing net (#0)
I have just started using Caffe, so any help would be much appreciated
Did you take a look at your log? It can be found at /tmp, with default name "[program name].[hostname].[user name].log.[severity level].[date].[time].[pid]" (e.g.caffe.HOST.USER.log.INFO.20150207-193541.13458 Otherwise, you can assign its location with the flag --log_dir=$PathWhereYouWantLogAt
HI ,I got same problem as what ZVERKA posted , when I try to use my images to train caffee imagenet example, caffee is stuck in Iteration 0, Testing net (#0) permenatly.
BR
Hi, I have was following your procedure to train my own set of images. But after running the train_caffenet.sh file it threw an error: A total of zero images. I think the problem is with imagenet_val.prototxt. Can you pls specify what should source parameter point to.
Thanks.
@abhishek9893 I have had to deal with many issues relating to the transferring of files to the data blob format. I would double check the that the solver linked by train_caffenet.sh points to the correct net prototxt file (this probably should be train_val.prototxt), and that its data layers source link to the correct lmdbs. If everything checks out there, I would remove the two lmdbs and re-run create_imagenet.sh (making sure the directories/text files are all correct). Note that if you do not delete them first, a mkdir error will be thrown and abort the process. As create_imagenet runs, check the console log, It should print that it created the val and train lmdbs, and their sizes. If that all works fine, you should be good to go. Add the paths to those lmdbs to train_val.prototxt and you should be good.
Hi!
I modified the create_imagenet.sh file in order to create my own lmdb file for the camvid database. However I can't use any of those files because the next message keeps appearing:
tools/convert_imageset: No such file or directory
Here is my code:
cd caffe EXAMPLE=examples/camvid DATA=data/camvid/rawpixels TOOLS=tools
TRAIN_DATA_ROOT=data/camvid/rawpixels
RESIZE=true if $RESIZE; then RESIZE_HEIGHT=720 RESIZE_WIDTH=960 else RESIZE_HEIGHT=0 RESIZE_WIDTH=0 fi
if [ ! -d "$TRAIN_DATA_ROOT" ]; then echo "Error: TRAIN_DATA_ROOT is not a path to a directory: $TRAIN_DATA_ROOT" echo "Set the TRAIN_DATA_ROOT variable in create_camvid.sh to the path" \ "where the Camvid training data is stored." exit 1 fi
echo "Creating train lmdb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset \ --resize_height=$RESIZE_HEIGHT \ --resize_width=$RESIZE_WIDTH \ --shuffle \ $TRAIN_DATA_ROOT \ $DATA/train2.txt \ $EXAMPLE/camvid_train_lmdb
echo "Done."
Thanks in advance
@dennis-chen I saw your reply that"But I trained on 2 classes, not 1000. What's going on?...Remember that numbering starts at 0!".Is that means if I want to train on two class, I don't need to modify train_val.prototxt, and I can ignore the other 998 classes?如果你能说中文,用中文回答的话我会非常感激的,谢谢啦~
@ctrevino Try setting TOOLS=build/tools
@JIALICHEN Everything works out fine if you ignore the others. If you check predictions later, you will see that the other classes have incredibly small/infinitesimal probabilities.
@zacharyhorvitz Thank you very much for your reply, that's make me don't so worry. Could you tell me how to check predictions?
@JIALICHEN No problem. Do you want a prediction on new individual images, your training set, or your validation set?
There are a couple ways to do it. If you add a probability layer to your net, it will output probabilities per image during training and/or testing.
Another way (maybe the best if you are looking at individual images) is via the file classifier.py. It should be in your caffe/python directory, or here: https://github.com/BVLC/caffe/blob/master/python/classify.py.
You can open it up and modify it to point to your data set and net, or add in the following arguments:
python classify.py --pretrained_model <path/to/your_model.caffemodel> --input_file <path/to/your_file.jpg> --model_def <path/to/your/deploy.prototxt> --output_file <path to a .npy file where the array will be stored>
There are a couple more optional arguments you might want to add. Unless you have a mean file to use, I would set the mean variable in classify.py = 0. One note is that I am pretty sure these are raw probability values, meaning they aren't scaled to the distribution of categories. This means that if you put a cat image in a dog or cat classifier, you may get a cat probability that is less than a dog, but much higher than usual. So, the right category may not be the one with the higher probability, rather, it may be high relative to the other.
I would check out the python documentation. It seems like a pretty good interface.
If you want to see the probabilities displayed, add:
print predictions
Hi all, I am trying to use Caffe as an eye detector. My idea is to have 2d vectors, expressing displacements, as labels, but I think there is some issue with their format. In the text file that summarizes the content of the training dataset each line is something like:
image1.png 1 2 image2.png 0.5 1
But this seems not to be recognized by the system since when I run create_imagenet.sh for some reason it reads only 2 images instead of almost 20000. Do you know what's the format for 2-dimensional label?
Hi @dennis-chen and whoever that could give me a help with my struggle. I just started to use caffe, and I am working on preparing the dataset in order to train and validate the neural network that I am working on (basically following the caffe tutorial on website). I already downloaded the 138GB of images of ILSVRC2012_img_test, and also the 4.4 GB of IILSVRC2012_img_val. However, I did not find how to get the class of each picture to generate the text files required to create the ImageNet, should I categorize by myself, or there is anyway to get this information?
Additionally, would be possible using less categories in order to reduce the amount of input I need to use on the neural network?
In caffe/matlab/hdf5creation it shows how to read and write HDF5 data with Matlab. This should work for any kind of data, not just images.
Hello everybody, I was just running the imagenet example from the tutorial, but I got the error message below. Have anyone ever seen this before? This happened after I try to run the command ./build/tools/caffe train --solver=models/bvlc_reference_caffenet/solver.prototxt
I0706 11:00:31.481516 8842 layer_factory.hpp:74] Creating layer data I0706 11:00:31.481535 8842 net.cpp:90] Creating Layer data I0706 11:00:31.481547 8842 net.cpp:368] data -> data I0706 11:00:31.481564 8842 net.cpp:368] data -> label I0706 11:00:31.481578 8842 net.cpp:120] Setting up data I0706 11:00:31.481590 8842 data_transformer.cpp:22] Loading mean file from: data/ilsvrc12/imagenet_mean.binaryproto F0706 11:00:31.485407 8842 db_lmdb.hpp:13] Check failed: mdb_status == 0 (2 vs. 0) No such file or directory * Check failure stack trace: * @ 0x7f906fb6bdaa (unknown) @ 0x7f906fb6bce4 (unknown) @ 0x7f906fb6b6e6 (unknown) @ 0x7f906fb6e687 (unknown) @ 0x7f906ff9453e caffe::db::LMDB::Open() @ 0x7f906feff412 caffe::DataLayer<>::DataLayerSetUp() @ 0x7f906ff33d19 caffe::BasePrefetchingDataLayer<>::LayerSetUp() @ 0x7f906ffafe33 caffe::Net<>::Init() @ 0x7f906ffb1ba2 caffe::Net<>::Net() @ 0x7f906ff6e034 caffe::Solver<>::InitTestNets() @ 0x7f906ff6e72b caffe::Solver<>::Init() @ 0x7f906ff6e8f6 caffe::Solver<>::Solver() @ 0x40c970 caffe::GetSolver<>() @ 0x406621 train() @ 0x404ab1 main @ 0x7f906f07dec5 (unknown) @ 0x40505d (unknown) @ (nil) (unknown)
@andersonRocha091 I think the issue is your path to the lmdb folders. First, I would check the prototxt file that solver.prototxt links to. Within that file there should be definitions of the paths to the train and val datasets. You should make sure that these link to the datasets you are using. If all looks correct, then try recreating the lmdbs using createimagenet.sh, but only after deleting the original lmdbs (otherwise, the folders will not be created)
@zacharyhorvitz thank you very much for the heads up. I was looking for the dataset lmdb files and I found that when I ran CreateImagenet.sh I executed like root of the system. So, the lmdb files regarded to the validation images was saved in a totally different location. After copying those lmdb to the right path everything worked just fine. Thank you for the help
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.