tyandzx / caffe

Other
29 stars 16 forks source link

关于测试集的batch大小设置 #4

Open ccc013 opened 7 years ago

ccc013 commented 7 years ago

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

tyandzx commented 7 years ago

不需要,triplet loss只在训练中使用,测试的时候单张图片即可。@ccc013

ccc013 commented 7 years ago

哦,所以triplet loss层应该加上 include { phase: TRAIN
} 才对,是吗

tyandzx commented 7 years ago

是的@ccc013

ccc013 commented 7 years ago

好的,谢谢...不过我发现triplet loss一直没有下降,而且我也同时有使用softmax loss的。 然后网络结构是这样的: layer { name: "data" type: "Data" top: "data" top: "label" include { phase: TRAIN } transform_param { mirror: true crop_size: 227 scale: 0.00390625 mean_file: "/home/cai/dataset/food-101/data/food101_mean_train.binaryproto" } data_param { source: "/home/cai/dataset/food-101/examples/food101_train_triplet_lmdb" batch_size: 250 backend: LMDB } } layer { name: "data" type: "Data" top: "data" top: "label" include { phase: TEST } transform_param { mirror: false crop_size: 227 scale: 0.00390625 mean_file: "/home/cai/dataset/food-101/data/food101_mean_val.binaryproto" } data_param { source: "/home/cai/dataset/food-101/examples/food101_val_lmdb" batch_size: 50 backend: LMDB } } 接下来是一些conv层和fc层,最后的fc层和loss层如下: layer { name: "ip3" type: "InnerProduct" bottom: "fc7" top: "ip3" param { lr_mult: 1 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 101 weight_filler { type: "xavier" std: 0.01 } bias_filler { type: "constant" value: 0 } } } layer { name: "sample_triplet" type: "SampleTriplet" bottom: "ip3" top: "triplet" sample_triplet_param { label_num: 10 sample_num: 25 } include { phase: TRAIN } } layer { name: "triplet_loss" type: "TripletLoss" bottom: "ip3" bottom: "triplet" top: "triplet_loss" triplet_loss_param { margin: 0.1 } include { phase: TRAIN } loss_weight: 0.5 } layer { name: "loss" type: "SoftmaxWithLoss" bottom: "ip3" bottom: "label" top: "loss" } layer { name: "accuracy" type: "Accuracy" bottom: "ip3" bottom: "label" top: "accuracy" include { phase: TEST } } 所以我想问是不是我的网络结构的设置出现了什么问题,才会导致这个loss一直不变,然后准确率也不变

tyandzx commented 7 years ago

看了一下你的网络结构,我看到你的结构中把triplet loss加在了分类器输出(ip3)上,个人觉得triplet loss作用在倒数第二层的输出(fc7)上更合适,因为这一层的输出相当于网络学习到的特征,而最后一层ip3则是针对这些特征的分类器,其输出ip3作为分类器的响应。triplet loss的目标是使学习到的特征包含“类内近、类间远“的特性。所以,以fc7作为SampleTriplet的bottom可能更合适一些,以上仅是我个人的观点@ccc013

ccc013 commented 7 years ago

哦,好像应该是用倒数第二层的输出合适点,我先修改下,看看效果如何,谢谢解答!

z-pc commented 6 years ago

Hi Mr @tyandzx Did you release the layer of recognition in demo phase ?