Coder Social home page Coder Social logo

caffe's Introduction

Triplet loss for Caffe

Introduce triplet loss layer to caffe.
Concretely, we use cosine matric to constrain the distance between samples among same label/different labels.

Useage

1st, you need create a ordered file list for training.
This file list control the exactly data read-in order during training phase. Suppose in each mini-batch, you have data from 4 labels and 2 samples in each label, then the content of the file list should be like this:


  img_path_1_from_label_1 label_1
  img_path_2_from_label_1 label_1
  img_path_1_from_label_2 label_2
  img_path_2_from_label_2 label_2
  ...
  img_path_1_from_label_4 label_4
  img_path_2_from_label_4 label_4

2nd, define network structure in your train_val.prototxt.
Setup SampleTripletLayer to sample triplets in each mini-batch. Currently, triplets are made up by all anchor-positive pairs in the same label and one hardest negative sample from other labels.


  layer {
    name: "sample_triplet"
    type: "SampleTriplet"
    bottom: "fully_connected_feature"
    top: "triplet"
    sample_triplet_param {
      label_num: 4
      sample_num: 2
    }
  }

Setup TripletLossLayer to calculate loss.


  layer {
    name: "triplet_loss"
    type: "TripletLoss"
    bottom: "fully_connected_feature"
    bottom: "triplet"
    top: "triplet_loss"
    triplet_loss_param {
      margin: 0.1
    }
    loss_weight: 1
  }

caffe's People

Contributors

tianyuan702 avatar tyandzx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

caffe's Issues

关于测试集的batch大小设置

你好,非常感谢分享这个实现了triplet loss的代码。
我的问题是测试集的batch大小是否也要设置得跟训练集的batch大小一样?或者说,在测试的时候,测试集是否也需要实现triplet loss?

about the triplet loss layer

in your example,the triplet loss layer has two bottom, but it need 3 bottoms as input, can u give a complete example. thanks very much.

FaceNet architecture

Hi, I am trying to implment the FaceNet architecture using your triplet loss. I got it to running but the loss is unusually high (e.g. loss = 7.24332e+07). Could you check the following prototxt and see if I am using your tripletLoss and SampleTriplet correctly for this case. Thanks.

`name: "FaceNet"
layer {
name: "facenet"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
crop_size: 220
}
data_param {
source: "/media/esb172/Hard_Disk_2/facenet_data/tightface/webfaces_train_lmdb/"
batch_size: 44
backend: LMDB
}
}
layer {
name: "facenet"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
scale: 0.00390625
crop_size: 220
}
data_param {
source: "/media/esb172/Hard_Disk_2/facenet_data/tightface/webfaces_val_lmdb"
batch_size: 44
backend: LMDB
}
}
layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 64
kernel_size: 7
stride: 2
pad: 3
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "pool1"
type: "Pooling"
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "rnorm1"
type: "LRN"
bottom: "pool1"
top: "rnorm1"
lrn_param {
local_size: 5
alpha: 1.0
beta: 0.75
}
}
layer {
name: "conv2a"
type: "Convolution"
bottom: "rnorm1"
top: "conv2a"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 64
kernel_size: 1
stride: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "conv2"
type: "Convolution"
bottom: "conv2a"
top: "conv2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 192
kernel_size: 3
stride: 1
pad: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "rnorm2"
type: "LRN"
bottom: "conv2"
top: "rnorm2"
lrn_param {
local_size: 5
alpha: 1.0
beta: 0.75
}
}
layer {
name: "pool2"
type: "Pooling"
bottom: "rnorm2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
pad: 1
}
}

layer {
name: "conv3a"
type: "Convolution"
bottom: "pool2"
top: "conv3a"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 192
kernel_size: 1
stride: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "conv3"
type: "Convolution"
bottom: "conv3a"
top: "conv3"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 384
kernel_size: 3
stride: 1
pad: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "pool3"
type: "Pooling"
bottom: "conv3"
top: "pool3"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
#pad: 1
}
}

layer {
name: "conv4a"
type: "Convolution"
bottom: "pool3"
top: "conv4a"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 384
kernel_size: 1
stride: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "conv4"
type: "Convolution"
bottom: "conv4a"
top: "conv4"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 256
kernel_size: 3
stride: 1
pad: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "conv5a"
type: "Convolution"
bottom: "conv4"
top: "conv5a"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 256
kernel_size: 1
stride: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "conv5"
type: "Convolution"
bottom: "conv5a"
top: "conv5"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 256
kernel_size: 3
stride: 1
pad: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "conv6a"
type: "Convolution"
bottom: "conv5"
top: "conv6a"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 256
kernel_size: 1
stride: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "conv6"
type: "Convolution"
bottom: "conv6a"
top: "conv6"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 256
kernel_size: 3
stride: 1
pad: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "pool4"
type: "Pooling"
bottom: "conv6"
top: "pool4"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
#pad: 1
}
}

layer {
name: "fc1a"
type: "InnerProduct"
bottom: "pool4"
top: "fc1a"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "fc1b"
type: "InnerProduct"
bottom: "pool4"
top: "fc1b"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "maxout1"
type: "Eltwise"
bottom: "fc1a"
bottom: "fc1b"
top: "maxout1"
eltwise_param {
operation:MAX
}
}

layer {
name: "fc2a"
type: "InnerProduct"
bottom: "maxout1"
top: "fc2a"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "fc2b"
type: "InnerProduct"
bottom: "maxout1"
top: "fc2b"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "maxout2"
type: "Eltwise"
bottom: "fc2a"
bottom: "fc2b"
top: "maxout2"
eltwise_param {
operation:MAX
}
}

layer {
name: "fc7128"
type: "InnerProduct"
bottom: "maxout2"
top: "fc7128"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 128
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
}
}
}

layer {
name: "sample_triplet"
type: "SampleTriplet"
bottom: "fc7128"
top: "sample_triplet"
sample_triplet_param {
label_num: 10575
sample_num: 2
}
}

layer {
name: "triplet_loss"
type: "TripletLoss"
bottom: "fc7128"
bottom: "sample_triplet"
bottom: "label"
top: "triplet_loss"
triplet_loss_param {
margin: 0.1
}
loss_weight: 1
}

`

多GPU时候应该怎样设置

您好,我现在正在试验您的代码,是在拥有100W人的数据集上微调一个已经训练好的人脸识别模型,我目前遇到的困惑是:只能使用单张显卡,不知道在多GPU下怎样设置您的TripletLoss层,我尝试用两张显卡,但似乎loss只在第一张上起作用。

make all error

您好。我修改Makefile.config了,设置CPU_ONLY=1,以及修改了Python,opencv,openblas等路径。同样的Makefile.config,在使用make all编译BVLC-caffe的时候没有问题。但编译该版本caffe时出现如下错误:(还未找到解决方法,在这里求助一下)
.......
.......
CXX examples/cifar10/convert_cifar_data.cpp
CXX .build_debug/src/caffe/proto/caffe.pb.cc
AR -o .build_debug/lib/libcaffe.a
LD -o .build_debug/lib/libcaffe.so.1.0.0-rc3
CXX/LD -o .build_debug/tools/test_net.bin
CXX/LD -o .build_debug/tools/train_net.bin
CXX/LD -o .build_debug/tools/upgrade_net_proto_binary.bin
CXX/LD -o .build_debug/tools/upgrade_solver_proto_text.bin
CXX/LD -o .build_debug/tools/device_query.bin
CXX/LD -o .build_debug/tools/finetune_net.bin
CXX/LD -o .build_debug/tools/convert_imageset.bin
CXX/LD -o .build_debug/tools/extract_features.bin
..build_debug/build_debug/lib/liblibcaffe.so�/libcaffe.so����寚�‘caffe::SampleTripletLayer::Backward_gpu(std::vector<caffe::Blob, std::allocator<caffe��::Blob>� >� const&, std::vector<bool, std::allocator > const&, std::vector<caffe::Blob��caffe::,SampleTripletLayer:std::allocator<:caffe::BlobBackward_gpu<double(>>std > const&):��:�未定义的引用vector<caffe::Blob<double

,. build_debug/stdlib/:libcaffe.so:对:‘allocatorcaffe::TripletLossLayer<:caffe:Forward_gpu(std:::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<:caffe::Blob, stdBlob::allocator<caffe:<:Blobdouble>> > const&)’未定义的引用
.build_debug/
>lib/libcaffe.so:对� ��caffe::>SampleTripletLayer< double>::Forward_gpu(stdconst::&vector<,caffe: :Blob, std::stdallocator<:caffe::vector<bool, std:::allocator< > doubleconst&>, std::vector<caffe::Blob**, >std: :allocatorcaffe::Blob< double>const> &> , std::constvector<caffe&::)�Blob<double�>�,� std�::�allocator<�caffe::Blob<��double>> > �const&)‹�未定义的引甉�
�.build_debug�/lib�/libcaffe.so��:对╀�caffe::TripletLossLayer::Backward_gpu��(std::vector<caffe::Blob�<float
,. stdbuild_debug/::allocator<caffe::Blob> > constlib/&libcaffe.so:��,�� ��caffestd:::TripletLossLayer<:float>vector<bool::,Forward_gpu(std::vector<caffe:: stdBlob, std::allocator<::caffe::Blob> allocator> const&, std:<:vectorboolcaffe::Blob, std::allocator<caffe::Blob> > const&)’ >未定� const��的引用
.build_debug/lib/libcaffe.so:对‘caffe&::,SampleTripletLayer::Forward_gpu(std::vector<caffe:: Blob, std::allocator<caffe::Blobstd:> > const&, std:::vectorvector<caffe::Blob, std::allocator<<caffe:caffe:Blob:double:> > const&)’未定义的引用
.build_debug/lib/Blob<libcaffe.so:对‘caffe::TripletLossLayerfloat>::Backward_gpu(std::vector<caffe::Blob**, ,std: :allocatorstd<:caffe::Blobfloat:allocator<> > const&, std::vector<bool, std::allocator > const&, std::vector<caffe::Blob, std::allocator<::caffe::Blob> > const&)’未定�Blob��的引用
.<floatbuild_debug/lib/libcaffe.so:对‘caffe::SampleTripletLayer:>:Forward_gpu
(std>:: vector<caffe::Blob,> std ::allocatorconst<caffe&::)Blob�> �>� �const&�, �std::vector<caffe::Blob��, std::allocator<caffe::Blob> > const&)’未定乚�的引用
.build_debug��/lib/libcaffe.so:对‘caffe::TripletLossLayer:�:Forward_gpu(std:�:vector��<caffe::Blob�, �std�:�:�allocator<caffe::�Blob
.build_debug > const&, std:/:vector<caffe:lib/:Blob<libcaffe.sodouble>
, �std::allocator��<caffe::Blob�>� �>� �const&)’未定义的引用
.build_debug/lib/libcaffe.so�caffe:对‘caffe::SampleTripletLayerfloat::::Backward_gpu(std:SampleTripletLayer:vector<caffe:<:float>Blob<::float>
, std::allocator<caffe:Forward_gpu:Blob<float(std::vector<caffe::Blob
, std::allocator<caffe::Blob> > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::TripletLossLayer::Forward_gpu(std::vector<caffe::Blob
, std::allocator<caffe::Blob> > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob>> > const&)’未定义的引用
.build_debug/lib> /libcaffe.so:对‘caffe::SampleTripletLayer>:: Backward_gpu(stdconst::&vector,< caffe:std:Blob
, std::allocator<caffe::::Blob<vector
> > const&, std::vector<bool, boolstd::allocator, > const&, stdstd:::vector<caffe:::Blob<, std:bool>:allocator<caffe::Blob>> > const&const&)’未定义的引, 用
.build_debug/lib/libcaffe.so:std��::�‘caffe::TripletLossLayer:<:Backward_gpucaffe:(std::vector<caffe::Blob, std::allocator<caffe:::Blob<Blob> > const&, std::floatvector<bool, std:>:allocator, std::<allocator > :const&,:Blob std> >: const&:vector)’未定义的引用
<.build_debug/caffe:lib/:Bloblibcaffe.so:对‘<caffe::TripletLossLayer:>, std:::allocator<caffeBackward_gpu(::stdBlob<:double>>: > constvector<&)��caffe:�未定义的引用
:Blob, std::allocator<caffe::Blob> > const&, std::vector<bool, std::allocatorcollect2: error: ld returned 1 exit status
> const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
collect2: error: ld returned 1 exit status
make: *** [.build_debug/tools/upgrade_solver_proto_text.bin] 错误 1
make: *** 正在等待未完成的任务....
make: *** [.build_debug/tools/upgrade_net_proto_binary.bin] 错误 1
.build_debug/lib/libcaffe.so:对‘caffe::SampleTripletLayer::Backward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<bool, std::allocator > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::TripletLossLayer::Forward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::SampleTripletLayer::Forward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::TripletLossLayer::Backward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<bool, std::allocator > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::SampleTripletLayer::Forward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::TripletLossLayer::Forward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::SampleTripletLayer::Backward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<bool, std::allocator > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::TripletLossLayer::Backward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<bool, std::allocator > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
collect2: error: ld returned 1 exit status
make: *** [.build_debug/tools/convert_imageset.bin] 错误 1
.build_debug/lib/libcaffe.so:对‘caffe::SampleTripletLayer::Backward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<bool, std::allocator > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::TripletLossLayer::Forward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::SampleTripletLayer::Forward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::TripletLossLayer::Backward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<bool, std::allocator > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::SampleTripletLayer::Forward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::TripletLossLayer::Forward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::SampleTripletLayer::Backward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<bool, std::allocator > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
.build_debug/lib/libcaffe.so:对‘caffe::TripletLossLayer::Backward_gpu(std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&, std::vector<bool, std::allocator > const&, std::vector<caffe::Blob, std::allocator<caffe::Blob> > const&)’未定义的引用
collect2: error: ld returned 1 exit status
make: *** [.build_debug/tools/extract_features.bin] 错误 1

major reference ?

Hi,
I want to know your reference(paper) about triplet loss.
Can you give me the paper you refer to? facenet??

loss 在0.7500上下跳动

您好,我由于项目需要,临时了解了一些尺度学习的知识,所以感觉用起来有很多地方并不了解,所以想请教一下。

  1. 我看前面的issue有说,您采用的是三角的loss,不是很懂这个,我还以为是l2的loss,请问下这个loss的全称或者公式?

2.我们一开始觉得可能和别的任务一样,深层网络较好,所以用了Res100和Res50去训练,但是loss一直停留在0.75(margin 0.25),不是波动,而是保持在

  1. 我们最后采用了ZF-net结构
    `name:"ZF car detect"
    layer {
    name: "data"
    type: "ImageData"
    top: "data"
    top: "label"
    transform_param {
    mean_value: 127.5
    mean_value: 127.5
    mean_value: 127.5
    scale: 0.0078125

mirror: true

}
image_data_param {
new_height: 256
new_width: 256
source: "imagesets/train.txt"
batch_size: 32
shuffle: false
}
}

layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 96
kernel_size: 7
stride: 2
weight_filler {
type: "xavier"
}
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 {
kernel_size: 3
stride: 2
pool: MAX
}
}

layer {
name: "conv2"
type: "Convolution"
bottom: "pool1"
top: "conv2"
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 256
kernel_size: 5
stride: 2
weight_filler {
type: "xavier"
}
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 {
kernel_size: 3
stride: 2
pool: MAX
}
}

layer {
name: "conv3"
type: "Convolution"
bottom: "pool2"
top: "conv3"
param { lr_mult: 1.0 }
param { lr_mult: 2.0 }
convolution_param {
num_output: 512
kernel_size: 3
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
...
some other layers
...
layer {
name:"fc8"
bottom: "fc7"
top: "fc8"
type: "InnerProduct"
inner_product_param {
num_output: 512
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}

layer {
name: "sample_triplet"
type: "SampleTriplet"
bottom: "fc8"
top: "triplet"
sample_triplet_param {
label_num: 8
sample_num: 4
}
}

layer {
name: "triplet_loss"
type: "TripletLoss"
bottom: "fc8"
bottom: "triplet"
top: "triplet_loss"
triplet_loss_param {
margin: 0.25
}
loss_weight: 1
}
训练一晚上后的结果,从开始到最后一直在0.75的小数点后4位波动
I0614 17:36:31.718358 28781 solver.cpp:244] Train net output #32: triplet_loss = 0.749998 (* 1 = 0.749998 loss)
I0614 17:36:31.718369 28781 sgd_solver.cpp:106] Iteration 446000, lr = 1e-08
I0614 17:36:34.979749 28781 solver.cpp:228] Iteration 446020, loss = 0.75007
I0614 17:36:35.046409 28781 solver.cpp:244] Train net output #0: label = 14537
I0614 17:36:35.046422 28781 solver.cpp:244] Train net output #1: label = 14537
I0614 17:36:35.046438 28781 solver.cpp:244] Train net output #2: label = 14537
I0614 17:36:35.046443 28781 solver.cpp:244] Train net output #3: label = 14537
I0614 17:36:35.046448 28781 solver.cpp:244] Train net output #4: label = 12832
I0614 17:36:35.046453 28781 solver.cpp:244] Train net output #5: label = 12832
I0614 17:36:35.046458 28781 solver.cpp:244] Train net output #6: label = 12832
I0614 17:36:35.046468 28781 solver.cpp:244] Train net output #7: label = 12832
I0614 17:36:35.046478 28781 solver.cpp:244] Train net output #8: label = 12280
I0614 17:36:35.046488 28781 solver.cpp:244] Train net output #9: label = 12280
I0614 17:36:35.046499 28781 solver.cpp:244] Train net output #10: label = 12280
I0614 17:36:35.046509 28781 solver.cpp:244] Train net output #11: label = 12280
I0614 17:36:35.046519 28781 solver.cpp:244] Train net output #12: label = 27357
I0614 17:36:35.046530 28781 solver.cpp:244] Train net output #13: label = 27357
I0614 17:36:35.046540 28781 solver.cpp:244] Train net output #14: label = 27357
I0614 17:36:35.046550 28781 solver.cpp:244] Train net output #15: label = 27357
I0614 17:36:35.046561 28781 solver.cpp:244] Train net output #16: label = 7992
I0614 17:36:35.046571 28781 solver.cpp:244] Train net output #17: label = 7992
I0614 17:36:35.046581 28781 solver.cpp:244] Train net output #18: label = 7992
I0614 17:36:35.046591 28781 solver.cpp:244] Train net output #19: label = 7992
I0614 17:36:35.046602 28781 solver.cpp:244] Train net output #20: label = 9613
I0614 17:36:35.046613 28781 solver.cpp:244] Train net output #21: label = 9613
I0614 17:36:35.046623 28781 solver.cpp:244] Train net output #22: label = 9613
I0614 17:36:35.046634 28781 solver.cpp:244] Train net output #23: label = 9613
I0614 17:36:35.046645 28781 solver.cpp:244] Train net output #24: label = 19435
I0614 17:36:35.046655 28781 solver.cpp:244] Train net output #25: label = 19435
I0614 17:36:35.046665 28781 solver.cpp:244] Train net output #26: label = 19435
I0614 17:36:35.046672 28781 solver.cpp:244] Train net output #27: label = 19435
I0614 17:36:35.046682 28781 solver.cpp:244] Train net output #28: label = 219
I0614 17:36:35.046694 28781 solver.cpp:244] Train net output #29: label = 219
I0614 17:36:35.046703 28781 solver.cpp:244] Train net output #30: label = 219
I0614 17:36:35.046715 28781 solver.cpp:244] Train net output #31: label = 219
I0614 17:36:35.046730 28781 solver.cpp:244] Train net output #32: triplet_loss = 0.75007 (* 1 = 0.75007 loss)
I0614 17:36:35.046741 28781 sgd_solver.cpp:106] Iteration 446020, lr = 1e-08
I0614 17:36:38.170933 28781 solver.cpp:228] Iteration 446040, loss = 0.750116
I0614 17:36:38.238198 28781 solver.cpp:244] Train net output #0: label = 384
I0614 17:36:38.238209 28781 solver.cpp:244] Train net output #1: label = 384
I0614 17:36:38.238226 28781 solver.cpp:244] Train net output #2: label = 384
I0614 17:36:38.238231 28781 solver.cpp:244] Train net output #3: label = 384
I0614 17:36:38.238235 28781 solver.cpp:244] Train net output #4: label = 11448
I0614 17:36:38.238240 28781 solver.cpp:244] Train net output #5: label = 11448
I0614 17:36:38.238246 28781 solver.cpp:244] Train net output #6: label = 11448
I0614 17:36:38.238256 28781 solver.cpp:244] Train net output #7: label = 11448
I0614 17:36:38.238266 28781 solver.cpp:244] Train net output #8: label = 9058
I0614 17:36:38.238276 28781 solver.cpp:244] Train net output #9: label = 9058
I0614 17:36:38.238287 28781 solver.cpp:244] Train net output #10: label = 9058
I0614 17:36:38.238297 28781 solver.cpp:244] Train net output #11: label = 9058
I0614 17:36:38.238308 28781 solver.cpp:244] Train net output #12: label = 26239
I0614 17:36:38.238319 28781 solver.cpp:244] Train net output #13: label = 26239
I0614 17:36:38.238348 28781 solver.cpp:244] Train net output #14: label = 26239
I0614 17:36:38.238359 28781 solver.cpp:244] Train net output #15: label = 26239
I0614 17:36:38.238369 28781 solver.cpp:244] Train net output #16: label = 15103
I0614 17:36:38.238380 28781 solver.cpp:244] Train net output #17: label = 15103
I0614 17:36:38.238390 28781 solver.cpp:244] Train net output #18: label = 15103
I0614 17:36:38.238401 28781 solver.cpp:244] Train net output #19: label = 15103
I0614 17:36:38.238411 28781 solver.cpp:244] Train net output #20: label = 4531
I0614 17:36:38.238421 28781 solver.cpp:244] Train net output #21: label = 4531
I0614 17:36:38.238432 28781 solver.cpp:244] Train net output #22: label = 4531
I0614 17:36:38.238442 28781 solver.cpp:244] Train net output #23: label = 4531
I0614 17:36:38.238452 28781 solver.cpp:244] Train net output #24: label = 8527
I0614 17:36:38.238463 28781 solver.cpp:244] Train net output #25: label = 8527
I0614 17:36:38.238473 28781 solver.cpp:244] Train net output #26: label = 8527
I0614 17:36:38.238484 28781 solver.cpp:244] Train net output #27: label = 8527
I0614 17:36:38.238494 28781 solver.cpp:244] Train net output #28: label = 17737
I0614 17:36:38.238505 28781 solver.cpp:244] Train net output #29: label = 17737
I0614 17:36:38.238515 28781 solver.cpp:244] Train net output #30: label = 17737
I0614 17:36:38.238525 28781 solver.cpp:244] Train net output #31: label = 17737
I0614 17:36:38.238540 28781 solver.cpp:244] Train net output #32: triplet_loss = 0.750116 (* 1 = 0.750116 loss)
I0614 17:36:38.238554 28781 sgd_solver.cpp:106] Iteration 446040, lr = 1e-08

`

训练数据的话有约3k个类。不过我们的图像比较凌乱,大小不一,没什么预处理,不知道这会不会有影响。
谢谢!

[error] Check failed: ExactNumBottomBlobs() == bottom.size() (2 vs. 3) TripletLoss Layer takes 2 bottom blob(s) as input.

hi.
i try your triplet loss. but i have next problem.

F0721 12:28:31.108945 19808 layer.hpp:374] Check failed: ExactNumBottomBlobs() == bottom.size() (2 vs. 3) TripletLoss Layer takes 2 bottom blob(s) as input.
*** Check failure stack trace: ***
@ 0x7fa8885d0b5d google::LogMessage::Fail()
@ 0x7fa8885d4b77 google::LogMessage::SendToLog()
@ 0x7fa8885d29f9 google::LogMessage::Flush()
@ 0x7fa8885d2cfd google::LogMessageFatal::~LogMessageFatal()
@ 0x7fa88e3e1f01 caffe::Layer<>::CheckBlobCounts()
@ 0x7fa88e42de13 caffe::Net<>::Init()
@ 0x7fa88e43028b caffe::Net<>::Net()
@ 0x7fa88e50778a caffe::Solver<>::InitTrainNet()
@ 0x7fa88e507e74 caffe::Solver<>::Init()
@ 0x7fa88e5083a8 caffe::Solver<>::Solver()
@ 0x7fa88e409d13 caffe::Creator_SGDSolver<>()
@ 0x412193 caffe::SolverRegistry<>::CreateSolver()
@ 0x40c0c8 train()
@ 0x4089af main
@ 0x33f3a1ed5d (unknown)
@ 0x407ef9 (unknown)
중지됨

Is triplet loss need 3 input size ?

Sample data-label file and model prototxt

Hi,

I'm trying to use your triplet loss for cifar10. However my train loss isn't decreasing, and my validation accuracy is always 0. I believe the problem is with my input.

Can you share an example model along with image-label (for certain batch size) file which will help us understand what is required.

Thank you

训练准确率一直不变

我按照说明种的图片排列和网络配置方式,训练了50个类,每个类2张图片,准确率一直不变,为随机初始的值,因为readme中没有详细的教程,所以不知是否配置错误还是其他

about the negative node selection in triplets samples

In your triplets sampling layer, you will firstly select the <anchor, positive>, when to find the best negative to form the triplets, but I see in your code(https://github.com/tyandzx/caffe/blob/master/src/caffe/layers/sample_triplet_layer.cpp#L48), you will select the negative node that is most far from the anchor, not the closest one (hardest negative) or using semi-hardest negative proposed in FaceNet, like
qq 20171229161440

What is your considerations? thanks.

About label_num and sample_num

Hello @tyandzx.
In your example, we have 4 label_num and 2 sample_num each label_num.
The problem is in my data, number of each label is allway different.
Whether:

  1. I can igorne two these parameter.
  2. I can make a lits train with number of each is different.
    example:

in train.prototxt

layer {
name: "sample_triplet"
type: "SampleTriplet"
bottom: "loss3/classifier"
top: "triplet"
}
}

in listtrain

data\facenet\images\Aaron_Peirsol_0002.jpg 1
data\facenet\images\Aaron_Peirsol_0003.jpg 1
data\facenet\images\Aaron_Peirsol_0004.jpg 1
data\facenet\images\Aaron_Sorkin_0002.jpg 2
data\facenet\images\Abdoulaye_Wade_0002.jpg 3
data\facenet\images\Abdoulaye_Wade_0003.jpg 3
data\facenet\images\Abdoulaye_Wade_0004.jpg 3
data\facenet\images\Abdullah_0002.jpg 4
data\facenet\images\Abdullah_0003.jpg 4
data\facenet\images\Abdullah_0004.jpg 4
data\facenet\images\Abdullah_al-Attiyah_0002.jpg 5
data\facenet\images\Abdullah_al-Attiyah_0003.jpg 5

Thank you so much

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.