how to train a model in machine learning - python

iam working on my grad project that is a security detection program
now i need to ask a few questions
1- how to train a model for object detection with yolo, i already have the images with the annotations but i dont know how to train them
2-iam using haarcascade with opencv to do face recognition is there is a better model or new way because haarcascade is not accurate and drop frames and its only on front face or if not how can i train the haarcascade on more image to be better
3- also all of the program is obv written with python so after i finish the program how can i make it a website or desktop app because for example i run yolo with parser arg so i dont know how to make a button do that
1-i tried google collab to train data but it was on tensorflow so it didnt help me
2-and i tried cascade trainer but i failed to train every time

Related

How to tile images on inference with Yolo Object Detection

I've recently trained a custom yolov5 model to recognize animals on safari.
Animals on safari are far away most of the time, and so, after resizing images to 640x640, most of the animals are now too small to be detected.
I've researched the technique of tiling, taking a large image and splitting it into 5x5 smaller images, allowing the inference not to take up as much ram as trying to run the inference on the initial large image.
However, there is no instruction on how to do this on real-time inference.
The model I'm using is Yolov5 trained with PyTorch.
Does anyone know how to do tiling on real-time inference?

Problem in finding code for Simple image classification between two classes in android studio

i trained keras model on 2 classes and converted it into the .tflite model. now i want to use this model in android studio for simple classification between two classes when i put an image from the gallery. i can't find any help on internet regarding this simple way. On internet there is ways for camera but i don't need that in my simple project.
You will need to use TensorFlow Lite's Java API to run inference on-device. Start with the Android quickstart, if you haven't installed the dependencies etc.
If your model is similar to how standard image classification models (for eg MobileNet) work, you can start with the TFLite Image Classification app source for inspiration. Specifically, you might be interested in the Classifier base-class (and its floating point child class). Classifier demonstrates how you can use TFLite's Java API to instantiate a new Interpreter & run inference for image inputs.

Can I retrain OpenCV DNN face detector using my own face dataset and .pb .pbtxt files provided by OpenCV?

I want to fine tune existing OpenCV DNN face detector to a face images database that I own. I have opencv_face_detector.pbtxt and opencv_face_detector_uint8.pb tensorflow files provided by OpenCV. I wonder if based on this files is there any way to fit the model to my data? So far, I haven't also managed to find any tensorflow training script for this model in OpenCV git repository and I only know, that given model is and SSD with resnet-10 as a backbone. I am also not sure, reading the information on the internet, if I can resume training from .pb file. Are you aware of availability of any scripts defining the model, that could be used for training? Would pbtxt and pb files be enough to continue training on new data?
Also, I noticed that there is a git containing caffe version of this model https://github.com/weiliu89/caffe/tree/ssd. Although I never worked with caffe before, would it be possible/easier to use existing weight (caffe .pg and .pbtxt files are also available in OpenCV's github) and fit the model to my dataset?
I don't see a way to do this in opencv, but I think you'd be able to load the model into tensorflow and use model.fit() to retrain.
The usual advice about transfer learning applies. You'd probably want to freeze most of the early layers and only retrain the last one or two. A slow learning rate would be advised as well.

Transfer learning for facial identification using classifiers

I wish to know whether I can use an Inception or ResNet model to identify faces. I want to know whether transfer learning and training is even considerable for my task.
I just want to be able to identify faces but I am also curious whether I can retrain/optimize a pre-trained model for my task.
Or have I been reading of things wrong; do I need to get a pre-trained model that was designed for faces?
I have tried poking around with Inception and VGG16 but I have not trained them for faces. I am working on it but I want to know whether this is even viable or simply a waste of time. If I use transfer learning with FaceNet I think I'll be better off.
Transfer learning for facial detection would be a great way to go ahead. Also, yes transfer learning with facenet is a great idea.
Also, for transfer learning to work it is not necessary that the model had to be initially pre-trained with only faces like using facenet. A model pre-trained with imagenet would also be pretty darn good! This is a very hot topic, so do not try to reinvent the wheel. There are many repositories that have already done this using transfer learning from imagenet dataset and using resnet50 with astonishingly good results.
Here is a link to one such repository:
https://github.com/loheden/face_recognition_with_siamese_network
Also note that siamese networks is a technique that is especially good in the facial recognition use case. The concept of siamese is really simple: take two images and compare the features of these two images. If the similarity in features are above a set threshold, then the two images are the same (the two faces are the same) else not the same (face not recognized).
Here is a research paper on siamese networks for facial recognition.
Also, here is a two-part tutorial on how to implement the siamese network for facial recognition using transfer learning:
http://www.loheden.com/2018/07/face-recognition-with-siamese-network.html
http://www.loheden.com/2018/07/face-recognition-with-siamese-network_29.html
The above tutorial's code is in the first Github link I shared at the beginning of this answer.

How can I create a checkpoint file of a TensorFlow model?

I am trying to implement Neural Style Transfer using TensorFlow and want to integrate the same within an Android application for image filtering. Can anyone help me save this TensorFlow model, so I can restore it whenever in use in the application?
I've tried creating .ckpt file of this TensorFlow model, but I'm not able to create one.
I haven't copied the code here as it consists of dozens of lines. Here is the link for the model https://colab.research.google.com/github/tensorflow/models/blob/master/research/nst_blogpost/4_Neural_Style_Transfer_with_Eager_Execution.ipynb
I am expecting to save this model to generate a new image at very low latency. Currently, I've to run hundreds of iterations for every image and that's what I don't want in real time while running in the application.

Categories

Resources