由大卫桑德伯格制作的facenet三重损失训练误差

时间:2018-01-09 11:31:48

标签: python numpy tensorflow


当我在三元组丢失中实现传输学习时,我收到的错误是:

  

ValueError:无法将大小为160的数组重塑为形状(3)。

这是实施代码。

python src/train_tripletloss.py --logs_base_dir 
~/lab/experiments/facenet/logs/facenet/ --models_base_dir 
~/lab/experiments/facenet/models/facenet/ --data_dir 
~/lab/experiments/noise_lfw_30_mtcnnalign_182_160 --image_size 160 --model_def 
models.inception_resnet_v1 --weight_decay 1e-4 --optimizer RMSPROP --
learning_rate 0.01 --keep_probability 0.8 --random_crop --random_flip --
pretrained_model ~/lab/experiments/facenet/model/20170512-110547/model-20170512-
110547.ckpt-250000 --people_per_batch 80 --images_per_person 2 --
gpu_memory_fraction 0.15

这是所有错误消息

Running forward pass on sampled images: Traceback (most recent call last):
File "src/train_tripletloss.py", line 486, in 
main(parse_arguments(sys.argv[1:]))
File "src/train_tripletloss.py", line 186, in main
args.embedding_size, anchor, positive, negative, triplet_loss)
File "src/train_tripletloss.py", line 217, in train
labels_array = np.reshape(np.arange(nrof_examples),(-1,3))
File "/home/hideki/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 232, in reshape
return _wrapfunc(a, 'reshape', newshape, order=order)
File "/home/hideki/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
return getattr(obj, method)(*args, **kwds)
ValueError: cannot reshape array of size 160 into shape (3)

使用转移学习的数据集是由mtcnn对齐的LFW数据集,大小为160 x 160 数据集有1678个目录和3356个文件 虽然我试图改变160到182的大小,但程序说同样的错误。

我该怎么办?

1 个答案:

答案 0 :(得分:0)

问题是您尝试重塑的数据没有标签。 nrof_examples应该是形状(...,3),其中最后一个维度是标签(L为[1,0,0],f为[0,1,0]等)但是你给的nrof_examples有形状(160,160)。