convert train_val.prototxt to deploy.prototext

725 views
Skip to first unread message

rsl

unread,
Feb 25, 2016, 2:31:21 PM2/25/16
to Caffe Users
I want to my cnn network predict multilabel output for images 128*128 dimension. It's my train_val.prototxt
name: "cnv_net"
layer {
  name: "MyData"
  type: "HDF5Data"
  top: "data"
  top: "label"
  hdf5_data_param {
    source: "/cnn/train_h5_list.txt"
    batch_size: 128
  }
  include: { phase: TRAIN }
}
layer {
  name: "MyData"
  type: "HDF5Data"
  top: "data"
  top: "label"
  hdf5_data_param {
    source: "/cnn/test_h5_list.txt"
    batch_size: 540
  }
  include: { phase: TEST }
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  #blobs_lr: 1
  #blobs_lr: 2
  convolution_param {
    num_output: 40
    kernel_size: 7
    stride: 1
    weight_filler {
      type: "xavier"
      variance_norm: AVERAGE
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
}

layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}

layer {
  name: "dropout1"
  type: "Dropout"
  bottom: "pool1"
  top: "pool1"
  dropout_param {
    dropout_ratio: 0.1
  }
}

layer {
  name: "conv2"
  type: "Convolution"
  bottom: "pool1"
  top: "conv2"
  convolution_param {
    num_output: 144
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
      variance_norm: AVERAGE

    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv2"
  top: "conv2"
}

layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}

layer {
  name: "dropout2"
  type: "Dropout"
  bottom: "pool2"
  top: "pool2"
  dropout_param {
    dropout_ratio: 0.3
  }
}

layer {
  name: "conv3"
  type: "Convolution"
  bottom: "pool2"
  top: "conv3"
  convolution_param {
    num_output: 36
    kernel_size: 2
    stride: 1
    weight_filler {
      type: "xavier"
      variance_norm: AVERAGE

    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
 }
 layer {
  name: "relu3"
  type: "ReLU"
  bottom: "conv3"
  top: "conv3"
}


layer {
  name: "dropout3"
  type: "Dropout"
  bottom: "conv3"
  top: "conv3"
  dropout_param {
    dropout_ratio: 0.5
  }
}


layer {
  name: "fc5"
  type: "InnerProduct"
  bottom: "conv3"
  top: "fc5"
  inner_product_param {
    num_output: 500
    weight_filler {
      type: "xavier"
      variance_norm: AVERAGE
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}

layer {
  name: "drop4"
  type: "Dropout"
  bottom: "fc5"
  top: "fc5"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  name: "fc6"
  type: "InnerProduct"
  bottom: "fc5"
  top: "fc6"
  #blobs_lr: 1
  #blobs_lr: 2
  inner_product_param {
    num_output: 8100
    weight_filler {
      type: "xavier"
      variance_norm: AVERAGE
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "loss"
  type: "EuclideanLoss"
  bottom: "fc6"
  bottom: "label"
  top: "loss"
}

I create this deploy.prototxt:
name: "cnn_net"
input: "data"
input_shape {
  dim: 1
  dim: 1
  dim: 128
  dim: 128
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  #blobs_lr: 1
  #blobs_lr: 2
  convolution_param {
    num_output: 40
    kernel_size: 7
    stride: 1
    weight_filler {
      type: "xavier"
      variance_norm: AVERAGE
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
}

layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}

layer {
  name: "dropout1"
  type: "Dropout"
  bottom: "pool1"
  top: "pool1"
  dropout_param {
    dropout_ratio: 0.1
  }
}

layer {
  name: "conv2"
  type: "Convolution"
  bottom: "pool1"
  top: "conv2"
  convolution_param {
    num_output: 144
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
      variance_norm: AVERAGE

    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv2"
  top: "conv2"
}

layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}

layer {
  name: "dropout2"
  type: "Dropout"
  bottom: "pool2"
  top: "pool2"
  dropout_param {
    dropout_ratio: 0.3
  }
}

layer {
  name: "conv3"
  type: "Convolution"
  bottom: "pool2"
  top: "conv3"
  convolution_param {
    num_output: 36
    kernel_size: 2
    stride: 1
    weight_filler {
      type: "xavier"
      variance_norm: AVERAGE

    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
 }
 layer {
  name: "relu3"
  type: "ReLU"
  bottom: "conv3"
  top: "conv3"
}


layer {
  name: "dropout3"
  type: "Dropout"
  bottom: "conv3"
  top: "conv3"
  dropout_param {
    dropout_ratio: 0.5
  }
}


layer {
  name: "fc5"
  type: "InnerProduct"
  bottom: "conv3"
  top: "fc5"
  inner_product_param {
    num_output: 500
    weight_filler {
      type: "xavier"
      variance_norm: AVERAGE
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}

layer {
  name: "drop4"
  type: "Dropout"
  bottom: "fc5"
  top: "fc5"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  name: "fc6"
  type: "InnerProduct"
  bottom: "fc5"
  top: "fc6"
  #blobs_lr: 1
  #blobs_lr: 2
  inner_product_param {
    num_output: 8100
    weight_filler {
      type: "xavier"
      variance_norm: AVERAGE
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "prob"
  type: "EuclideanLoss"
  bottom: "fc6"
  top: "prob"
}


But I can not do prediction! it gives me this error : 
F0225 22:24:28.898002 29816 layer.hpp:374] Check failed: ExactNumBottomBlobs() == bottom.size() (2 vs. 1) EuclideanLoss Layer takes 2 bottom blob(s) as input.
*** Check failure stack trace: ***
Aborted (core dumped)

Is there anybody what should I do? Thanks 

Joshua Slocum

unread,
Feb 25, 2016, 3:12:31 PM2/25/16
to rsl, Caffe Users
EuclidianLoss takes two inputs: the predicted value and the target value. Take a look at the example Euclidean layer here: http://caffe.berkeleyvision.org/tutorial/layers.html

--
You received this message because you are subscribed to the Google Groups "Caffe Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caffe-users...@googlegroups.com.
To post to this group, send email to caffe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/caffe-users/183700ab-32f2-4939-8fc4-cd17993fc526%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rsl

unread,
Feb 25, 2016, 3:22:55 PM2/25/16
to Caffe Users, rasoul...@gmail.com
Thanks Jashua, I have tried to change it to :

layer {
  name: "prob"
  type: "EuclideanLoss"
  bottom: "fc6"
  bottom: "label"
  top: "prob"
}

but it gives this error: 

F0225 23:17:50.417438   378 insert_splits.cpp:35] Unknown bottom blob 'label' (layer 'prob', bottom index 1)
*** Check failure stack trace: ***
Aborted (core dumped)

Is that because I didn't specified label input in deploy.prototxt ? because I didn't see any example with label information in deploy.prototxt file.

Jan C Peters

unread,
Feb 26, 2016, 8:01:01 AM2/26/16
to Caffe Users, rasoul...@gmail.com
Exactly. You need to add an input: "label" and respective input_shape. On the other hand, if you just want to do inference/prediction and don't care about the loss (which is the most common use case for the deploy file I think), you can just remove the EuclideanLoss layer in your deploy prototxt, ignore labels completely and be done with it.

Jan

P.S. the name "prob" of your output blob may not be intended to mean much, but I just wanted to add that what you compute can in no way be interpreted as a probability... (output of an IP layer, e.g. no guarantees about being inside [0,1])

Luke Yeager

unread,
Feb 29, 2016, 1:18:39 PM2/29/16
to Caffe Users, rasoul...@gmail.com
You can now use the new "Input" layer to specify your network all-in-one!

The inferface will be a little easier to use with this pycaffe PR:

For now, it can be tricky to set up your include/exclude rules correctly. Here's one way to do it:

# in solver.prototxt
test_state { stage: "val" }

# in network.prototxt
layer {
  name: "train_data"
  type: "Data"
  top: "data"
  top: "label"
  include { phase: TRAIN }
}
layer {
  name: "val_data"
  type: "Data"
  top: "data"
  top: "label"
  include { stage: "val" }
}
layer {
  name: "data"
  type: "Input"
  top: "data"
  exclude { phase: TRAIN }
  exclude { stage: "val" }
}

Jan C Peters

unread,
Mar 1, 2016, 4:42:09 AM3/1/16
to Caffe Users, rasoul...@gmail.com
That is great news Luke! The deploy config has always been a strange artifact. Now we are approaching a more clean interface. A next great addition would be the possibility to add a data transformer to this "Input" layer, as can be done in the other data layers, such that preprocessing is done in a way transparent to the user/API.

Thanks to the caffe community for all their work!

Jan
Reply all
Reply to author
Forward
0 new messages