seathiefwang / FaceRecognition-tensorflow

基于TensorFlow训练的人脸识别神经网络
1.31k stars 414 forks source link

Some of my questions #16

Closed XuBino closed 6 years ago

XuBino commented 6 years ago

1

输出层

Wout = weightVariable([512,2])
bout = weightVariable([2])                                    
#out = tf.matmul(dropf, Wout) + bout
out = tf.add(tf.matmul(dropf, Wout), bout)
return out

问题1:第二行bout这里为什么给的是权值,不应该是给偏差值吗?(The second row “bout” here why give "weightVariable“, should not be given ”biasVariable”?) 2 def is_my_face(image):

run(fetches,feed_dict=None,options=None, run_metadata=None)

#tf.Session.run()执行fetches中的操作,计算fetches中的张量值。返回值为fetches的执行结果
res = sess.run(predict, feed_dict={x: [image/255.0], keep_prob_5:1.0, keep_prob_75: 1.0})  
if res[0] == 1:  
    return True  
else:  
    return False  

问题2:res = sess.run(predict, feed_dict={x: [image/255.0], keep_prob_5:1.0, keep_prob_75: 1.0})
res[0] == 1这一句看不懂,为什么==1就是真了? (Res[0] = = 1, this sentence does not understand why ==1 is true?)

我在做本科毕设,有些问题不懂,可以加好友请教一下吗?QQ1198265517 微信xu17862702083 非常感谢你!

seathiefwang commented 6 years ago

问题1 我的失误,造成了误解,可以看一下两个函数的内容,其实是没有区别的。 问题2 # 将图片数据与标签转换成数组 imgs = np.array(imgs) labs = np.array([[0,1] if lab == my_faces_path else [1,0] for lab in labs]) 前面已经将标签变成[0, 1]格式,所以res[0]取值就是0或1了。

XuBino commented 6 years ago

imgs = np.array(imgs) labs = np.array([[0,1] if lab == my_faces_path else [1,0] for lab in labs]) 前面已经将标签变成[0, 1]格式,所以res[0]取值就是0或1了。 对,就是这块有点看不懂。这里把自己人脸的标签变成[0,1],其他人的变成[1,0],这里的标签是数组吧?那不应该是res[0]==0下标为0的元素==0的时候才是True 吗?求耐心指导,非常感谢,谢谢你!

seathiefwang commented 6 years ago

predict = tf.argmax(output, 1) 这一行代码,tf.argmax返回的是索引位置,你去看一下这个函数具体用法。

XuBino commented 6 years ago

嗯,这个函数我知道了,按行比较返回最大值的索引 前面是labs = np.array([[0,1] if lab == my_faces_path else [1,0] for lab in labs]) 这里 predict = tf.argmax(output, 1) res = sess.run(predict, feed_dict={x: [image/255.0], keep_prob_5:1.0, keep_prob_75: 1.0})
if res[0] == 1:
return True
else:
return False
然后res[0]==0或者1 所以不应该是==0的时候才true吗?我怎么感觉写反了?而且我刚录了5000张人脸,然后识别结果全是false,改成res[0]==0 正确了。我一会儿得回宿舍了,可能就上不了这个网站了。方便加个联系方式我好向你请教一下吗?非常感谢!!!

seathiefwang commented 6 years ago

predict = tf.argmax(output, 1) 这一句代码 output的shape(None, 2), 存放了形如这样的数据:[[1,0], [0,1], [0,1], [1,0]] 经过 tf.argmax之后,得到 predict = [0, 1, 1, 0], 之后res[0] ==0实际就是表示[1, 0]了。

XuBino commented 6 years ago

这块终于懂了,后期若还有啥不懂的还会继续来提问,望老哥你可以耐心指导一下,谢谢你啦