hizhangp / triplet Goto Github PK
View Code? Open in Web Editor NEWRe-implementation of tripletloss function in FaceNet
License: MIT License
Re-implementation of tripletloss function in FaceNet
License: MIT License
Hi, hizhangp, I have some problems during I running it, hoping you can give some advice, Thank you!
1.In tripletsample_layer.py,in the loop for j in range(len(label_index_map[anchor_label])):
top_anchor.append(anchor)
top_positive.append(positive)
top_negative.append(negative)
self.index_map.append([i, positive_index, negative_index])
There is following error
Solving...
I0829 15:46:58.676357 13370 solver.cpp:341] Iteration 0, Testing net (#0)
Semi-hard failed
Semi-hard failed
Traceback (most recent call last):
File "python/train.py", line 98, in
sw.train_model(max_iters)
File "python/train.py", line 60, in train_model
self.solver.step(1)
File "/home/zeng/caffe-master_p1/python/triplet/tripletsample_layer.py", line 102, in backward
bottom[0].diff[...] = bottom_diff
ValueError: could not broadcast input array from shape (270,128) into shape (55,128)
So I put it into for i in xrange(bottom[0].num):
Is it correct?
2.test_iter can only to be 0,why?
Need your answer,thank you!
您好!我使用您的代码在Facescrub上训练。我在pretrain(对530个人进行分类)中,iteration经过3000多之后loss仍然一直保持6.25左右徘徊。accuracy也是不到0.01%,所以想问问。由于我在车辆识别上也在做类似FaceNet的任务,我仿照您的代码也写了车辆型号的分类,loss也是一样的趋势,保持5以上。我想请问这个趋势正常吗?周围同事说这个趋势不常见,所以想问问您!谢谢!
Epoch 1
Shuffling the data ...
Traceback (most recent call last):
File "train.py", line 94, in
sw = SolverWrapper(solver, output_dir, pretrained_model, gpu_id, data)
File "train.py", line 32, in init
self.solver.net.layers[0].set_data(data)
File "/home/dl1/lvlu/triplet-master/triplet/data_layer.py", line 77, in set_data
self._shuffle_data()
File "/home/dl1/lvlu/triplet-master/triplet/data_layer.py", line 22, in _shuffle_data
np.random.choice(self._data._sample_person[person]))
File "mtrand.pyx", line 1080, in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:10392)
ValueError: a must be non-empty
@hizhangp 您好 请教一个问题,您的网络结构vgg16_face.prototxt,为什么每一层的学习率因子都是0呢?最后一层fc9_1是1,bias的学习率因子也是0。这样可以学到东西吗?
Hello,
I was trying to run this code with this dataset: http://vis-www.cs.umass.edu/lfw/
I needed to fix some problems in code, but has one I could not fix, when I run "train.py" I got this error below:
File "/home/user/projects/triplet/data_layer.py", line 36, in _get_next_minibatch
print('lenAttributeError: 'DataLayer' object has no attribute '_data'
(self._data._sample): '+str(len(self._data._sample)))
I can't see where this error occur, because my code execute that function "_shuffle_data" the same object and printed "self._data" without problems, when I was trying to execute "sw.train_model(max_iters)" (in "train.py") this error to occur.
tripletsample_layer.py", line 102, in backward
bottom[0].diff[...] = bottom_diff
ValueError: could not broadcast input array from shape (200,128) into shape (50,128)
我batchsize设的50
您好,我想请教一下测试的时候是提取"fc7"还是"fc9_1"作为模型特征?谢谢!
May be you can share accuracy results?
您好!您在tripletsample_layer.py中,第73行至75行是不是少了一个缩进?否则上面关于semi-hard的计算部分就没有意义了,每次都取最后一个?
Hello,
Do you have any idea on how to determine the value of the margin in triplet loss formula? I saw you assigned 0.2 to the margin in your code. But I also noticed other people assigned 1 to it somewhere else. Can you give me some tips on choosing the value of margin ? Thank you a lot !
what does "negative_label = anchor_label" mean? Is it correct?
Hi, hizhangp,
In this while loop, len(sample_person) does not decrease, right? How would it become 0?
Does setting "SEMI_HARD = True" have a obvious improvement on the model? (converging speed, accuracy, etc.) I'm setting it to FALSE, and it seems that the loss couldn't decrease after thousands of iteration.
BTW, would you be kind enough to provide any statistical result for your model using your datasets? Or how you evaluate your model?
for i in range(bottom[0].num):
label_index_map[bottom_label[i]].append(i)
for i in range(bottom[0].num):
anchor_label = bottom_label[i]
anchor = bottom_data[i]
for j in range(len(label_index_map[anchor_label])):
positive_index = label_index_map[anchor_label][j]
if len(label_index_map[anchor_label]) > 1 and positive_index == i:
continue
positive = bottom_data[positive_index]
negative_label = anchor_label
negative_index = np.random.choice(
label_index_map[negative_label])
negative = bottom_data[negative_index]
# need semi-hard mining?
semihard = True
# max iteration
max_iter = bottom[0].num * 2
while len(label_index_map) > 1 and (negative_label == anchor_label or semihard):
when the label_index_map only have one key, which means that the samples within this batch own the same label, your code will generate a triplet within the same class?
Traceback (most recent call last):
File "casiaWebface/triplet-master/train.py", line 94, in
sw = SolverWrapper(solver, output_dir, pretrained_model, gpu_id, data)
File "casiaWebface/triplet-master/train.py", line 32, in init
self.solver.net.layers[0].set_data(data)
File "/home/zlu/caffe/casiaWebface/triplet-master/triplet/data_layer.py", line 77, in set_data
self._shuffle_data()
File "/home/zlu/caffe/casiaWebface/triplet-master/triplet/data_layer.py", line 22, in _shuffle_data
np.random.choice(self._data._sample_person[person]))
File "mtrand.pyx", line 1110, in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:17158)
ValueError: a must be non-empty
I am using the triplet loss with my inception batch-norm network. And it breaks down on the 1st iteration.
Epoch 1
Shuffling the data ...
Solving...
I1216 21:59:13.990463 6601 solver.cpp:337] Iteration 0, Testing net (#0)
Traceback (most recent call last):
File "triplet_train.py", line 97, in <module>
sw.train_model(max_iters)
File "triplet_train.py", line 59, in train_model
self.solver.step(1)
File "/home/wenfahu/inception_bn_face/triplet/data_layer.py", line 107, in forward
blobs = self._get_next_minibatch()
File "/home/wenfahu/inception_bn_face/triplet/data_layer.py", line 37, in _get_next_minibatch
if self._index + self.batch_size <= len(self._data._sample):
AttributeError: 'DataLayer' object has no attribute '_data'
for i in range(bottom[0].num):
label_index_map[bottom_label[i]].append(i)
for i in range(bottom[0].num):
anchor_label = bottom_label[i]
anchor = bottom_data[i]
for j in range(len(label_index_map[anchor_label])):
positive_index = label_index_map[anchor_label][j]
if len(label_index_map[anchor_label]) > 1 and positive_index == i:
continue
positive = bottom_data[positive_index]
negative_label = anchor_label
negative_index = np.random.choice(
label_index_map[negative_label])
negative = bottom_data[negative_index]
# need semi-hard mining?
semihard = True
# max iteration
max_iter = bottom[0].num * 2
while len(label_index_map) > 1 and (negative_label == anchor_label or semihard):
when the label_index_map only have one key, which means that the samples within this batch own the same label, your code will generate a triplet within the same class?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.