Need help writing prototxt for 5-class image classifier.

274 views
Skip to first unread message

Dan

unread,
Apr 12, 2015, 11:06:37 PM4/12/15
to caffe...@googlegroups.com
Hi, I'm new to caffe. I'm trying to write a 5 class image classifier as stated in the title. I'm working with the Python bindings but that's probably irrelevant.

I get that there is a Classifier class which takes a model definition (*.prototxt) and an actual model (*.caffemodel). I'm stuck at trying to build the actual model definition. I've been looking at the examples but I'm not quite sure how I should be building the model definition.

There seems to be a general solver .prototxt which allows you to specify things like the number of iterations and gamma, learning rate, etc. That makes sense. But that file lists where the "protocol buffer definition" .prototxt is (called net). That file is hard to figure out even after looking at the docs. And the caffe tutorials seems outdated sometimes? For example, the ImageNet example says there should be train.txt and a val.txt files but when I ran the scripts, they produced a single train.txt file that produced the files and values together.

My working tree looks something like this:
.
├── data
│   ├── train
│   │   └── (loads of .jpeg training images)
│   ├── test
│   │   └── (loads of .jpeg test images)
│   ├── models
│   │  ├── solver.prototxt (copied a random example)
│   │  └── train_test.prototxt (copied a random example)
│   └── train.txt (contains files and labels 0 - 4)
└── src
    └── caffe
        └── main.py

Could someone get me started on what my train_test.prototxt should look like? Ie, any setup for a basic 5 class classifier?

What I've got so far in train_test looks like:

name: "CaffeNet"
layer {
  name: "data"
  type: "ImageData"
  top: "data"
  top: "label"
  data_param {
    source: "data/train.txt"    // This is actually an absolute path, shortened for brevity
    batch_size: 16
  }
}
layer {
  name: "ip"
  type: "INNER_PRODUCT"
  bottom: "data"
  top: "ip"
  inner_product_param {
    num_output: 2
  }
}
layer {
  name: "loss"
  type: "SOFTMAX_LOSS"
  bottom: "ip"
  bottom: "label"
  top: "loss"
}

Which just gets me:

I0412 22:18:45.236593 15925 layer_factory.hpp:74] Creating layer data
I0412 22:18:45.236623 15925 net.cpp:84] Creating Layer data
I0412 22:18:45.236642 15925 net.cpp:338] data -> data
I0412 22:18:45.236678 15925 net.cpp:338] data -> label
I0412 22:18:45.236701 15925 net.cpp:113] Setting up data
I0412 22:18:45.236717 15925 image_data_layer.cpp:36] Opening file
I0412 22:18:45.236757 15925 image_data_layer.cpp:51] A total of 0 images. // Not sure why its not getting the images
*** Aborted at 1428891525 (unix time) try "date -d @1428891525" if you are using GNU date ***
PC: @     0x7f13cacce4b0 std::string::append()
*** SIGSEGV (@0x0) received by PID 15925 (TID 0x7f13cbb97980) from PID 0; stack trace: ***
    @     0x7f13ca684540 (unknown)
    @     0x7f13cacce4b0 std::string::append()
    @     0x7f13cb4c780c std::operator+<>()
    @     0x7f13cb518221 caffe::ImageDataLayer<>::DataLayerSetUp()
    @     0x7f13cb54eb7a caffe::BaseDataLayer<>::LayerSetUp()
    @     0x7f13cb54ec69 caffe::BasePrefetchingDataLayer<>::LayerSetUp()
    @     0x7f13cb4c19ec caffe::Net<>::Init()
    @     0x7f13cb4c2a95 caffe::Net<>::Net()
    @     0x7f13cb4a9b8c caffe::Solver<>::InitTrainNet()
    @     0x7f13cb4aad70 caffe::Solver<>::Init()
    @     0x7f13cb4aaf56 caffe::Solver<>::Solver()
    @           0x40f0e0 (unknown)
    @           0x4081c2 (unknown)
    @           0x405abb (unknown)
    @     0x7f13ca671800 __libc_start_main
    @           0x406109 (unknown)
[1]    15925 segmentation fault (core dumped)  caffe train -solver data/models/solver.prototxt

It says it found a total of 0 images. But I'm 100% sure the path is correct and the file is in the format: filepath label
So I'm not sure what's going on here either...

Thanks,
Dan

Jinchao Lin

unread,
Nov 17, 2015, 10:12:46 PM11/17/15
to Caffe Users
In your model definition, you should change 

layer {
  name: "data"
  type: "ImageData"
  top: "data"
  top: "label"
  data_param {
    source: "data/train.txt"    // This is actually an absolute path, shortened for brevity
    batch_size: 16
  }
}

to 


layer {
  name: "data"
  type: "ImageData"
  top: "data"
  top: "label"
  image_data_param {

    source: "data/train.txt"    // This is actually an absolute path, shortened for brevity
    batch_size: 16
  }
}

Hope this will fix your problem. 
Reply all
Reply to author
Forward
0 new messages