How to prepare the lmdb training data to train a convolutional auto-encoder ?

253 views
Skip to first unread message

Chun-Hsien Lin

unread,
May 6, 2016, 1:20:31 AM5/6/16
to Caffe Users
I want to train a convolutional auto-encoder (CAE), but I have no idea to build the training data with image ground truth in lmdb format.

Currently, the labeled training data in lmdb format is used to train the CAE while the error messages show up when execute the training progress.

The error messages are like below.

: not foundh: 2: train_CAE.sh:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast> >'
  what():  bad lexical cast: source type value could not be interpreted as target
*** Aborted at 1462506324 (unix time) try "date -d @1462506324" if you are using GNU date ***
PC: @     0x7ff569da4cc9 (unknown)
*** SIGABRT (@0xc6d) received by PID 3181 (TID 0x7ff56b8d6780) from PID 3181; stack trace: ***
    @     0x7ff569da4d40 (unknown)
    @     0x7ff569da4cc9 (unknown)
    @     0x7ff569da80d8 (unknown)
    @     0x7ff56a3a9535 (unknown)
    @     0x7ff56a3a76d6 (unknown)
    @     0x7ff56a3a7703 (unknown)
    @     0x7ff56a3a7922 (unknown)
    @           0x40b3f1 boost::throw_exception<>()
    @           0x406bc8 get_gpus()
    @           0x407c66 train()
    @           0x405a2c main
    @     0x7ff569d8fec5 (unknown)
    @           0x4062cb (unknown)
Aborted (core dumped)
: not foundh: 4: train_CAE.sh:


And, the following is the defined loss layer.

layers {
  name: "loss"
  type: SIGMOID_CROSS_ENTROPY_LOSS
  bottom: "deconv1"
  bottom: "data"
  top: "cross_entropy_loss"
  loss_weight: 1
}

Thanks a lot.

Jan

unread,
May 6, 2016, 8:26:23 AM5/6/16
to Caffe Users
Have you set a batch_size? I have seen this error (*** Aborted at 1462506324 (unix time) try "date -d @1462506324" if you are using GNU date ***) when a setting in the prototxt was not set that was actually necessary (but had no default value). batch_size is one of the candidates. Also: Are you still using the legacy format? Why? Convert to the new/current format using the upgrade_net_proto tool.

Jan

Chun-Hsien Lin

unread,
May 6, 2016, 8:37:01 AM5/6/16
to Caffe Users
What do you mean about the legacy format ?

Do you mean the layer definition ?

I've solved the problem.

Since the net model is designed based on other version of Caffe, the problems are gone after installing the correct version.


Jan

unread,
May 6, 2016, 8:47:49 AM5/6/16
to Caffe Users
Yes, the definition of the network. The version you were using is deprecated for at least a year now. But you can use the upgrade_net_proto tools to convert it to the current format.

Jan

Chun-Hsien Lin

unread,
May 6, 2016, 11:38:27 PM5/6/16
to Caffe Users
Since there some problems when using the deconvolution layer in the latest version of Caffe, I use a modified version which is about two years ago to run the convolutional auto-encoder (CAE) network.

If I apply the CAE to the latest version, the output dimensions would be wrong as a deconvolution layer is connected to a inner product layer. For instance, if the structure is designed as

conv 8 -> inp 128 -> inp 20 -> inp 128 -> deconv 8

Then, the output dimensions in each layer will be

1x8x12x12 -> 1x128 -> 1x20 -> 1x128 -> 1x8

The finial output wont be the image anymore.

But, it runs correctly in the old and modified version.

Are there any errors in the network definitions?

Jan

unread,
May 9, 2016, 4:48:01 AM5/9/16
to Caffe Users
I am not quite sure how that could have worked in the past, but the solution is relatively easy: You just need a reshape layer in front of the deconv layer to reformat the vector to an image (more-than-1D array) again, e.g. you could convert 1x128 into 1x2x8x8.

Jan

Chun-Hsien Lin

unread,
May 9, 2016, 6:41:11 AM5/9/16
to Caffe Users
Thank you very much  Jan.

It works after adding your suggestion.

Chun-Hsien Lin

unread,
May 9, 2016, 6:51:16 AM5/9/16
to Caffe Users
Jan, do you know how to parse the caffemodel ?

I want to use the CAE as the pre-trained model for feature extraction.

Hence, I have to use the former part of the caffemodel to generate another caffemodel, and apply it to the feature extraction part of a classification network.

Jan

unread,
May 9, 2016, 7:32:52 AM5/9/16
to Caffe Users
A caffemodel file contains a NetParameter protobuf message in binary serialized form. I.e. to read it from the file you only have to do something like this in python:

import caffe
from caffe.proto.caffe_pb2 import NetParameter

with open('my.caffemodel', 'rb') as f:
  netparam
= NetParameter.FromString(f.read())

# then netparam.layer can be used to access the layers,
# and every layer message has a repeated field 'blobs'
# which contains the set of trainable params for that layer.

# e.g.: if layer [4] is a conv-layer,
#          netparam.layer[4].blobs[0].data contains the filter kernels,
#          netparam.layer[4].blobs[1].data contains the biases.


Jan

Chun-Hsien Lin

unread,
May 10, 2016, 9:22:02 AM5/10/16
to Caffe Users
Thanks, Jan.

I'll try it.

Alien H

unread,
Jan 9, 2017, 2:20:11 AM1/9/17
to Caffe Users
Hello, I have a question on training data. When I use the sigmoidCrossEntropyLoss as the loss to backpropagate there always occurs an error: SigmoidCrossEntopyLoss Layer cannot backpropagate to label inputs. However, when I made the train-lmdb, I just used the training data but not use the label part. That means the train-lmdb doesn't include the label part. Because I think in CAE, the input and the output are the same, so I didn't use the labels. I want to know how you made the lmdb data?
Reply all
Reply to author
Forward
0 new messages