Real Time Face Mask Detection with Tensorflow and Python | Custom Object Detection w/ MobileNet SSD




[ad_1]

Ever wanted to build your very own custom object detector?

Got lost with all the tutorials and installation?

Well…I hear you…I went through the

EXACT. SAME. THING.

So, let’s flip it up. In this video we’re going to go through how to build a custom object detection model that can be used to make detections in real time. Now whilst we’re using it for detecting face masks this can be easily repurposed to perform real-time detection for a whole range of use cases simply by updating the annotations and the label map.

In this video you’ll learn how to:
1. Install labelImg and label images from scratch for object detection
2. Train and run a custom object detector for face mask detection
3. Use transfer learning to train on top of existing SOTA models
4. Setup a proper workflow and directory structure for training
5. Make detections in real time using the trained model

Get the training template here: https://github.com/nicknochnack/RealTimeObjectDetection

Other Links Mentioned in the Video
LabelImg: https://github.com/tzutalin/labelImg
Kaggle Repo: https://www.kaggle.com/wobotintelligence/face-mask-detection-dataset
Installing the Tensorflow Object Detection API: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/install.html
Tensorflow Models: https://github.com/tensorflow/models
Tensorflow 2 Detection Model Zoo (for alternate pre-trained models): https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md

Oh, and don’t forget to connect with me!
LinkedIn: https://www.linkedin.com/in/nicholasrenotte
Facebook: https://www.facebook.com/nickrenotte/
GitHub: https://github.com/nicknochnack

Happy coding!
Nick

P.s. Let me know how you go and drop a comment if you need a hand!

Source


[ad_2]

Comment List

  • Nicholas Renotte
    January 24, 2021

    Is there a reason you are using core TensorFlow over the Keras API for object detection? Is this the recommended way to write object detection code?
    I have worked on a small computer vision project using Keras more than a year ago. This was an awesome video, but almost the entire code/imports/functions/tf records/pb files were new to me.

  • Nicholas Renotte
    January 24, 2021

    hello! im currently stuck in the jupyter notebook as it says that 'git' is not recognized as an internal or external command. I launched my jupyter notebook from anaconda. Hope you can reply! Thanks!

  • Nicholas Renotte
    January 24, 2021

    Hi Nicholas, tutorial working perfect right up until last block of code where real time detection should be done and I get the following error:

    —> 30 cv2.imshow('object detection', cv2.resize(image_np_with_detections, (800, 600)))

    error: OpenCV(4.5.1) C:UsersappveyorAppDataLocalTemp1pip-req-build-memyuvq3opencvmoduleshighguisrcwindow.cpp:651: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

    Help would be greatly appreciated!

  • Nicholas Renotte
    January 24, 2021

    hi, i'm at the last part of the tutorial and i'm having problems:
    OpenCV(4.5.1) C:UsersappveyorAppDataLocalTemp1pip-req-build-memyuvq3opencvmoduleshighguisrcwindow.cpp:651: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'
    please help, thank you

  • Nicholas Renotte
    January 24, 2021

    Great tutorial! Do you have idea how to get coordinates of center of the box?

  • Nicholas Renotte
    January 24, 2021

    Sir I am having trouble with an error which says function is not implemented rebuild the Library with windows,gtk+2.x or carbon support. please help me with this.

  • Nicholas Renotte
    January 24, 2021

    So amazing, really worth it to watch. Best explanation and easy to follow. Keep up doing video sir. You just got 1 new subscriber 😁

  • Nicholas Renotte
    January 24, 2021

    Hello there, I have an issue if maybe you'd have some insight on it please.
    When I ran command "python labelImg.py" for the firsttime, I received an error about pathlib not being istalled. So I installed it in python dir with pip and now I have an error "ImportError: No module named PyQt4.QtCore".

    I tried installing pyqt4 package but it refuses to do so as it's used on python 2.7 and I have 3.7.
    Up until this point, everything worked as shown in the video.

    Solution edit:
    I tried to implement it with anaconda prompt where I installed everything inside venv (python, tensorflow and the rest that you showed) and then ran python labelImg.py from labellImg directory and it opened up.

  • Nicholas Renotte
    January 24, 2021

    Hi i have an error saying that No module named 'libs.resource' can you please slove this issue its my kind request..

  • Nicholas Renotte
    January 24, 2021

    Will the Model Generalize on some other person since in this you have used your face as data?This is wrt no Mask
    Because recently i trained model using EfficientDetD0 which predicts if a person is wearing Glasses or not. So it was working if I wore glasses but was not predicting anything if I removed my glasses.
    The Data was Scrapped from the internet and consisted of very random people's images.
    Can you tell me why it wasn't predicting?

  • Nicholas Renotte
    January 24, 2021

    Hey thank you for this video 🙂
    I want to ask a question. I trained a model using keras, tensorflow with CNN. And I applied my model using opencv-dnn face detection. But, sometimes it works really well, sometimes it does not. I mean, one day when I wear a mask, it shows masked, the other day it can show without a mask even though I wear a mask. I do not understand why. Do you know why it is so? Please help.

  • Nicholas Renotte
    January 24, 2021

    Hello Nichilas, fistly tks a lot for this tuturial and I`m facing this error "error: OpenCV(4.5.1) C:UsersappveyorAppDataLocalTemp1pip-req-build-memyuvq3opencvmoduleshighguisrcwindow.cpp:651: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

    " could you please help me? tks again

  • Nicholas Renotte
    January 24, 2021

    In the last step to show real-time video, i got an error in this code :
    cv2.imshow('object detection', cv2.resize(image_np_with_detections, (800, 600)))

    Please Help. I dont understand at all.

    Full error :
    error Traceback (most recent call last)

    <ipython-input-39-3a5cc6a8923f> in <module>

    28 agnostic_mode=False)

    29

    —> 30 cv2.imshow('object detection', cv2.resize(image_np_with_detections, (800, 600)))

    31

    32 if cv2.waitKey(1) & 0xFF == ord('q'):

    error: OpenCV(4.5.1) C:UsersappveyorAppDataLocalTemp1pip-req-build-memyuvq3opencvmoduleshighguisrcwindow.cpp:651: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

  • Nicholas Renotte
    January 24, 2021

    Traceback (most recent call last):

    File "Tensorflow/models/research/object_detection/model_main_tf2.py", line 32, in <module>

    from object_detection import model_lib_v2

    ModuleNotFoundError: No module named 'object_detection'
    I got this error though i installed the API. please help me

  • Nicholas Renotte
    January 24, 2021

    Amazing video Nicholas! Thanks a million 🙂 Can I use this approach for a ImageNet pretrained model mobilenet_1_0_224_tf.h5 with a custom dataset of 6 classes?

  • Nicholas Renotte
    January 24, 2021

    when i tried to train the model.the following error occurs .anyone guide me .thank in advance

    from tensorflow.python.keras.saving.saved_model import export_saved_model

    ImportError: cannot import name 'export_saved_model'

  • Nicholas Renotte
    January 24, 2021

    Greetings Nicholas. Really appreciate this video of yours as it will help me out a lot. However, I encountered an error in part 7 of your codes when I was trying to import. It states "module 'tensorflow.python.framework.ops' has no attribute 'RegisterShape'". Im probably thinking its Tensorflow issue? Would really be great if you could help me out with this issue. Thank you very much Nicholas.

  • Nicholas Renotte
    January 24, 2021

    hi i need your help im trying to run the config=config_util.get_configs_from_pipeline_file(PATH)
    but getting this error->
    ParseError: 21:11 : Message type "object_detection.protos.Initializer" has no field named "random_normal_initializer".

    i am working with jupyter notebook
    plz answer me asap

  • Nicholas Renotte
    January 24, 2021

    can you help me for my error ""from object_detection.utils import dataset_util, label_map_util

    ModuleNotFoundError: No module named 'object_detection' ""

  • Nicholas Renotte
    January 24, 2021

    I training this model in google cloud platform and got this error massage :
    " index error: Read less bytes than requested "

  • Nicholas Renotte
    January 24, 2021

    I'm having this error : raise ValueError(''images' must have either 3 or 4 dimensions.')
    ValueError: 'images' must have either 3 or 4 dimensions.

  • Nicholas Renotte
    January 24, 2021

    I am still having problems with TF records. I downloaded the object detection API and everything, but when I run the command I get the following error : tensorflow.python.framework.errors_impl.InvalidArgumentError: NewRandomAccessFile failed to Create/Open: {'D:/Projects/eyantra/object_detection/Tensorflow/workspace/annotations/label_map.pbtxt'} : The filename, directory name, or volume label syntax is incorrect.

    ; no protocol option
    Please help me with what to do

  • Nicholas Renotte
    January 24, 2021

    Awesome vid. I have an issue however,
    !mkdir {'Tensorflowworkspacemodels\'+CUSTOM_MODEL_NAME}
    !cp {PRETRAINED_MODEL_PATH+'/ssd_mobilenet_v2_fpnlite_320x320_coco17_tpu-8/pipeline.config'} {MODEL_PATH+'/'+CUSTOM_MODEL_NAME}
    returns:
    A subdirectory or file Tensorflowworkspacemodelsmy_ssd_mobnet already exists.

    'cp' is not recognized as an internal or external command,

    operable program or batch file.

    When I switch cp to copy it returns:
    A subdirectory or file Tensorflowworkspacemodelsmy_ssd_mobnet already exists.

    The syntax of the command is incorrect.

  • Nicholas Renotte
    January 24, 2021

    pipeline config is not defined. please help

  • Nicholas Renotte
    January 24, 2021

    01:43 Let's do this
    04:20 Building up Imaglabling
    05:29 PyQt & XML
    07:50 Image ready for deployment
    12:36 Get and read Xml file
    18:01 00-Setup paths
    19:57 Creating label map(dictionary)
    21:52 Creating label map(labeling complete)
    23:25 Creating TF records
    26:19 TF model zoo(downloading pretrained models)
    27:50 TF model zoo choosing
    30:03 Copy model config to training model
    32:21 Update Config for transfer learning
    40:27 Train the model
    44:51 Load train model from check point
    49:00 Detect in real time
    56:11 error

  • Nicholas Renotte
    January 24, 2021

    Hey, firstly thanks a lot for the tutorial but i m taking this error when i run model_main_tf2.py. How can i fix that? also i tried set_memory_growth but i can not solve it. any idea?
    tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,

    tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize,

  • Nicholas Renotte
    January 24, 2021

    Hi Nicholas im not sure why i have this ParseError: 172:3 : Message type "object_detection.protos.TrainConfig" has no field named "fine_tune_checkpoint_version".
    Would really appreciate your help

  • Nicholas Renotte
    January 24, 2021

    PLEASE ! LET ME KNOW , WHERE I CAN GET YOUR TEMPLATE.IPYNB ?

  • Nicholas Renotte
    January 24, 2021

    I am not able to run the create TF records command. Whenever I try to run it, any error shows up, "python.exe – Application Error The application was unable to start correctly". Could you please help me with this. Thank you.

  • Nicholas Renotte
    January 24, 2021

    Hi Nicholas. How can I see the "summary" of the model used to train the data? I tried "detection_model.summary()" but it does not work.

    When you use the a "pretrained model" does a layer modification make sense?

    For example: change a optimizer function, or add a new dense layer?

    Thanks a lot.

  • Nicholas Renotte
    January 24, 2021

    Great Tutorial. Done with the training and detection finally after a whole day of dealing with errors. Could you guide me to generate a training vs testing loss graph?

  • Nicholas Renotte
    January 24, 2021

    Hi @Nicholas,

    I want to ask you that for training you are determining number of steps to be 5000. What happens if I increase it lets say to 20000? I think both training time and accuracy will improve but I am not sure of it. And also is it enough to change it by manually retyping 20000 instead of 5000 or should I change something else in config files?

    Also I want to continue to train at where I stop before. How can I do that? Thank you so much, you are helping me so much

Write a comment