vudung45/FaceRec

program gets disconnected when there is no face on the screen.

Opened this issue · 10 comments

I am using this on windows 8 and Pycharm IDE.
As long as a face is detected the program runs. But when there is no face in the screen the program gets disconnected and exit. Below is the error I am getting

c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero
[[Node: InceptionResnetV1/Logits/Flatten/flatten/Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](InceptionResnetV1/Logits/AvgPool_1a_8x8/AvgPool, InceptionResnetV1/Logits/Flatten/flatten/Reshape/shape)]]

Checked about the issue and found a link tensorflow/tensorflow#10609
not sure how to proceed on for this.
I tweaked here and there at waitkey for the camera to run as per windows.

Hi there,
Please pull the latest changes i made in main.py. Please let me know if this works.
I haven't touched this project in a while. However, I'm planning to make some changes and release an upgrade for this project in the near future.

Thanks for the input, but getting the same error after adding the "if" condition. The only change I have done is changing the waitkey to 27 instead of "q". I can see my face with bounding box and immeadiately exits the program with the error.

InvalidArgumentError (see above for traceback): Reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero
[[Node: InceptionResnetV1/Logits/Flatten/flatten/Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](InceptionResnetV1/Logits/AvgPool_1a_8x8/AvgPool, InceptionResnetV1/Logits/Flatten/flatten/Reshape/shape)]]

I believe it is something to do with the "tf.reshape()" in mtcnn_detect.py , when the tensor is empty - getting the above exception.

@roocoder which tensorflow version are u running under? I believe that the current model code in this repo is not compatible with the latest tensorflow.
Please try installing 1.1.0-rc. or 1.2.0

Also, could you point out the specific line that you are getting this error from?

Thanks for pointing. I have been using tensorflow 1.7 . Now created a virtual env and installed the 1.2.0 version. Working great now.

@roocoder I'm glad that you've got this resolved. Could you point out which line were you getting error at? I may release a new updated version compatible with the latest tensorflow version.

here it goes when I run with tensorflow 1.7.0rc1

File "C:/Users/609633982/PycharmProjects/IRIS/captureio/FaceRec-master/main.py", line 160, in
extract_feature = FaceFeature(FRGraph)
File "C:\Users\609633982\PycharmProjects\IRIS\captureio\FaceRec-master\face_feature.py", line 22, in init
resnet.inference(self.x, 0.6, phase_train=False)[0], 1, 1e-10); #some magic numbers that u dont have to care about
File "C:\Users\609633982\PycharmProjects\IRIS\captureio\FaceRec-master\architecture\inception_resnet_v1.py", line 155, in inference
reuse=reuse)
File "C:\Users\609633982\PycharmProjects\IRIS\captureio\FaceRec-master\architecture\inception_resnet_v1.py", line 236, in inception_resnet_v1
net = slim.flatten(net)

@roocoder
Could you try to change this chunk of code, and run it under 1.7.0rc1
line 236 inception_resnet_v1.py

 net = slim.avg_pool2d(net, net.get_shape()[1:3], padding='VALID',
                                          scope='AvgPool_1a_8x8')
 net = slim.flatten(net)

to

net_size =  net.get_shape()[1:3]
if net_size.is_fully_defined():
   net = slim.avg_pool2d(net, net_size, padding='VALID',
                                           scope='AvgPool_1a_8x8')
else:
   net = tf.reduce_mean(net, [1, 2], keep_dims=True, name='global_pool');
net = slim.flatten(net)

ERRORS:

tensorflow.python.framework.errors_impl.InvalidArgumentError: Reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero
[[Node: InceptionResnetV1/Logits/Flatten/flatten/Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](InceptionResnetV1/Logits/AvgPool_1a_8x8/AvgPool, InceptionResnetV1/Logits/Flatten/flatten/Reshape/shape)]]

Caused by op 'InceptionResnetV1/Logits/Flatten/flatten/Reshape', defined at:
File "C:/Users/609633982/PycharmProjects/IRIS/captureio/FaceRec-master/main.py", line 160, in
extract_feature = FaceFeature(FRGraph)
File "C:\Users\609633982\PycharmProjects\IRIS\captureio\FaceRec-master\face_feature.py", line 22, in init
resnet.inference(self.x, 0.6, phase_train=False)[0], 1, 1e-10); #some magic numbers that u dont have to care about
File "C:\Users\609633982\PycharmProjects\IRIS\captureio\FaceRec-master\architecture\inception_resnet_v1.py", line 155, in inference
reuse=reuse)
File "C:\Users\609633982\PycharmProjects\IRIS\captureio\FaceRec-master\architecture\inception_resnet_v1.py", line 243, in inception_resnet_v1
net = slim.flatten(net)

I meet this error too, and fix it by change code(main.py) like this:

if(len(aligns) > 0):
features_arr = extract_feature.get_features(aligns)
recog_data = findPeople(features_arr,positions);
for (i,rect) in enumerate(rects):
cv2.rectangle(frame,(rect[0],rect[1]),(rect[0] + rect[2],rect[1]+rect[3]),(255,0,0)) #draw bounding box for the face
cv2.putText(frame,recog_data[i][0]+" - "+str(recog_data[i][1])+"%",(rect[0],rect[1]),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,255),1,cv2.LINE_AA)

@idea4good
After making this changes will this code run with tensorflow_gpu 1.4 ??