alexgkendall / SegNet-Tutorial

Files for a tutorial to train SegNet for road scenes using the CamVid dataset
http://mi.eng.cam.ac.uk/projects/segnet/tutorial.html
847 stars 517 forks source link

What should I change in .prototxt files if I want to train two classes? #62

Open WeiyiLi opened 7 years ago

WeiyiLi commented 7 years ago

I am new to caffe. I followed the instructions in http://mi.eng.cam.ac.uk/projects/segnet/tutorial.html to learn training two classes, building and non-building. But I am confused what I should do with the three necessary .prototxt files. I run the training but it is always stuck at somewhere so I would like to make sure whether I have done is correct. If not, can anyone figure out my mistake? If it's correct and it is stuck because I am using CPU, is there a less complex net I can use or how can I modify the given net to distinguish two classes? Thx!

The dataset I used is also camVid. What I have done is listed below:

  1. Label the street-view images in camVid with two classes. Buildings are 0, and non-buildings are 1. I save the label-images into graylevel images, the corresponding pixel value are 0 and 1.
  2. Follow the file structure to divide the dataset into training and testing. Modify test.txt and train.txt
  3. In Models/segnet_train.prototxt, I changed source to my path locating train.txt and batch_size to 2 because I am only using computer (not gpu) to train. The last three layers in segnet_train.prototxt is changed to the code below. I didn't change any other layers in segnet_train.prototxt.

layer { bottom: "conv1_2_D" top: "conv1_1_D" name: "conv1_1_D" type: "Convolution" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } convolution_param { weight_filler { type: "msra" } bias_filler { type: "constant" } num_output: 2 # TWO CLASSES pad: 1 kernel_size: 3 } } layer { name: "loss" type: "SoftmaxWithLoss" bottom: "conv1_1_D" bottom: "label" top: "loss" softmax_param {engine: CAFFE} loss_param: { weight_by_label_freqs: true class_weighting: 0.2595 # CHANGE CLASS WEIGHT class_weighting: 7.3614 } } layer { name: "accuracy" type: "Accuracy" bottom: "conv1_1_D" bottom: "label" top: "accuracy" top: "per_class_accuracy" }

In Models/segnet_solvers.prototxt, I changed 'net' to the path of segnet_train.prototxt; snapshot_prefixto the path of solver snapshots and the solver_mode to CPU

In Models/segnet_inference.prototxt, I changed source path to my path of test.txt and num_output to 2 in the last convolution layer.

And I run the training using PATH/SegNet/caffe-segnet/build/tools/caffe train -gpu -1 -solver PATH/SegNet/Models/segnet_solver.prototxt

Thanks for helping me out!

sepidehhosseinzadeh commented 7 years ago

Hi @alexgkendall Could you help @WeiyiLi I have the same problem. Thanks

SRIVALSAN commented 7 years ago

Hi @alexgkendall I face the same problem too .. Would be great if you can guide

zhenzhen1022 commented 7 years ago

@alexgkendall would you please tell us how to modify the file ? Thanks

nathanin commented 7 years ago

I'd like to try to help, but please clarify: Are you seeing poor accuracy, or an error causing caffe to crash? How many training iterations do you use?

You might try segnet_basic - it's smaller and might fit on your GPU. Good luck.

ArunJ1 commented 5 years ago

Hi, Please somebody tell what to change to train Segnet with only two classes???

Thanks in advance, Arun