Can I combine the results from a model.fit that are in a .h5 file - python-3.x

So I am using the keras module to create a facial recognition program but I have hit one problem, my computer can`t compute all the answers at once so I change the data to smaller amount and calculate each part until it is close to 100% accuracy. My data is constantly being trained with different data e.g. Happy face, Sad face and Confused face the code is then trained with this data then another set of data Angry face, Lonely face and Amazed face and the code is trained with this data. The two datasets are run at different times but both produce a h5 file with the data they have collected. How can I combine these two or more files into one singular file. I am guessing that the model may have to be retrained with the h5 files and then produce a singular 5h file but I do not know. Anyone know how to combine two trained models saved in h5 files?
The code below shows where I train and save the model before changing the data and rerunning the code.
model.fit(train_generator, steps_per_epoch=int(train / batch_size), epochs=epochs, callbacks=[checkpoint, lr_scheduler])

Related

In YOLO V7, Can I combine two separate trained model (weight files) to detect different images?

Let's say, I have trained a custom model with 500 images of Apple. I have got a best.pt file which can detect apple very well. Now, I have trained another yolov7 model, with 500 images of Orange, and have got another best.pt file which can detect Orange very well. Now I want to combine that two .pt file together, so that if I provide both orange and apple image, then that combined .pt file can detect them all. Is that possible, or how can I solve this issue. Any other way, to do that instead of training a model with two types of images.
Please, experts asking for your help.
So far, I have just trained two models, but don't know how to combine and make the models as one.

Bert for relation extraction

i am working with bert for relation extraction from binary classification tsv file, it is the first time to use bert so there is some points i need to understand more?
how can i get an output like giving it a test data and show the classification results whether it is classified correctly or not?
how bert extract features of the sentences, and is there a method to know what are the features that is chosen?
i used once the hidden layers and another time i didn't use i got the accuracy of not using the hidden layer higher than using it, is there an reason for that?

in the face recognition training part, trainner.yml file is generated. is it useful to find the confuison matrix?

I was working on a face recognition code. I wanted to find the performance metrics (accuracy, precision, etc.) of my algorithm. I've used HaarCascade Algorithm and LBPH FaceRecogniser When I searched for it on the net, I could find only those sources where already existing datasets are taken and the parameters are computed. I want to use the data obtained from training my model (trained from the images folder). A folder named "trainner.yml" is generated automatically after running the file.
is the data from the trainner.yml file my dataset? What is my dataset now and how can I find the confusion matrix
Thanks

How do i retrain the model without losing the earlier model data with new set of data

for my current requirement, I'm having a dataset of 10k+ faces from 100 different people from which I have trained a model for recognizing the face(s). The model was trained by getting the 128 vectors from the facenet_keras.h5 model and feeding those vector value to the Dense layer for classifying the faces.
But the issue I'm facing currently is
if want to train one person face, I have to retrain the whole model once again.
How should I get on with this challenge? I have read about a concept called transfer learning but I have no clues about how to implement it. Please give your suggestion on this issue. What can be the possible solutions to it?
With transfer learning you would copy an existing pre-trained model and use it for a different, but similar, dataset from the original one. In your case this would be what you need to do if you want to train the model to recognize your specific 100 people.
If you already did this and you want to add another person to the database without having to retrain the complete model, then I would freeze all layers (set layer.trainable = False for all layers) except for the final fully-connected layer (or the final few layers). Then I would replace the last layer (which had 100 nodes) to a layer with 101 nodes. You could even copy the weights to the first 100 nodes and maybe freeze those too (I'm not sure if this is possible in Keras). In this case you would re-use all the trained convolutional layers etc. and teach the model to recognise this new face.
You can save your training results by saving your weights with:
model.save_weights('my_model_weights.h5')
And load them again later to resume your training after you added a new image to the dataset with:
model.load_weights('my_model_weights.h5')

which is the most suitable method for training among model.fit(), model.train_on_batch(), model.fit_generator()

I have a training dataset of 600 images with (512*512*1) resolution categorized into 2 classes(300 images per class). Using some augmentation techniques I have increased the dataset to 10000 images. After having following preprocessing steps
all_images=np.array(all_images)/255.0
all_images=all_images.astype('float16')
all_images=all_images.reshape(-1,512,512,1)
saved these images to H5 file.
I am using an AlexNet architecture for classification purpose with 3 convolutional, 3 overlap max-pool layers.
I want to know which of the following cases will be best for training using Google Colab where memory size is limited to 12GB.
1. model.fit(x,y,validation_split=0.2)
# For this I have to load all data into memory and then applying an AlexNet to data will simply cause Resource-Exhaust error.
2. model.train_on_batch(x,y)
# For this I have written a script which randomly loads the data batch-wise from H5 file into the memory and train on that data. I am confused by the property of train_on_batch() i.e single gradient update. Do this will affect my training procedure or will it be same as model.fit().
3. model.fit_generator()
# giving the original directory of images to its data_generator function which automatically augments the data and then train using model.fit_generator(). I haven't tried this yet.
Please guide me which will be the best among these methods in my case. I have read many answers Here, Here, and Here about model.fit(), model.train_on_batch() and model.fit_generator() but I am still confused.
model.fit - suitable if you load the data as numpy-array and train without augmentation.
model.fit_generator - if your dataset is too big to fit in the memory or\and you want to apply augmentation on the fly.
model.train_on_batch - less common, usually used when training more than one model at a time (GAN for example)

Resources