FaceBoxes-tensorflow icon indicating copy to clipboard operation
FaceBoxes-tensorflow copied to clipboard

How to run on cpu ?

Open vipcualo opened this issue 6 years ago • 15 comments

Thanks you ! I have only cpu and i run this project on cpu. My error : self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Default MaxPoolingOp only supports NHWC on device type CPU [[Node: import/pool1/MaxPool = MaxPoolT=DT_FLOAT, data_format="NCHW", ksize=[1, 1, 3, 3], padding="SAME", strides=[1, 1, 2, 2], _device="/job:localhost/replica:0/task:0/device:CPU:0"]] how to fix this error ? Thanks you very much @TropComplique ?

vipcualo avatar Jul 19 '18 09:07 vipcualo

Can someone help me? Thanks

vipcualo avatar Jul 20 '18 11:07 vipcualo

Hi. To run this on CPU you will need to change all NCHW tensors to NHWC tensors.

For example:

  1. Change axis here (1 -> 3): https://github.com/TropComplique/FaceBoxes-tensorflow/blob/master/src/network.py#L22
  2. Change NCHW to NHWC here: https://github.com/TropComplique/FaceBoxes-tensorflow/blob/master/src/network.py#L36
  3. Also, make changes in this function: https://github.com/TropComplique/FaceBoxes-tensorflow/blob/master/src/detector.py#L242

But these are not all places you will need to change.
You can find other places by yourself.

After these changes, you will need to refreeze the graph using save.py and create_pb.py.

TropComplique avatar Jul 20 '18 19:07 TropComplique

https://pan.baidu.com/s/1Y5LJ8mzVKoALTEyaUklkAA here is the cpu version of this PR, including a trained model.

tirtile avatar Jul 21 '18 10:07 tirtile

@tirtile do you convert trained model of TropCompile to CPU or you trained from scratch ?

vipcualo avatar Jul 21 '18 15:07 vipcualo

@tirtile thank for your share. Can you give me advice to train your NHWC model? I tried to train the faceboxes to detect bottle. I trained the model by TropComplique's code, it can detect the bottle. But when I used the same .tfrecord to train the model by your code, it detect nothing in same image. Is there anything change in generate the train dataset? Looking forward for your reply!

junedgar avatar Jul 23 '18 10:07 junedgar

@vipcualo @junedgar I trained the model according to config.json in this PR and changed nothing except data format.

tirtile avatar Jul 23 '18 12:07 tirtile

@tirtile :when is it the loss value you stop the training?

alexliyang avatar Aug 16 '18 03:08 alexliyang

@junedgar Do you find the reason? I used tritile's NHWC code also detected nothing in same image. It's very strange... Is there anything wrong during saving PB file?

hahasofia avatar Aug 16 '18 07:08 hahasofia

@hahasofia I used the wrong model. I ran the 'save.py' script, the model.pb was saved in root directory. I used a model in subdirectory with the some name, so i detect nothing. You can check if you used the correct model.

junedgar avatar Aug 16 '18 07:08 junedgar

@junedgar I used right model file, but I changed detector.py because I met error below when ran 'save.py'. So I'm not sure whether my changes affect the result. Do you meet below error? Thank you. image

hahasofia avatar Aug 21 '18 04:08 hahasofia

@tirtile I'd love to try your CPU model, but it looks like the link you posted expired. Any chance you can rehost it?

ptrckqnln avatar Aug 23 '18 15:08 ptrckqnln

Hi. Now the .pb file also works on CPU. 33 fps on an image with size 1024x768.

TropComplique avatar Aug 24 '18 11:08 TropComplique

@hahasofia yes, I encountered this problem, you can solve it by using python3.

junedgar avatar Sep 05 '18 07:09 junedgar

@TropComplique Hi. Use you provide .pb works on CPU speed:100ms per image, How did you test it?Is the test code provider

yhl2018 avatar Oct 08 '18 09:10 yhl2018

@TropComplique Hi. Use you provide .pb works on CPU speed:100ms per image, How did you test it?Is the test code provider

I got 300ms on CPU. Did you also get 33FPS?

marcoruizrueda avatar Oct 09 '19 15:10 marcoruizrueda